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
mapping (address => mapping (bytes32 => bool)) public orders; | |
mapping (address => mapping (bytes32 => uint)) public orderFills; | |
function trade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s, uint amount) { | |
bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce); | |
if (!( | |
(orders[user][hash] || ecrecover(sha3("\x19Ethereum Signed Message:\n32", hash),v,r,s) == user) && | |
block.number <= expires && | |
safeAdd(orderFills[user][hash], amount) <= amountGet | |
)) throw; |
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
mapping (address => mapping (address => uint)) public tokens; | |
function deposit() payable { | |
tokens[0][msg.sender] = safeAdd(tokens[0][msg.sender], msg.value); | |
Deposit(0, msg.sender, msg.value, tokens[0][msg.sender]); | |
} | |
function withdraw(uint amount) { | |
if (tokens[0][msg.sender] < amount) throw; | |
tokens[0][msg.sender] = safeSub(tokens[0][msg.sender], amount); |
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
pragma solidity ^0.4.16; | |
contract Token { | |
bytes32 public standard; | |
bytes32 public name; | |
bytes32 public symbol; | |
uint256 public totalSupply; | |
uint8 public decimals; | |
bool public allowTransactions; | |
mapping (address => uint256) public balanceOf; |
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
function getOriginAddress(bytes32 signedMessage, uint8 v, bytes32 r, bytes32 s) constant returns(address) { | |
bytes memory prefix = "\x19Ethereum Signed Message:\n32"; | |
bytes32 prefixedHash = keccak256(prefix, signedMessage); | |
return ecrecover(prefixedHash, v, r, s); | |
} |
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
const message = web3.sha3('Hello World'); | |
const signature = await web3.eth.sign(account, message); | |
const { v, r, s } = ethUtil.fromRpcSig(signature); |
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
// ECRECOVER implemented as a native contract. | |
type ecrecover struct{} | |
func (c *ecrecover) RequiredGas(input []byte) uint64 { | |
return params.EcrecoverGas | |
} | |
func (c *ecrecover) Run(input []byte) ([]byte, error) { | |
const ecRecoverInputLength = 128 |
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
EC.prototype.sign = function sign(msg, key, enc, options) { | |
if (typeof enc === 'object') { | |
options = enc; | |
enc = null; | |
} | |
if (!options) | |
options = {}; | |
key = this.keyFromPrivate(key, enc); | |
msg = this._truncateToN(new BN(msg, 16)); |
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
// For eth_sign, we need to sign arbitrary data: | |
signMessage (withAccount, data) { | |
const wallet = this._getWalletForAccount(withAccount) | |
const message = ethUtil.stripHexPrefix(data) | |
var privKey = wallet.getPrivateKey() | |
var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey) | |
var rawMsgSig = ethUtil.bufferToHex(sigUtil.concatSig(msgSig.v, msgSig.r, msgSig.s)) | |
return Promise.resolve(rawMsgSig) | |
} |
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
/// @notice The minimum payment required to use breedWithAuto(). This fee goes towards | |
/// the gas cost paid by whatever calls giveBirth(), and can be dynamically updated by | |
/// the COO role as the gas price changes. | |
uint256 public autoBirthFee = 2 finney; | |
/// @notice Have a pregnant Kitty give birth! | |
/// @param _matronId A Kitty ready to give birth. | |
/// @return The Kitty ID of the new kitten. |
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
bool ret; | |
address addr; | |
assembly { | |
let size := mload(0x40) | |
mstore(size, msgHash) | |
mstore(add(size, 32), v) | |
mstore(add(size, 64), r) | |
mstore(add(size, 96), s) | |
ret := call(3000, 1, 0, size, 128, size, 32) | |
addr := mload(size) |
NewerOlder