Skip to content

Commit

Permalink
ethereum#891 Call functions
Browse files Browse the repository at this point in the history
Fixed call functions of the ethereum#891 issue.
  • Loading branch information
saifkatoutatcom authored and saifalkatout committed Sep 28, 2023
1 parent 1233a21 commit 58a839b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
18 changes: 7 additions & 11 deletions crates/library/std/src/context.fe
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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
)
}
}

Expand Down
10 changes: 6 additions & 4 deletions crates/library/std/src/evm.fe
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use ingot::buf

// Basic context accessor functions.
pub unsafe fn chain_id() -> u256 {
return __chainid()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 58a839b

Please sign in to comment.