-
Notifications
You must be signed in to change notification settings - Fork 39
/
00h_payment_channel.bbo
33 lines (31 loc) · 1013 Bytes
/
00h_payment_channel.bbo
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
// based on https://medium.com/@matthewdif/ethereum-payment-channel-in-50-lines-of-code-a94fad2704bc
contract Channel
( address channelSender
, address channelRecipient
, uint256 startDate
, uint256 endDate
, bytes32 => address signatures
)
{
case(void CloseChannel(bytes32 h, uint8 v, bytes32 r, bytes32 s, uint256 val)) {
address signer = pre_ecdsarecover(h, v, r, s);
if ((signer != channelSender) && (signer != channelRecipient)) abort;
bytes32 proof = keccak256(this, val);
if (proof != h) abort;
if (iszero(signatures[proof])) {
signatures[proof] = signer;
return then become Channel(channelSender, channelRecipient, startDate, endDate, signatures);
}
else if (signatures[proof] != signer) {
void = channelRecipient.default() with val reentrance { abort; }; // failure throws.
selfdestruct(channelSender);
}
else
abort;
}
case(void ChannelTimeOut()) {
if (endDate > now(block))
abort;
selfdestruct(channelSender);
}
}