Created
September 5, 2022 14:45
-
-
Save madhavanmalolan/232972b10c98b901adb8675fa416c963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
contract Benchmark { | |
mapping (uint => uint) onchainStorage; | |
mapping (uint => uint) params; | |
address bridge; | |
constructor(){ | |
bridge = msg.sender; | |
} | |
function storeOnchain(uint key, uint val) public { | |
onchainStorage[key] = val; | |
} | |
function checkOnchainStorage(uint key) public view returns(bool) { | |
return onchainStorage[key] == 0; | |
} | |
event CheckOffChainStorage(uint id, uint key); | |
event DummyAction(bool); | |
function foo(uint param) public { | |
uint key = 1; | |
uint id = uint(keccak256(abi.encodePacked(block.timestamp, msg.sender))); | |
params[id] = param; | |
emit CheckOffChainStorage(id, key); | |
} | |
// ... wait for callback before continuing | |
function foo_callback(bool ret_val, uint id) public { | |
require(msg.sender == bridge, "Only bridge can call this function"); | |
uint param = params[id]; | |
delete params[id]; | |
emit DummyAction(ret_val); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment