Skip to content

Instantly share code, notes, and snippets.

@madhavanmalolan
Created September 5, 2022 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madhavanmalolan/232972b10c98b901adb8675fa416c963 to your computer and use it in GitHub Desktop.
Save madhavanmalolan/232972b10c98b901adb8675fa416c963 to your computer and use it in GitHub Desktop.
// 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