forked from skydogch/coinlock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redeem.js
52 lines (47 loc) · 1.82 KB
/
redeem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(function () {
var contractCode = [
'contract owned {',
' function owned() {',
' owner = msg.sender;',
' }',
' modifier onlyowner() { ',
' if (msg.sender == owner)',
' _',
' }',
' address owner;',
'}',
'contract CoinLock is owned {',
' uint public expiration; // Timestamp in # of seconds.',
' ',
' function lock(uint _expiration) onlyowner returns (bool) {',
' if (_expiration > block.timestamp && expiration == 0) {',
' expiration = _expiration;',
' return true;',
' }',
' return false;',
' }',
' function redeem() onlyowner {',
' if (block.timestamp > expiration) {',
' suicide(owner);',
' }',
' }',
'}'
].join("\n");
var build = eth.compile.solidity(contractCode).CoinLock;
function redeemLock(address) {
web3.personal.unlockAccount(web3.eth.defaultAccount);
var contract = web3.eth.contract(build.info.abiDefinition).at(address);
var redemptionTx = contract.redeem({from: web3.eth.defaultAccount, gas: 180000});
console.log("Redemption tx is " + redemptionTx);
};
if (typeof(address) == "undefined") {
console.error("You must set the 'address' variable first!");
} else if (typeof(web3.eth.defaultAccount) == "undefined") {
console.error("You must set 'web3.eth.defaultAddress' first!");
console.error("Needs to be the same as the address you used to create the lock.");
} else {
console.log("Everything looks in order.");
console.log("Retrieving coins at " + address);
redeemLock(address);
}
})();