Skip to content

Instantly share code, notes, and snippets.

@tina1998612
Created July 12, 2018 04:27
Show Gist options
  • Save tina1998612/f1852388f7c45bc4c9fcb3e17920d310 to your computer and use it in GitHub Desktop.
Save tina1998612/f1852388f7c45bc4c9fcb3e17920d310 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=true&gist=
pragma solidity ^0.4.24;
// @title MAR mode: Module-Agnostic Rendering Mode (Core)
// @author Jeff Hu
// @dev This smart contract is modularized via a module agnostic execution scheme
contract C {
address public M_addr; // The deployed address of the module M
string public M_func; // The target function signature of module M
uint public result;
event ExecutionResult(bool result);
// Address Storage (stores module addresses)
mapping(string => address) AddressStorage;
function getAddressValue(string record) constant public returns (address) {
return AddressStorage[record];
}
function setAddressValue(string record, address value) public {
AddressStorage[record] = value;
}
// String Storage (stores function signatures)
mapping(string => string) StringStorage;
function getStringValue(string record) constant public returns (string) {
return StringStorage[record];
}
function setStringValue(string record, string value) public {
StringStorage[record] = value;
}
// Render target that is to-be-called
function renderModule(string _addrByte, string _funcByte) public {
M_addr = getAddressValue(_addrByte);
M_func = getStringValue(_funcByte);
}
// Execute the target modules's function
function exec() public returns (bool success){
success = M_addr.delegatecall(bytes4(keccak256(M_func)),1,2);
emit ExecutionResult(success);
}
}
pragma solidity ^0.4.24;
//// All Modules ////
contract Math {
uint public result;
// Module #0
function plus(uint _n1, uint _n2) public returns (uint) { result = _n1 + _n2; return result; }
// Module #1
function minus(uint _n1, uint _n2) public returns (uint ans) { result = _n1 - _n2; return result; }
// Module #2
function multiply(uint _n1, uint _n2) public returns (uint ans) { result = _n1 * _n2; return result; }
// Module #3
function divide(uint _n1, uint _n2) public returns (uint ans) { result = _n1 / _n2; return result; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment