-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcc-covenant-testnet.cash
50 lines (40 loc) · 2.07 KB
/
cc-covenant-testnet.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
pragma cashscript ^0.7.2;
contract CCCovenant(bytes20 monitorPubkeysHash,
bytes20 operatorPubkeysHash) {
function redeemOrConvert(
sig sig0, sig sig1, sig sig2, sig sig3, sig sig4, sig sig5, sig sig6,
pubkey op0, pubkey op1, pubkey op2, pubkey op3, pubkey op4,
pubkey op5, pubkey op6, pubkey op7, pubkey op8, pubkey op9,
bytes newMonitorPubkeysHash,
bytes newOperatorPubkeysHash
) {
require(hash160(op0+op1+op2+op3+op4+op5+op6+op7+op8+op9) == operatorPubkeysHash);
require(checkMultiSig([sig0, sig1, sig2, sig3, sig4, sig5, sig6],
[op0, op1, op2, op3, op4, op5, op6, op7, op8, op9]));
require(tx.inputs.length == 1);
require(tx.outputs.length == 1);
require(tx.outputs[0].value >= tx.inputs[0].value - 20000); // max miner fee is hardcoded
if (newMonitorPubkeysHash.length > 0 || newOperatorPubkeysHash.length > 0) {
// convertByOperators
require(newMonitorPubkeysHash.length == 20);
require(newOperatorPubkeysHash.length == 20);
bytes newContract = 0x14 + newOperatorPubkeysHash + 0x14 + newMonitorPubkeysHash + this.activeBytecode.split(42)[1];
bytes23 newContractLock = new LockingBytecodeP2SH(hash160(newContract));
require(tx.outputs[0].lockingBytecode == newContractLock);
}
}
function convertByMonitors(
sig sig0, sig sig1,
pubkey m0, pubkey m1, pubkey m2,
bytes20 newOperatorPubkeysHash
) {
require(hash160(m0+m1+m2) == monitorPubkeysHash);
require(checkMultiSig([sig0, sig1], [m0, m1, m2]));
require(this.activeInputIndex == 0);
require(tx.outputs[0].value == tx.inputs[0].value);
require(tx.age >= 34560); // 6 * 24 * 30 * 8 ~= 8 months
bytes newContract = 0x14 + newOperatorPubkeysHash + this.activeBytecode.split(21)[1];
bytes23 newContractLock = new LockingBytecodeP2SH(hash160(newContract));
require(tx.outputs[0].lockingBytecode == newContractLock);
}
}