From 58a839bd149ba5a6e0c3c74081739379c48c2af0 Mon Sep 17 00:00:00 2001 From: saifkatoutatcom Date: Wed, 31 May 2023 20:25:56 +0400 Subject: [PATCH] #891 Call functions Fixed call functions of the #891 issue. --- crates/library/std/src/context.fe | 18 +++++++----------- crates/library/std/src/evm.fe | 10 ++++++---- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/crates/library/std/src/context.fe b/crates/library/std/src/context.fe index 3632e1f7dc..41d389b61d 100644 --- a/crates/library/std/src/context.fe +++ b/crates/library/std/src/context.fe @@ -81,11 +81,10 @@ pub struct Context { if evm::balance() < wei { revert Error(code: ERROR_INSUFFICIENT_FUNDS_TO_SEND_VALUE) } - - let success: u256 = evm::call(gas: evm::gas_remaining(), addr: to, value: wei, - input_offset: 0, input_len: 0, - output_offset: 0, output_len: 0) - if success == 0 { + let buffer: RawCallBuffer = RawCallBuffer::new(input_len: 0, output_len: 0) + let success: bool = evm::call(gas: evm::gas_remaining(), addr: to, value: wei, + buffer) + if success { revert Error(code: ERROR_FAILED_SEND_VALUE) } } @@ -96,18 +95,15 @@ pub struct Context { self, addr: address, value: u256, - mut buf: RawCallBuffer + buffer: RawCallBuffer ) -> bool { unsafe { return evm::call( gas: evm::gas_remaining(), addr, value, - input_offset: buf.offset(), - input_len: buf.input_len(), - output_offset: buf.offset(), - output_len: buf.output_len() - ) == 1 + buffer + ) } } diff --git a/crates/library/std/src/evm.fe b/crates/library/std/src/evm.fe index fb524c2e04..bced433e2d 100644 --- a/crates/library/std/src/evm.fe +++ b/crates/library/std/src/evm.fe @@ -1,3 +1,5 @@ +use ingot::buf + // Basic context accessor functions. pub unsafe fn chain_id() -> u256 { return __chainid() @@ -236,8 +238,8 @@ pub unsafe fn call_data_size() -> u256 { return __calldatasize() } -pub unsafe fn call_data_copy(to_offset t: u256, from_offset f: u256, len: u256) { - __calldatacopy(t, f, len) +pub fn call_data_copy(buffer: buf::MemoryBuffer) { + unsafe { __calldatacopy(buffer.offset(), buffer.offset(), buffer.len()) } } pub unsafe fn code_size() -> u256 { @@ -284,8 +286,8 @@ pub unsafe fn create2(value v: u256, offset p: u256, len n: u256, salt s: u256) } // TODO: return bool (success) -pub unsafe fn call(gas: u256, addr: address, value: u256, input_offset: u256, input_len: u256, output_offset: u256, output_len: u256) -> u256 { - return __call(gas, u256(addr), value, input_offset, input_len, output_offset, output_len) +pub fn call(gas: u256, addr: address, value: u256, buffer: buf::RawCallBuffer) -> bool { + unsafe{ return __call(gas, u256(addr), value, buffer.offset(), buffer.input_len(), buffer.offset(), buffer.output_len()) == 1 } } pub unsafe fn call_code(gas: u256, addr: address, value: u256, input_offset: u256, input_len: u256, output_offset: u256, output_len: u256) -> u256 {