Created
March 22, 2016 08:12
-
-
Save y12studio/bfff0c442c662310a458 to your computer and use it in GitHub Desktop.
Y12 Reality Key 1
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
// Ethereum以太坊智能合約環境說明 https://gist.github.com/y12studio/f142cd9789c7d396d8f7 | |
contract YRealityKey { | |
uint public realityId; | |
bytes32 public factHash; | |
address public factAddress; | |
uint public baseUnit; | |
uint public rkResult; | |
function YRealityKey() { | |
} | |
// YES/NO 1 Bitcoin to be at least 200 US Dollar on March 4, 2016 https://www.realitykeys.com/exchange/7508 | |
// reality_id 7508 | |
// fact_hash 0xa1c7a300e9b2122b2fb3307a95d32c6a291c33bbb48d01f3a6a6e1f7da4d32e1 | |
// ethereum_address 0x6fde387af081c37d9ffa762b49d340e6ae213395 | |
// base_unit 1 | |
function setupRealityKey(uint reality_id, bytes32 fact_hash,address ethereum_address, uint base_unit){ | |
realityId = reality_id; | |
factHash = fact_hash; | |
factAddress = ethereum_address; | |
baseUnit = base_unit; | |
rkResult = 0; | |
} | |
// https://www.realitykeys.com/exchange/7508 | |
// sig_r: 0x7f4a360ea834b3c7c67fc026bddade144ba319d47fb50e706f7982b5984ba7a5 | |
// sig_s: 0xea694b3e853518e2d02d5ac8bb718df299ea9361783ffc118f979bfa67c7cbe3 | |
// sig_v: 27 | |
// signed_value: 0x0000000000000000000000000000000000000000000000000000000000000001 | |
function checkRealityKey(uint8 sig_v, bytes32 sig_r, bytes32 sig_s, bytes32 signed_value) returns (bool){ | |
bytes32 result_hash = sha3(factHash, signed_value); | |
address signer_address = ecrecover(result_hash, sig_v, sig_r, sig_s); | |
if (signer_address != factAddress) { | |
return false; | |
} | |
// result true/false=1/0 | |
rkResult = uint256(signed_value) / baseUnit; | |
return true; | |
} | |
function () { | |
throw; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment