-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.js
59 lines (51 loc) · 1.28 KB
/
test.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
53
54
55
56
57
58
59
loadScript("/Users/jeffrey/dev/ethereum/payment_channel/payment_channel.js");
personal.unlockAccount(eth.accounts[0], "")
personal.unlockAccount(eth.accounts[1], "")
var receiver = shh.newIdentity()
sender = shh.newIdentity()
numbers = [3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8];
index = 0;
var tx = new PaymentChannel({
account: eth.accounts[0],
me: sender,
them: receiver,
role: PaymentChannel.payer,
payment: {
value: web3.toWei(2, "ether"),
base: web3.toWei(1, "ether"),
inc: 100000,
},
});
tx.onPayload = function(payload) {
console.log("received data", payload);
return true;
};
var rx = new PaymentChannel({
account: eth.accounts[1],
me: receiver,
them: sender,
role: PaymentChannel.beneficiary,
payment: {
base: web3.toWei(1, "ether"),
inc: 100000,
},
});
rx.onPayment = function(error, payment) {
if( error ) {
console.log("invalid payment:", error);
return false;
}
console.log("received payment", payment);
return true;
};
rx.data = function() {
// either run out of numbers or quit randomly
if( index == numbers.length) {
console.log("done")
rx.redeem();
return false;
}
return web3.toHex(numbers[index++]);
}
tx.start();
rx.start();