Created
September 15, 2017 06:40
-
-
Save anonymous/6befb1d7b9a421207134ce6c1f9662c7 to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.16+commit.d7661dd9.js&optimize=undefined&gist=
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.12; | |
contract owned { | |
address public owner; | |
function owned() { | |
owner = msg.sender; | |
} | |
modifier onlyOwner { | |
require(msg.sender == owner); | |
_; | |
} | |
function transferOwnership(address newOwner) onlyOwner { | |
owner = newOwner; | |
} | |
} | |
library verySig { | |
function checkSig(bytes32 hash, bytes sig) internal returns(address) | |
{ | |
//https://gitter.im/ethereum/solidity/archives/2016/12/14 | |
uint8 v; | |
bytes32 r; | |
bytes32 s; | |
assembly { | |
r := mload(add(sig, 32)) | |
s := mload(add(sig, 64)) | |
v := and(mload(add(sig, 65)), 255) | |
} | |
if (v < 27) v += 27; | |
return ecrecover(hash, v, r, s) ; | |
} | |
} | |
contract bridgeDeposit is owned { | |
using verySig for bytes32; | |
bool public active; | |
uint public nextId; | |
uint public minimum = 0.01 ether; | |
mapping(uint => bool) usedId; | |
event onDeposit(uint id, address target, uint value); | |
function deposit(address target) payable { | |
require(active); | |
require(msg.value >= minimum); | |
onDeposit(nextId,target,msg.value); | |
nextId++; | |
} | |
function setActive(bool _active) onlyOwner { | |
active = _active; | |
} | |
function setMinimum(uint _minimum) onlyOwner { | |
minimum = _minimum; | |
} | |
function withdraw(uint id, address benifactor, uint value, bytes sig) | |
{ | |
require(usedId[id] == false); | |
bytes32 hash = sha3(this,id,benifactor,value); | |
if(owner == hash.checkSig(sig)) { | |
usedId[id] = true; | |
msg.sender.transfer(value); | |
} | |
} | |
} |
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.12; | |
contract ERC20 { | |
event Transfer(address indexed from, address indexed to, uint value); | |
event Approval( address indexed owner, address indexed spender, uint value); | |
function totalSupply() constant returns (uint supply); | |
function balanceOf( address who ) constant returns (uint value); | |
function allowance(address owner, address spender) constant returns (uint _allowance); | |
function transfer( address to, uint value) returns (bool ok); | |
function transferFrom( address from, address to, uint value) returns (bool ok); | |
function approve(address spender, uint value) returns (bool ok); | |
} | |
library SafeMath | |
{ | |
function safeMul(uint a, uint b) internal returns (uint) { | |
uint c = a * b; | |
assert(a == 0 || c / a == b); | |
return c; | |
} | |
function safeDiv(uint a, uint b) internal returns (uint) { | |
assert(b > 0); | |
uint c = a / b; | |
assert(a == b * c + a % b); | |
return c; | |
} | |
function safeSub(uint a, uint b) internal returns (uint) { | |
assert(b <= a); | |
return a - b; | |
} | |
function safeAdd(uint a, uint b) internal returns (uint) { | |
uint c = a + b; | |
assert(c>=a && c>=b); | |
return c; | |
} | |
function max(uint a, uint b) internal constant returns (uint) { | |
return a >= b ? a : b; | |
} | |
function min(uint a, uint b) internal constant returns (uint) { | |
return a < b ? a : b; | |
} | |
} | |
contract baseToken is ERC20 { | |
using SafeMath for uint; | |
mapping( address => uint ) _balances; | |
mapping( address => mapping( address => uint ) ) _approvals; | |
uint _supply; | |
bool public locked; | |
function totalSupply() constant returns (uint supply) { | |
return _supply; | |
} | |
function balanceOf( address who ) constant returns (uint value) { | |
return _balances[who]; | |
} | |
function transfer( address to, uint value) returns (bool ok) | |
{ | |
require(locked == false); | |
_balances[msg.sender] = _balances[msg.sender].safeSub(value); // will throw if insufficient funds | |
_balances[to] = _balances[to].safeAdd(value); // will throw if overflow | |
Transfer( msg.sender, to, value ); | |
return true; | |
} | |
function transferFrom( address from, address to, uint value) returns (bool ok) | |
{ | |
require(locked == false); | |
_approvals[from][msg.sender] = _approvals[from][msg.sender].safeSub(value); // will throw if insufficient approval | |
_balances[from] = _balances[from].safeSub(value); // will throw if insufficient funds | |
_balances[to] = _balances[to].safeAdd(value); // will throw if overflow | |
Transfer( from, to, value ); | |
return true; | |
} | |
function approve(address spender, uint value) returns (bool ok) { | |
require(locked == false); | |
_approvals[msg.sender][spender] = value; | |
Approval( msg.sender, spender, value ); | |
return true; | |
} | |
function allowance(address owner, address spender) constant returns (uint _allowance) { | |
return _approvals[owner][spender]; | |
} | |
} | |
library verySig { | |
function checkSig(bytes32 hash, bytes sig) internal returns(address) | |
{ | |
//https://gitter.im/ethereum/solidity/archives/2016/12/14 | |
uint8 v; | |
bytes32 r; | |
bytes32 s; | |
assembly { | |
r := mload(add(sig, 32)) | |
s := mload(add(sig, 64)) | |
v := and(mload(add(sig, 65)), 255) | |
} | |
if (v < 27) v += 27; | |
return ecrecover(hash, v, r, s) ; | |
} | |
} | |
contract owned { | |
address public owner; | |
function owned() { | |
owner = msg.sender; | |
} | |
modifier onlyOwner { | |
require(msg.sender == owner); | |
_; | |
} | |
function transferOwnership(address newOwner) onlyOwner { | |
owner = newOwner; | |
} | |
} | |
contract bridgeToken is baseToken, owned { | |
using verySig for bytes32; | |
mapping(uint => bool) public usedId; | |
uint public minimum = 0.01 ether; | |
uint public nextId; | |
event onWithdraw(uint Id, address target, uint value); | |
function setLocked(bool _locked) onlyOwner { | |
locked = _locked; | |
} | |
function claim(uint id, address to, uint256 value, bytes sig) returns (bool ok) | |
{ | |
bytes32 hash = sha3(this,id,to,value); | |
if(owner == hash.checkSig(sig)) { | |
_balances[to] = _balances[to].safeAdd(value); | |
_supply = _supply.safeAdd(value); | |
return true; | |
} | |
} | |
function burn(address target, uint256 value) returns (bool ok) | |
{ | |
require(value >= minimum); | |
_balances[msg.sender] = _balances[msg.sender].safeSub(value); | |
_supply = _supply.safeSub(value); | |
onWithdraw(nextId,target,value); | |
nextId++; | |
return true; | |
} | |
function () { | |
revert(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment