-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathmecenas.cash
34 lines (29 loc) · 1.42 KB
/
mecenas.cash
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
pragma cashscript ^0.10.0;
/* This is an unofficial CashScript port of Licho's Mecenas contract. It is
* not compatible with Licho's EC plugin, but rather meant as a demonstration
* of covenants in CashScript.
* The time checking has been removed so it can be tested without time requirements.
*/
contract Mecenas(bytes20 recipient, bytes20 funder, int pledge/*, int period */) {
function receive() {
// require(tx.age >= period);
// Check that the first output sends to the recipient
require(tx.outputs[0].lockingBytecode == new LockingBytecodeP2PKH(recipient));
int minerFee = 1000;
int currentValue = tx.inputs[this.activeInputIndex].value;
int changeValue = currentValue - pledge - minerFee;
// If there is not enough left for *another* pledge after this one, we send the remainder to the recipient
// Otherwise we send the remainder to the recipient and the change back to the contract
if (changeValue <= pledge + minerFee) {
require(tx.outputs[0].value == currentValue - minerFee);
} else {
require(tx.outputs[0].value == pledge);
require(tx.outputs[1].lockingBytecode == tx.inputs[this.activeInputIndex].lockingBytecode);
require(tx.outputs[1].value == changeValue);
}
}
function reclaim(pubkey pk, sig s) {
require(hash160(pk) == funder);
require(checkSig(s, pk));
}
}