Created
December 3, 2018 13:32
-
-
Save christoph2806/5178a5286d2f1b2e4a1a79524f533e38 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.5.0+commit.1d4f565a.js&optimize=false&gist=
This file contains hidden or 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
pragma solidity >0.4.99 <0.6.0; | |
// import paymentProcessor interface | |
// import oracleTypeRegistry interface | |
// import oracleRegistry interface | |
// import requestRegistry interface | |
contract OracleBrokerFront { | |
[...] | |
function makeRequest( | |
bytes32 _oracleType, | |
bytes32 _internalId, // An Id for request generated by Product, so the response could be matched to it | |
// request data ( inputs interpolated into string, according to format defined in OracleType ) | |
// callback instructions ( callback contract address, callback method name ) | |
bytes32[] tagsToPrioritize, // Prioritize Oracles that have these tags ??? | |
) public { | |
address memory responsibleOracleAddress; | |
bytes32 memory requestId; | |
OracleType memory oracleType = oracleTypeRegistry.getOracleType(_oracleType); | |
responsibleOracleAddress = oracleRegistry.nextResponsibleOracle( | |
_oracleType | |
) | |
requestId = requestRegistry.makeRequest( | |
// request data, | |
responsibleOracleAddress | |
); | |
paymentProcessor.storeRequestPayment( | |
msg.sender, | |
requestId, // | |
oracleType.requestPrice // TODO: fuzzy: define pricing in Types Registry, or have an additional ledger ? | |
) | |
emit NewRequest( | |
// request specifics | |
); | |
/* | |
Optional - ping responsible oracle to speed the resolution up | |
Oracle.at(responsibleOracleAddress).forwardRequest(requestId); | |
*/ | |
} | |
} | |
contract OracleTypeRegistry { | |
enum TypeState { Proposed, Active, Deprecated } | |
address owner; // TODO: control privileges | |
struct OracleType { | |
bytes32 callbackSignature, // ex. '(uint8,uint256, boolean)' | |
bytes32 inputFormat, // ex. | |
bytes32 description, | |
unit16 responsePreparationPeriod, | |
uint16 responseDeadlinePeriod, | |
TypeState state, | |
}; | |
mapping (bytes32 => OracleType) public types; | |
constructor( | |
// | |
) public { | |
// TODO | |
} | |
// TODO | |
function proposeOracleType( | |
// oracle type data | |
) public { | |
// save oracle type as Proposed | |
} | |
/* Optional method: update while the Type is still in Proposed state | |
function updateOracleType( | |
) public { | |
} | |
*/ | |
// TODO | |
function activateOracleType( | |
// oracle type id | |
) public onlyOwner { // TODO: control privileges | |
// transition oracle state to Active | |
} | |
// TODO | |
function deprecateOracleType( | |
// oracle type id | |
) public onlyOwner { // TODO: control privileges | |
// transition oracle state to Deprecated | |
} | |
function getOracleType( | |
string _oracleTypeId, | |
) public returns( | |
// TODO list public oracle type data | |
) { | |
// return oracle type data | |
} | |
modifier onlyOwner() { | |
// authorization | |
_; | |
} | |
} | |
contract OracleRequestRegistry is OracleBrokerBackend { | |
[...] | |
function makeRequest( | |
address responsibleOracleAddress, | |
// ... | |
) public onlyBrokerFront returns(bytes32) { | |
// store request to registry | |
// return id | |
} | |
} | |
contract OraclizeBridge() is oraclize { | |
function makeRequest (...) returns (bytes32 queryId) { | |
queryId = oraclize.query(...) | |
} | |
function __callback(...) { | |
} | |
} | |
This file contains hidden or 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
contract transactionDriven { | |
enum state {initial, state1, state2, state3} | |
state myState; | |
address participant1; | |
address participant2; | |
address participant3; | |
function first() public { | |
require(myState == state.initial); | |
myState = state.state1; | |
participant1 = msg.sender; | |
} | |
function second() public { | |
require(myState == state.state1); | |
require(msg.sender != participant1); | |
myState = state.state2; | |
participant2 = msg.sender; | |
} | |
function third() public { | |
require(myState == state.state2); | |
require(msg.sender != participant1); | |
require(msg.sender != participant2); | |
myState = state.state3; | |
participant3 = msg.sender; | |
performAction(); | |
} | |
function performAction() public { | |
// do something | |
} | |
} | |
contract messageDriven { | |
address participant1; | |
address participant2; | |
address participant3; | |
function performAction(uint8[] memory sigV, bytes32[] memory sigR, bytes32[] memory sigS, string memory data) public { | |
participant1 = ecrecover(keccak256(abi.encodePacked(data)), sigV[1], sigR[1], sigS[1]); | |
participant1 = ecrecover(keccak256(abi.encodePacked(data)), sigV[2], sigR[2], sigS[2]); | |
participant1 = ecrecover(keccak256(abi.encodePacked(data)), sigV[3], sigR[3], sigS[3]); | |
// do something | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment