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
@@ -607,6 +607,23 @@ where
Pointer::new(r#type, AddressSpace::Stack, pointer)
}
/// Truncate `address` to the ethereum address length and store it as bytes on the stack.
/// The stack allocation will be at the function entry. Returns the stack pointer.
/// This helper should be used when passing address arguments to the runtime, ensuring correct size and endianness.
pub fn build_address_argument_store(
&self,
address: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<Pointer<'ctx>> {
let address_type = self.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
let address_pointer = self.build_alloca_at_entry(address_type, "address_pointer");
let address_truncated =
self.builder()
.build_int_truncate(address, address_type, "address_truncated")?;
let address_swapped = self.build_byte_swap(address_truncated.into())?;
self.build_store(address_pointer, address_swapped)?;
Ok(address_pointer)
}
/// Load the address at given pointer and zero extend it to the VM word size.
pub fn build_load_address(
&self,