pragma cashscript ^0.6.0;
contract NFT(bytes20 owner) {
// Warning: This method 'reclaim' should only be used in testing.
// Backdoor to reclaim funds,
function reclaim(pubkey pk, sig s) {
require(hash160(pk) == owner);
require(checkSig(s, pk));
}
// Warning: This method 'createNFTChild' should only be used in testing.
// Backdoor to reclaim funds,
function createNFTChild(pubkey pk, sig s) {
require(hash160(pk) == owner);
require(checkSig(s, pk));
}
function createNFTGroup(
pubkey pk,
sig s,
bytes20 recipientPkh,
string actionType,
string symbol,
string name,
string documentURI,
string documentHash,
int minerFee,
) {
require(hash160(pk) == owner);
require(checkSig(s, pk));
bytes announcement = new OutputNullData([
0x534c5000,
0x81,
bytes(actionType),
bytes(symbol),
bytes(name),
bytes(documentURI),
bytes(documentHash),
0x00,
0xff, // Trick: Keep this number above the number of transactions you would expect.
0x0000000000001388
]);
// Calculate leftover money after fee (1000 sats)
// Add change output if the remainder can be used
// otherwise donate the remainder to the miner
// int minerFee = 1000;
int dust = 546;
int changeAmount = int(bytes(tx.value)) - dust - minerFee;
// require(changeAmount > dust);
if (changeAmount >= minerFee) {
bytes34 recipient = new OutputP2PKH(bytes8(dust), recipientPkh);
bytes32 change = new OutputP2SH(bytes8(changeAmount), hash160(tx.bytecode));
require(hash256(announcement + recipient + change) == tx.hashOutputs);
} else {
require(hash256(announcement) == tx.hashOutputs);
}
}
}