diff --git a/bindings/go/evmc/host.c b/bindings/go/evmc/host.c index 3d0b55a94..5b82a9a27 100644 --- a/bindings/go/evmc/host.c +++ b/bindings/go/evmc/host.c @@ -15,6 +15,8 @@ */ const struct evmc_host_interface evmc_go_host = { (evmc_account_exists_fn)accountExists, + (evmc_access_account_fn)accessAccount, + (evmc_access_storage_fn)accessStorage, (evmc_get_storage_fn)getStorage, (evmc_set_storage_fn)setStorage, (evmc_get_balance_fn)getBalance, @@ -46,6 +48,8 @@ static inline void go_exported_functions_type_checks() (void)tx_context; struct evmc_result result; (void)result; + enum evmc_access_status access_status; + (void)access_status; enum evmc_storage_status storage_status; (void)storage_status; bool bool_flag; @@ -55,6 +59,14 @@ static inline void go_exported_functions_type_checks() bool_flag = account_exists_fn(context, address); bool_flag = accountExists(context, address); + evmc_access_account_fn access_account_fn = NULL; + access_status = access_account_fn(context, address); + access_status = accessAccount(context, address); + + evmc_access_storage_fn access_storage_fn = NULL; + access_status = access_storage_fn(context, address, &bytes32); + access_status = accessStorage(context, address, &bytes32); + evmc_get_storage_fn get_storage_fn = NULL; bytes32 = get_storage_fn(context, address, &bytes32); bytes32 = getStorage(context, address, &bytes32); diff --git a/bindings/go/evmc/host.go b/bindings/go/evmc/host.go index c0d70c4fa..2a09ed429 100644 --- a/bindings/go/evmc/host.go +++ b/bindings/go/evmc/host.go @@ -26,6 +26,13 @@ const ( Create2 CallKind = C.EVMC_CREATE2 ) +type AccessStatus int + +const ( + ColdAccess AccessStatus = C.EVMC_ACCESS_COLD + WarmAccess AccessStatus = C.EVMC_ACCESS_WARM +) + type StorageStatus int const ( @@ -73,6 +80,8 @@ type TxContext struct { type HostContext interface { AccountExists(addr Address) bool + AccessAccount(addr Address) AccessStatus + AccessStorage(addr Address, key Hash) AccessStatus GetStorage(addr Address, key Hash) Hash SetStorage(addr Address, key Hash, value Hash) StorageStatus GetBalance(addr Address) Hash @@ -94,6 +103,18 @@ func accountExists(pCtx unsafe.Pointer, pAddr *C.evmc_address) C.bool { return C.bool(ctx.AccountExists(goAddress(*pAddr))) } +//export accessAccount +func accessAccount(pCtx unsafe.Pointer, pAddr *C.evmc_address) C.enum_evmc_access_status { + ctx := getHostContext(uintptr(pCtx)) + return C.enum_evmc_access_status(ctx.AccessAccount(goAddress(*pAddr))) +} + +//export accessStorage +func accessStorage(pCtx unsafe.Pointer, pAddr *C.evmc_address, pKey *C.evmc_bytes32) C.enum_evmc_access_status { + ctx := getHostContext(uintptr(pCtx)) + return C.enum_evmc_access_status(ctx.AccessStorage(goAddress(*pAddr), goHash(*pKey))) +} + //export getStorage func getStorage(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.evmc_bytes32) C.evmc_bytes32 { ctx := getHostContext(uintptr(pCtx)) diff --git a/bindings/go/evmc/host_test.go b/bindings/go/evmc/host_test.go index 07b6a24da..a87700829 100644 --- a/bindings/go/evmc/host_test.go +++ b/bindings/go/evmc/host_test.go @@ -15,6 +15,14 @@ func (host *testHostContext) AccountExists(addr Address) bool { return false } +func (host *testHostContext) AccessAccount(addr Address) AccessStatus { + return ColdAccess +} + +func (host *testHostContext) AccessStorage(addr Address, key Hash) AccessStatus { + return ColdAccess +} + func (host *testHostContext) GetStorage(addr Address, key Hash) Hash { return Hash{} }