-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathhodl_vault.cash
31 lines (27 loc) · 1.28 KB
/
hodl_vault.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
pragma cashscript ^0.10.0;
// This contract forces HODLing until a certain price target has been reached
// A minimum block is provided to ensure that oracle price entries from before this block are disregarded
// i.e. when the BCH price was $1000 in the past, an oracle entry with the old block number and price can not be used.
// Instead, a message with a block number and price from after the minBlock needs to be passed.
// This contract serves as a simple example for checkDataSig-based contracts.
contract HodlVault(
pubkey ownerPk,
pubkey oraclePk,
int minBlock,
int priceTarget
) {
function spend(sig ownerSig, datasig oracleSig, bytes oracleMessage) {
// message: { blockHeight, price }
bytes4 blockHeightBin, bytes4 priceBin = oracleMessage.split(4);
int blockHeight = int(blockHeightBin);
int price = int(priceBin);
// Check that blockHeight is after minBlock and not in the future
require(blockHeight >= minBlock);
require(tx.time >= blockHeight);
// Check that current price is at least priceTarget
require(price >= priceTarget);
// Handle necessary signature checks
require(checkDataSig(oracleSig, oracleMessage, oraclePk));
require(checkSig(ownerSig, ownerPk));
}
}