Fix implementation for balance_of (#79)

The balance_of syscall is now available in pallet-revive.
- Fix balance_of implementation to use correct runtime api
- Add build_address_argument_store helper to be used for address arguments
This commit is contained in:
Ermal Kaleci
2024-10-12 12:35:10 +02:00
committed by GitHub
parent 6335c34a2b
commit d9842b5427
7 changed files with 58 additions and 59 deletions
+1 -8
View File
@@ -27,14 +27,7 @@ pub fn call<'ctx, D>(
where
D: Dependency + Clone,
{
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
let address_pointer = context.build_alloca_at_entry(address_type, "address_pointer");
let address_truncated =
context
.builder()
.build_int_truncate(address, address_type, "address_truncated")?;
let address_swapped = context.build_byte_swap(address_truncated.into())?;
context.build_store(address_pointer, address_swapped)?;
let address_pointer = context.build_address_argument_store(address)?;
let value = value.unwrap_or_else(|| context.word_const(0));
let value_pointer = context.build_alloca_at_entry(context.word_type(), "value_pointer");
@@ -40,22 +40,19 @@ pub fn balance<'ctx, D>(
where
D: Dependency + Clone,
{
let balance_pointer = context.build_alloca(context.word_type(), "balance_pointer");
let address_pointer = context.build_alloca(context.word_type(), "address_pointer");
context.build_store(address_pointer, address)?;
let address_pointer = context.build_address_argument_store(address)?;
let balance_pointer = context.build_alloca(context.word_type(), "balance_pointer");
let balance = context.builder().build_ptr_to_int(
balance_pointer.value,
context.xlen_type(),
"balance",
)?;
let _address = context.builder().build_ptr_to_int(
address_pointer.value,
context.xlen_type(),
"address",
)?;
context.build_runtime_call(runtime_api::imports::BALANCE, &[balance.into()]);
context.build_runtime_call(
runtime_api::imports::BALANCE_OF,
&[address_pointer.to_int(context).into(), balance.into()],
);
context.build_load(balance_pointer, "balance")
}