Esempio n. 1
0
        public void BurnToken(string symbol, Address target, BigInteger tokenID)
        {
            var Runtime = this;

            Runtime.Expect(IsWitness(target), "invalid witness");

            Runtime.Expect(Runtime.TokenExists(symbol), "invalid token");
            var token = Runtime.GetToken(symbol);

            Runtime.Expect(!token.IsFungible(), "token must be non-fungible");
            Runtime.Expect(token.IsBurnable(), "token must be burnable");

            Nexus.BurnToken(this, token, target, target, Chain.Name, tokenID);
        }
Esempio n. 2
0
        public void SwapTokens(string sourceChain, Address from, string targetChain, Address to, string symbol, BigInteger value, byte[] rom, byte[] ram)
        {
            var Runtime = this;

            Runtime.Expect(sourceChain != targetChain, "source chain and target chain must be different");
            Runtime.Expect(Runtime.TokenExists(symbol), "invalid token");

            var token = Runtime.GetToken(symbol);

            Runtime.Expect(token.Flags.HasFlag(TokenFlags.Transferable), "must be transferable token");

            if (token.IsFungible())
            {
                Runtime.Expect(rom == null, "fungible tokens cant have rom");
                Runtime.Expect(ram == null, "fungible tokens cant have ram");
            }
            else
            {
                Runtime.Expect(rom != null & rom.Length > 0, "nft rom is missing");
                Runtime.Expect(ram != null, "nft ram is missing");
            }

            if (PlatformExists(sourceChain))
            {
                Runtime.Expect(sourceChain != DomainSettings.PlatformName, "invalid platform as source chain");

                if (token.IsFungible())
                {
                    Nexus.MintTokens(this, token, from, to, sourceChain, value);
                }
                else
                {
                    Nexus.MintToken(this, token, from, to, sourceChain, value, rom, ram);
                }
            }
            else
            if (PlatformExists(targetChain))
            {
                Runtime.Expect(targetChain != DomainSettings.PlatformName, "invalid platform as target chain");
                Nexus.BurnTokens(this, token, from, to, targetChain, value);

                var swap = new ChainSwap(DomainSettings.PlatformName, sourceChain, Transaction.Hash, targetChain, targetChain, Hash.Null);
                this.Chain.RegisterSwap(this.Storage, to, swap);
            }
            else
            if (sourceChain == this.Chain.Name)
            {
                Runtime.Expect(IsNameOfParentChain(targetChain) || IsNameOfChildChain(targetChain), "target must be parent or child chain");
                Runtime.Expect(to.IsUser, "destination must be user address");
                Runtime.Expect(IsWitness(from), "invalid witness");

                /*if (tokenInfo.IsCapped())
                 * {
                 *  var sourceSupplies = new SupplySheet(symbol, this.Runtime.Chain, Runtime.Nexus);
                 *  var targetSupplies = new SupplySheet(symbol, targetChain, Runtime.Nexus);
                 *
                 *  if (IsAddressOfParentChain(targetChainAddress))
                 *  {
                 *      Runtime.Expect(sourceSupplies.MoveToParent(this.Storage, amount), "source supply check failed");
                 *  }
                 *  else // child chain
                 *  {
                 *      Runtime.Expect(sourceSupplies.MoveToChild(this.Storage, targetChain.Name, amount), "source supply check failed");
                 *  }
                 * }*/

                if (token.IsFungible())
                {
                    Nexus.BurnTokens(this, token, from, to, targetChain, value);
                }
                else
                {
                    Nexus.BurnToken(this, token, from, to, targetChain, value);
                }

                var swap = new ChainSwap(DomainSettings.PlatformName, sourceChain, Transaction.Hash, DomainSettings.PlatformName, targetChain, Hash.Null);
                this.Chain.RegisterSwap(this.Storage, to, swap);
            }
            else
            if (targetChain == this.Chain.Name)
            {
                Runtime.Expect(IsNameOfParentChain(sourceChain) || IsNameOfChildChain(sourceChain), "source must be parent or child chain");
                Runtime.Expect(!to.IsInterop, "destination cannot be interop address");
                Runtime.Expect(IsWitness(to), "invalid witness");

                if (token.IsFungible())
                {
                    Nexus.MintTokens(this, token, from, to, sourceChain, value);
                }
                else
                {
                    Nexus.MintToken(this, token, from, to, sourceChain, value, rom, ram);
                }
            }
            else
            {
                throw new ChainException("invalid swap chain source and destinations");
            }
        }