示例#1
0
        // NFT version
        internal bool MintToken(string symbol, StorageContext storage, Chain chain, Address target, BigInteger tokenID)
        {
            if (!TokenExists(symbol))
            {
                return(false);
            }

            var tokenInfo = GetTokenInfo(symbol);

            if (tokenInfo.Flags.HasFlag(TokenFlags.Fungible))
            {
                return(false);
            }

            var supply = new SupplySheet(symbol, chain, this);

            if (!supply.Mint(storage, 1, tokenInfo.MaxSupply))
            {
                return(false);
            }

            var ownerships = new OwnershipSheet(symbol);

            if (!ownerships.Give(storage, target, tokenID))
            {
                return(false);
            }

            EditNFTLocation(symbol, tokenID, chain.Address, target);
            return(true);
        }
示例#2
0
        // NFT version
        internal bool MintToken(RuntimeVM runtimeVM, string symbol, Address target, BigInteger tokenID)
        {
            if (!TokenExists(symbol))
            {
                return(false);
            }

            var tokenInfo = GetTokenInfo(symbol);

            if (tokenInfo.Flags.HasFlag(TokenFlags.Fungible))
            {
                return(false);
            }

            var supply = new SupplySheet(symbol, runtimeVM.Chain, this);

            if (!supply.Mint(runtimeVM.ChangeSet, 1, tokenInfo.MaxSupply))
            {
                return(false);
            }

            var ownerships = new OwnershipSheet(symbol);

            if (!ownerships.Give(runtimeVM.ChangeSet, target, tokenID))
            {
                return(false);
            }

            var tokenTriggerResult = SmartContract.InvokeTrigger(runtimeVM, tokenInfo.Script, TokenContract.TriggerMint, target, tokenID);

            if (!tokenTriggerResult)
            {
                return(false);
            }

            var accountScript        = this.LookUpAddressScript(target);
            var accountTriggerResult = SmartContract.InvokeTrigger(runtimeVM, accountScript, AccountContract.TriggerMint, target, tokenID);

            if (!accountTriggerResult)
            {
                return(false);
            }

            EditNFTLocation(symbol, tokenID, runtimeVM.Chain.Address, target);
            return(true);
        }
示例#3
0
        internal bool TransferToken(string symbol, StorageContext storage, Chain chain, Address source, Address destination, BigInteger tokenID)
        {
            if (!TokenExists(symbol))
            {
                return(false);
            }

            var tokenInfo = GetTokenInfo(symbol);

            if (!tokenInfo.Flags.HasFlag(TokenFlags.Transferable))
            {
                throw new Exception("Not transferable");
            }

            if (tokenInfo.Flags.HasFlag(TokenFlags.Fungible))
            {
                throw new Exception("Should be non-fungible");
            }

            if (tokenID <= 0)
            {
                return(false);
            }

            var ownerships = new OwnershipSheet(symbol);

            if (!ownerships.Take(storage, source, tokenID))
            {
                return(false);
            }

            if (!ownerships.Give(storage, destination, tokenID))
            {
                return(false);
            }

            EditNFTLocation(symbol, tokenID, chain.Address, destination);
            return(true);
        }
示例#4
0
        internal bool TransferToken(RuntimeVM runtimeVM, string symbol, Address source, Address destination, BigInteger tokenID)
        {
            if (!TokenExists(symbol))
            {
                return(false);
            }

            var tokenInfo = GetTokenInfo(symbol);

            if (!tokenInfo.Flags.HasFlag(TokenFlags.Transferable))
            {
                throw new Exception("Not transferable");
            }

            if (tokenInfo.Flags.HasFlag(TokenFlags.Fungible))
            {
                throw new Exception("Should be non-fungible");
            }

            if (tokenID <= 0)
            {
                return(false);
            }

            var ownerships = new OwnershipSheet(symbol);

            if (!ownerships.Take(runtimeVM.ChangeSet, source, tokenID))
            {
                return(false);
            }

            if (!ownerships.Give(runtimeVM.ChangeSet, destination, tokenID))
            {
                return(false);
            }

            var tokenTriggerResult = SmartContract.InvokeTrigger(runtimeVM, tokenInfo.Script, TokenContract.TriggerSend, source, tokenID);

            if (!tokenTriggerResult)
            {
                return(false);
            }

            tokenTriggerResult = SmartContract.InvokeTrigger(runtimeVM, tokenInfo.Script, TokenContract.TriggerReceive, destination, tokenID);
            if (!tokenTriggerResult)
            {
                return(false);
            }

            var accountScript        = this.LookUpAddressScript(source);
            var accountTriggerResult = SmartContract.InvokeTrigger(runtimeVM, accountScript, AccountContract.TriggerSend, source, tokenID);

            if (!accountTriggerResult)
            {
                return(false);
            }

            accountScript        = this.LookUpAddressScript(destination);
            accountTriggerResult = SmartContract.InvokeTrigger(runtimeVM, accountScript, AccountContract.TriggerSend, destination, tokenID);
            if (!accountTriggerResult)
            {
                return(false);
            }

            EditNFTLocation(symbol, tokenID, runtimeVM.Chain.Address, destination);
            return(true);
        }