Created
December 5, 2022 16:35
-
-
Save blockative/8bc748c688f56d2d7b595977f83e858f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract ERC721MintBurn { | |
@state | |
public PubKeyHash owner; | |
@state | |
public int default_royalty; | |
@state | |
public HashedMap<int, PubKeyHash> tokenOwner; | |
@state | |
public HashedMap<int, bool> isBurned; | |
constructor(int royalty, PubKeyHash msgSender) { | |
this.owner = msgSender; | |
this.default_royalty = royalty; | |
} | |
public function mint(PubKeyHash recipient, int tokenId, Sig sig, PubKey pubKey, bool isBurned_tokenId, int i1, PubKeyHash tokenOwner_tokenId, int i0, SigHashPreimage txPreimage) { | |
PubKeyHash msgSender = hash160(pubKey); | |
require(checkSig(sig, pubKey)); | |
require(msgSender == this.owner); | |
require((!this.tokenOwner.has({tokenId, i0}) && tokenOwner_tokenId == Ripemd160(b'0000000000000000000000000000000000000000')) || this.tokenOwner.canGet({tokenId, i0}, tokenOwner_tokenId)); | |
tokenOwner_tokenId = recipient; | |
require((!this.isBurned.has({tokenId, i1}) && isBurned_tokenId == false) || this.isBurned.canGet({tokenId, i1}, isBurned_tokenId)); | |
isBurned_tokenId = false; | |
require(this.isBurned.set({tokenId, i1}, isBurned_tokenId)); | |
require(this.tokenOwner.set({tokenId, i0}, tokenOwner_tokenId)); | |
require(this.propagateState(txPreimage, SigHash.value(txPreimage))); | |
} | |
public function burn(int tokenId, Sig sig, PubKey pubKey, bool isBurned_tokenId, int i0, PubKeyHash tokenOwner_tokenId, int i1, SigHashPreimage txPreimage) { | |
PubKeyHash msgSender = hash160(pubKey); | |
require(checkSig(sig, pubKey)); | |
require(msgSender == this.owner); | |
require((!this.isBurned.has({tokenId, i0}) && isBurned_tokenId == false) || this.isBurned.canGet({tokenId, i0}, isBurned_tokenId)); | |
require(!isBurned_tokenId); | |
isBurned_tokenId = true; | |
require((!this.tokenOwner.has({tokenId, i1}) && tokenOwner_tokenId == Ripemd160(b'0000000000000000000000000000000000000000')) || this.tokenOwner.canGet({tokenId, i1}, tokenOwner_tokenId)); | |
tokenOwner_tokenId = Ripemd160(b'0000000000000000000000000000000000000000'); | |
require(this.isBurned.set({tokenId, i0}, isBurned_tokenId)); | |
require(this.tokenOwner.set({tokenId, i1}, tokenOwner_tokenId)); | |
require(this.propagateState(txPreimage, SigHash.value(txPreimage))); | |
} | |
public function setDefaultRoyalty(int royalty, Sig sig, PubKey pubKey, SigHashPreimage txPreimage) { | |
PubKeyHash msgSender = hash160(pubKey); | |
require(checkSig(sig, pubKey)); | |
require(msgSender == this.owner); | |
this.default_royalty = royalty; | |
require(this.propagateState(txPreimage, SigHash.value(txPreimage))); | |
} | |
public function balanceOf(PubKeyHash owner, int retVal, bool isBurned_i, int i0, PubKeyHash tokenOwner_i, int i1, SigHashPreimage txPreimage) { | |
int count = 0; | |
int i = 0; | |
loop (__LoopCount__0) { | |
if (i < this.isBurned.length()) { | |
require((!this.isBurned.has({i, i0}) && isBurned_i == false) || this.isBurned.canGet({i, i0}, isBurned_i)); | |
require((!this.tokenOwner.has({i, i1}) && tokenOwner_i == Ripemd160(b'0000000000000000000000000000000000000000')) || this.tokenOwner.canGet({i, i1}, tokenOwner_i)); | |
if (!isBurned_i && tokenOwner_i == owner) { | |
count++; | |
} | |
i++; | |
} | |
} | |
require(count == retVal); | |
require(this.propagateState(txPreimage, SigHash.value(txPreimage))); | |
} | |
public function ownerOf(int tokenId, PubKeyHash retVal, PubKeyHash tokenOwner_tokenId, int i0, SigHashPreimage txPreimage) { | |
require((!this.tokenOwner.has({tokenId, i0}) && tokenOwner_tokenId == Ripemd160(b'0000000000000000000000000000000000000000')) || this.tokenOwner.canGet({tokenId, i0}, tokenOwner_tokenId)); | |
require(tokenOwner_tokenId == retVal); | |
require(this.propagateState(txPreimage, SigHash.value(txPreimage))); | |
} | |
public function safeTransferFrom(PubKeyHash from, PubKeyHash to, int tokenId, bytes data, Sig sig, PubKey pubKey, SigHashPreimage txPreimage) { | |
PubKeyHash msgSender = hash160(pubKey); | |
require(checkSig(sig, pubKey)); | |
require(msgSender == from || msgSender == this.owner); | |
this.transferFrom(from, to, tokenId); | |
require(this.propagateState(txPreimage, SigHash.value(txPreimage))); | |
} | |
public function transferFrom(PubKeyHash from, PubKeyHash to, int tokenId, Sig sig, PubKey pubKey, bool isBurned_tokenId, int i0, PubKeyHash tokenOwner_tokenId, int i1, SigHashPreimage txPreimage) { | |
PubKeyHash msgSender = hash160(pubKey); | |
require(checkSig(sig, pubKey)); | |
require(msgSender == from || msgSender == this.owner); | |
require((!this.isBurned.has({tokenId, i0}) && isBurned_tokenId == false) || this.isBurned.canGet({tokenId, i0}, isBurned_tokenId)); | |
require(!isBurned_tokenId); | |
require((!this.tokenOwner.has({tokenId, i1}) && tokenOwner_tokenId == Ripemd160(b'0000000000000000000000000000000000000000')) || this.tokenOwner.canGet({tokenId, i1}, tokenOwner_tokenId)); | |
require(tokenOwner_tokenId == from); | |
tokenOwner_tokenId = to; | |
require(this.tokenOwner.set({tokenId, i1}, tokenOwner_tokenId)); | |
require(this.propagateState(txPreimage, SigHash.value(txPreimage))); | |
} | |
public function approve(PubKeyHash to, int tokenId, Sig sig, PubKey pubKey, PubKeyHash tokenOwner_tokenId, int i0, SigHashPreimage txPreimage) { | |
PubKeyHash msgSender = hash160(pubKey); | |
require(checkSig(sig, pubKey)); | |
require((!this.tokenOwner.has({tokenId, i0}) && tokenOwner_tokenId == Ripemd160(b'0000000000000000000000000000000000000000')) || this.tokenOwner.canGet({tokenId, i0}, tokenOwner_tokenId)); | |
require(msgSender == tokenOwner_tokenId); | |
require(this.propagateState(txPreimage, SigHash.value(txPreimage))); | |
} | |
public function getApproved(int tokenId, PubKeyHash retVal, SigHashPreimage txPreimage) { | |
require(Ripemd160(b'0000000000000000000000000000000000000000') == retVal); | |
require(this.propagateState(txPreimage, SigHash.value(txPreimage))); | |
} | |
public function setApprovalForAll(PubKeyHash to, bool approved, Sig sig, PubKey pubKey, SigHashPreimage txPreimage) { | |
PubKeyHash msgSender = hash160(pubKey); | |
require(checkSig(sig, pubKey)); | |
require(msgSender == this.owner); | |
require(this.propagateState(txPreimage, SigHash.value(txPreimage))); | |
} | |
public function isApprovedForAll(PubKeyHash owner, PubKeyHash operator, bool retVal, SigHashPreimage txPreimage) { | |
require(false == retVal); | |
require(this.propagateState(txPreimage, SigHash.value(txPreimage))); | |
} | |
function propagateState(SigHashPreimage txPreimage, int value) : bool { | |
require(Tx.checkPreimage(txPreimage)); | |
bytes outputScript = this.getStateScript(); | |
bytes output = Utils.buildOutput(outputScript, value); | |
return hash256(output) == SigHash.hashOutputs(txPreimage); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment