Skip to content

Commit

Permalink
refactor function output decode.
Browse files Browse the repository at this point in the history
  • Loading branch information
YancyParker committed Jan 25, 2024
1 parent ad9c88b commit 22d1383
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "ola-lang-abi"
version = "1.0.4"
version = "1.0.5"
edition = "2021"
license = "MIT"
description = "Ola Smart Contract ABI parsing library"
authors = ["yp945@outlook.com"]
authors = ["panos@olavm.org"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
keywords = ["abi", "ola", "olac", ]
documentation = "https://olang.gitbook.io/ola-lang/"
Expand Down
11 changes: 6 additions & 5 deletions src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,28 @@ impl Abi {
.find(|f| f.method_id() == input[input.len()-1])
.ok_or_else(|| anyhow!("ABI function not found"))?;

// input = [param1, param2, .. , param-len, method_id,]
// input = [param1, param2, .. , param-len, method_id]

let decoded_params = f.decode_input_from_slice(&input[0..input.len()-2])?;

Ok((f, decoded_params))
}

// Decode function input from slice.
// Decode function ouput from slice.
pub fn decode_output_from_slice<'a>(
&'a self,
signature: &str,
output: &[u64],
) -> Result<(&'a Function, DecodedParams)> {
let f = self
.functions
.iter()
.find(|f| f.method_id() == output[output.len()-1])
.find(|f| f.signature() == signature)
.ok_or_else(|| anyhow!("ABI function not found"))?;

// output = [param1, param2, .. , param-len, method_id,]
// output = [param1, param2, .. , param-len]

let decoded_params = f.decode_input_from_slice(&output[0..output.len()-2])?;
let decoded_params = f.decode_output_from_slice(&output[0..output.len()-1])?;

Ok((f, decoded_params))
}
Expand Down

0 comments on commit 22d1383

Please sign in to comment.