网赚论坛
标题:
智能合约:锁定5枚以太币,2065年见
[打印本页]
作者:
tup63304dmv
时间:
2017-11-24 21:59
标题:
智能合约:锁定5枚以太币,2065年见
智能合约:锁定5枚以太币,2065年见
这个哥们挺有意思,写了个智能合同,把5枚以太币,锁定了50年,预计2065年释放出来。结果后来给人找到了bug,结果他自已提出来后,修复了bug,然后又存进去了。
代码如下:
//0xdb30622d51e8d6221f0b1cbde57d4734387d7ca1
contract Locker {
mapping(address => mapping(uint => uint)) locker;
event Locked(address indexed _addr, uint _timestamp, uint _value);
event Withdrew(address indexed _addr, uint _timestamp, uint _value);
function lockUntil(uint _timestamp) returns (bool _success) {
if(_timestamp > now) { //only lock into the future.
locker[msg.sender][_timestamp] += msg.value;
Locked(msg.sender, _timestamp, msg.value);
return true;
} else {
msg.sender.send(msg.value); //send back. Perhaps replace with exception?
return false;
}
}
function withdrawAtTimestamp(uint _timestamp) returns (bool _success) {
//you can set an arb timestamp into the past & thus will return true
//but doesn't help since you can only set timestamps into the future.
if(now >= _timestamp && locker[msg.sender][_timestamp] > 0) {
msg.sender.send(locker[msg.sender][_timestamp]);
locker[msg.sender][_timestamp] = 0;
Withdrew(msg.sender, _timestamp, locker[msg.sender][_timestamp]);
return true;
} else {
return false;
}
}}
复制代码
来源:https://gist.github.com/simondlr/627400ade47dcd822e18
欢迎光临 网赚论坛 (http://www.caifuba.net/)
Powered by Discuz! X3.1