Skip to content

Commit

Permalink
Add FromAbi
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Sep 14, 2023
1 parent c848807 commit c7d8b49
Show file tree
Hide file tree
Showing 5 changed files with 441 additions and 25 deletions.
11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ed25519-dalek = { version = "2.0", optional = true }
everscale-crypto = { version = "0.2", features = ["tl-proto"], optional = true }
hex = "0.4"
num-bigint = { version = "0.4", optional = true }
num-traits = { version = "0.2", optional = true }
once_cell = "1.16"
serde = { version = "1", features = ["derive"], optional = true }
sha2 = "0.10"
Expand All @@ -56,7 +57,15 @@ sync = []
stats = []
serde = ["dep:serde", "base64"]
models = ["dep:everscale-crypto", "dep:tl-proto"]
abi = ["dep:anyhow", "dep:bytes", "dep:ed25519-dalek", "dep:num-bigint", "dep:serde", "models"]
abi = [
"dep:anyhow",
"dep:bytes",
"dep:ed25519-dalek",
"dep:num-bigint",
"dep:num-traits",
"dep:serde",
"models",
]
venom = []

[profile.release]
Expand Down
43 changes: 27 additions & 16 deletions src/abi/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,22 +730,22 @@ impl<'f, 'a> ExternalInput<'f, 'a> {
let abi_version = self.function.abi_version;

let mut serializer = AbiSerializer::new(abi_version);
serializer.add_offset(if abi_version.major == 1 {
// Reserve reference for signature
ShortAbiTypeSize { bits: 0, refs: 1 }
} else if reserve_signature {
let bits = if abi_version >= AbiVersion::V2_3 {
// Reserve only for address as it also ensures the the signature will fit
IntAddr::BITS_MAX

if reserve_signature {
serializer.add_offset(if abi_version.major == 1 {
// Reserve reference for signature
ShortAbiTypeSize { bits: 0, refs: 1 }
} else {
// Reserve for `Some` non-empty signature
1 + 512
};
ShortAbiTypeSize { bits, refs: 0 }
} else {
// Reserve for `None`
ShortAbiTypeSize { bits: 1, refs: 0 }
});
let bits = if abi_version >= AbiVersion::V2_3 {
// Reserve only for address as it also ensures the the signature will fit
IntAddr::BITS_MAX
} else {
// Reserve for `Some` non-empty signature
1 + 512
};
ShortAbiTypeSize { bits, refs: 0 }
});
}

let input_id = AbiValue::uint(32, self.function.input_id);

Expand All @@ -755,6 +755,18 @@ impl<'f, 'a> ExternalInput<'f, 'a> {
serializer.reserve_value(&token.value);
}

let finalizer = &mut Cell::default_finalizer();

if !reserve_signature {
let value = if abi_version.major == 1 {
AbiValue::Cell(Cell::default())
} else {
AbiValue::Bool(false)
};
serializer.reserve_value(&value);
serializer.write_value(&value, finalizer)?;
}

let time = self.time.unwrap_or_else(now_ms);
let expire_at = self
.expire_at
Expand All @@ -770,7 +782,6 @@ impl<'f, 'a> ExternalInput<'f, 'a> {
})?;
}

let finalizer = &mut Cell::default_finalizer();
serializer.write_value(&input_id, finalizer)?;
serializer.write_tuple(self.tokens, finalizer)?;

Expand Down
3 changes: 3 additions & 0 deletions src/abi/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ fn encode_unsigned_external_input() {
.build_input_without_signature()
.unwrap();

println!("{}", expected.display_tree());
println!("{}", body.display_tree());

assert_eq!(body, expected);
}

Expand Down
Loading

0 comments on commit c7d8b49

Please sign in to comment.