Crates.io | iota-sc-hname-generator |
lib.rs | iota-sc-hname-generator |
version | 1.1.6 |
source | src |
created_at | 2021-03-13 04:08:54.127425 |
updated_at | 2021-03-17 21:09:30.670999 |
description | Generates hashes for function, parameter,and variable names necessary to work with IOTA Smart contracts |
homepage | |
repository | https://github.com/brunoamancio/IOTA-SC-HName-Generator/ |
max_upload_size | |
id | 368133 |
size | 8,462 |
IOTA Smart contract require developers to generate hashes for smart contract functions and views, as well as for parameter and variable names.
They are used to be passed as argument to calls to other functions in the same smart contract and other smart contract functions and views.
With this generator uses procedural macros so you can pre-generate your hashes (in compile-time) to ensure no calculations is necessary in runtime.
The usage is very simple. For example, if your smart contract has the function below:
samplecontract.rs
fn my_sc_function(ctx: &ScFuncContext) {
ctx.log("Hello world!");
}
You can set your constants and generate their hashes with:
contants.rs
pub const MY_SC_FUNCTION : &str = "my_sc_function";
// Here is the HNAME generation. The output type is ScHName.
pub const HNAME_MY_SC_FUNCTION_1 : ScHname = iota_sc_hname_generator::generate_schname!("my_sc_function");
// Here is the HASH generation. The output type is u32.
pub const HNAME_MY_SC_FUNCTION_2 : ScHname = ScHname(iota_sc_hname_generator::generate_hash!("aa"));
No need to manually generate hashes and hardcode them.