-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathannouncement.cash
More file actions
28 lines (25 loc) · 1.21 KB
/
announcement.cash
File metadata and controls
28 lines (25 loc) · 1.21 KB
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
pragma cashscript ^0.12.0;
/* This is a contract showcasing covenants outside of regular transactional use.
* It enforces the contract to make an "announcement" on Memo.cash, and send the
* remainder of contract funds back to the contract.
*/
contract Announcement() {
function announce() {
// Create the memo.cash announcement output
bytes announcement = new LockingBytecodeNullData([
0x6d02,
bytes('A contract may not injure a human being or, through inaction, allow a human being to come to harm.')
]);
// Check that the first tx output matches the announcement
require(tx.outputs[0].value == 0);
require(tx.outputs[0].lockingBytecode == announcement);
// Calculate leftover money after fee (1000 sats)
// Check that the second tx output sends the change back if there's enough leftover for another announcement
int minerFee = 1000;
int changeAmount = tx.inputs[this.activeInputIndex].value - minerFee;
if (changeAmount >= minerFee) {
require(tx.outputs[1].lockingBytecode == tx.inputs[this.activeInputIndex].lockingBytecode);
require(tx.outputs[1].value == changeAmount);
}
}
}