Exemple #1
0
        // NFT version
        internal bool BurnToken(string symbol, StorageContext storage, Address target, BigInteger tokenID)
        {
            if (!TokenExists(symbol))
            {
                return(false);
            }

            var tokenInfo = GetTokenInfo(symbol);

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

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

            if (!supply.Burn(storage, 1))
            {
                return(false);
            }

            var ownerships = new OwnershipSheet(symbol);

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

            return(true);
        }
        internal bool BurnTokens(string symbol, StorageContext storage, BalanceSheet balances, SupplySheet supply, Address target, BigInteger amount)
        {
            if (!TokenExists(symbol))
            {
                return(false);
            }

            var tokenInfo = GetTokenInfo(symbol);

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

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

            if (tokenInfo.IsCapped && !supply.Burn(amount))
            {
                return(false);
            }

            if (!balances.Subtract(storage, target, amount))
            {
                return(false);
            }

            EditTokenSupply(symbol, -amount);
            return(true);
        }
Exemple #3
0
        internal bool BurnTokens(string symbol, StorageContext storage, Chain chain, Address target, BigInteger amount)
        {
            if (!TokenExists(symbol))
            {
                return(false);
            }

            var tokenInfo = GetTokenInfo(symbol);

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

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

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

            if (tokenInfo.IsCapped && !supply.Burn(storage, amount))
            {
                return(false);
            }

            var balances = new BalanceSheet(symbol);

            if (!balances.Subtract(storage, target, amount))
            {
                return(false);
            }

            return(true);
        }
Exemple #4
0
        internal bool BurnTokens(RuntimeVM runtimeVM, string symbol, Address target, BigInteger amount)
        {
            if (!TokenExists(symbol))
            {
                return(false);
            }

            var tokenInfo = GetTokenInfo(symbol);

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

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

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

            if (tokenInfo.IsCapped && !supply.Burn(runtimeVM.ChangeSet, amount))
            {
                return(false);
            }

            var balances = new BalanceSheet(symbol);

            if (!balances.Subtract(runtimeVM.ChangeSet, target, amount))
            {
                return(false);
            }

            var tokenTriggerResult = SmartContract.InvokeTrigger(runtimeVM, tokenInfo.Script, TokenContract.TriggerBurn, target, amount);

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

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

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

            return(true);
        }
Exemple #5
0
        // NFT version
        internal bool BurnToken(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 chain  = RootChain;
            var supply = new SupplySheet(symbol, chain, this);

            if (!supply.Burn(runtimeVM.ChangeSet, 1))
            {
                return(false);
            }

            var ownerships = new OwnershipSheet(symbol);

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

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

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

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

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