-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmint.cash
83 lines (67 loc) · 3.09 KB
/
mint.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
pragma cashscript ^0.10.0;
// Multi-threaded minting smart contract
// Contract holds the next NFT nummber to mint as state in the commitment field of the minting NFT
// Contract consists of a mintNFT and a payout function
// Opcode count: 84 (max 201)
// Bytesize: 163 (max 520)
contract Mint(
int mintPrice,
int increment,
bytes20 pkhPayout,
int maximumCount
) {
function mintNFT() {
// require minting contract to be at input index zero
require(this.activeInputIndex == 0);
// Read nftNumber from contract commitment
bytes commitment = tx.inputs[0].nftCommitment;
int nftNumber = int(commitment);
// Check if minting is still allowed
require(nftNumber <= maximumCount);
// Limit the max number of outputs to 3
require(tx.outputs.length <= 3);
// Output#0 preserves the NFT minting contract with a minting nft holding the new state and increased BCH value
require(tx.outputs[0].lockingBytecode == tx.inputs[0].lockingBytecode);
require(tx.outputs[0].tokenCategory == tx.inputs[0].tokenCategory);
int nextNftNumber = nftNumber + increment;
require(tx.outputs[0].nftCommitment == bytes(nextNftNumber));
require(tx.outputs[0].value == tx.inputs[0].value + mintPrice);
// Output#1 for the minted NFT
require(tx.outputs[1].value == 1000);
require(tx.outputs[1].nftCommitment == bytes(nftNumber));
// Strip capability to get the tokenId for an immutable NFT
bytes tokenId = tx.inputs[0].tokenCategory.split(32)[0];
require(tx.outputs[1].tokenCategory == tokenId);
// Allow for BCH change output
if(tx.outputs.length == 3){
// Output#2 BCH change output for minter
require(tx.outputs[2].tokenCategory == 0x);
}
}
function payout(sig sigPayout, pubkey pkPayout) {
// Check the signature & public key against pkhPayout
require(hash160(pkPayout) == pkhPayout);
require(checkSig(sigPayout, pkPayout));
// require minting contract to be at input index zero
require(tx.inputs.length == 1);
// Read count from contract commitment
bytes commitment = tx.inputs[0].nftCommitment;
int nftNumber = int(commitment);
// Check if minting is still ongoing
if(nftNumber <= maximumCount){
// Limit the number of outputs to 2
require(tx.outputs.length == 2);
// Output#0 preserves the NFT minting contract with same minting nft
require(tx.outputs[0].lockingBytecode == tx.inputs[0].lockingBytecode);
require(tx.outputs[0].tokenCategory == tx.inputs[0].tokenCategory);
require(tx.outputs[0].nftCommitment == tx.inputs[0].nftCommitment);
// Output#1 payout output
require(tx.outputs[1].tokenCategory == 0x);
} else {
// Output#0 payout output
require(tx.outputs.length == 1);
// Burns minting NFT
require(tx.outputs[0].tokenCategory == 0x);
}
}
}