Skip to content

Commit

Permalink
refactor function selector to litte endian encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
YancyParker committed Nov 8, 2023
1 parent 6107f4f commit e099bee
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ola-lang-abi"
version = "1.0.0"
version = "1.0.1"
edition = "2021"
license = "MIT"
description = "Ola Smart Contract ABI parsing library"
Expand All @@ -9,6 +9,7 @@ authors = ["yp945@outlook.com"]
keywords = ["abi", "ola", "olac", ]
documentation = "https://olang.readthedocs.io/"
homepage = "https://github.com/Sin7Y/ola-lang-abi"
exclude = ["/docs", "/examples"]

[dependencies]
anyhow = { version = "1.0", default-features = false, features = ["std"] }
Expand Down
6 changes: 3 additions & 3 deletions examples/book_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use ola_lang_abi::{Abi, Value};
fn main() {
// Parse ABI from file
let abi: Abi = {
let file = File::open("examples/BookExample.json").expect("failed to open ABI file");
let file = File::open("examples/sqrt_prophet_abi.json").expect("failed to open ABI file");

serde_json::from_reader(file).expect("failed to parse ABI")
};

let function_sig = "createBook(u32,string)";
let function_sig = "sqrt_benchmark(u32,u32)";

let params = vec![Value::U32(60), Value::String("olavm".to_string())];
let params = vec![Value::U32(60), Value::U32(1)];

let input = abi
.encode_input_with_signature(function_sig, &params)
Expand Down
37 changes: 37 additions & 0 deletions examples/sqrt_prophet_abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{
"name": "sqrt_benchmark",
"type": "function",
"inputs": [
{
"name": "q",
"type": "u32",
"internalType": "u32"
},
{
"name": "times",
"type": "u32",
"internalType": "u32"
}
],
"outputs": []
},
{
"name": "sqrt_test",
"type": "function",
"inputs": [
{
"name": "n",
"type": "u32",
"internalType": "u32"
}
],
"outputs": [
{
"name": "",
"type": "u32",
"internalType": "u32"
}
]
}
]
2 changes: 1 addition & 1 deletion src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Function {
let mut hasher = Keccak::v256();
hasher.update(self.signature().as_bytes());
hasher.finalize(&mut keccak_out);
u32::from_be_bytes(keccak_out[0..4].try_into().unwrap()) as u64
u32::from_le_bytes(keccak_out[0..4].try_into().unwrap()) as u64
}

/// Returns the function's signature.
Expand Down

0 comments on commit e099bee

Please sign in to comment.