private void DoSettlement(Chain sourceChain, Address targetAddress, TokenEventData data)
        {
            var symbol = data.symbol;
            var value  = data.value;

            Runtime.Expect(value > 0, "value must be greater than zero");
            Runtime.Expect(targetAddress != Address.Null, "target must not be null");

            var token = this.Runtime.Nexus.FindTokenBySymbol(symbol);

            Runtime.Expect(token != null, "invalid token");

            if (token.IsCapped)
            {
                var sourceSupplies = sourceChain.GetTokenSupplies(token);
                var targetSupplies = this.Runtime.Chain.GetTokenSupplies(token);

                if (IsParentChain(sourceChain.Address))
                {
                    Runtime.Expect(sourceSupplies.MoveToChild(this.Runtime.Chain, value), "source supply check failed");
                    Runtime.Expect(targetSupplies.MoveFromParent(value), "target supply check failed");
                }
                else // child chain
                {
                    Runtime.Expect(sourceSupplies.MoveToParent(value), "source supply check failed");
                    Runtime.Expect(targetSupplies.MoveFromChild(this.Runtime.Chain, value), "target supply check failed");
                }
            }

            if (token.Flags.HasFlag(TokenFlags.Fungible))
            {
                var balances = this.Runtime.Chain.GetTokenBalances(token);
                Runtime.Expect(token.Mint(balances, targetAddress, value), "mint failed");
            }
            else
            {
                var ownerships = this.Runtime.Chain.GetTokenOwnerships(token);
                Runtime.Expect(ownerships.Give(targetAddress, value), "give token failed");

                var nft = this.Runtime.Nexus.GetNFT(token, value);
                nft.CurrentChain = Runtime.Chain.Address;
                nft.CurrentOwner = targetAddress;
            }

            Runtime.Notify(EventKind.TokenReceive, targetAddress, new TokenEventData()
            {
                symbol = symbol, value = value, chainAddress = sourceChain.Address
            });
        }
        private void DoSettlement(Chain sourceChain, Address targetAddress, TokenEventData data)
        {
            var symbol = data.symbol;
            var value  = data.value;

            Runtime.Expect(value > 0, "value must be greater than zero");
            Runtime.Expect(targetAddress != Address.Null, "target must not be null");

            Runtime.Expect(this.Runtime.Nexus.TokenExists(symbol), "invalid token");
            var tokenInfo = this.Runtime.Nexus.GetTokenInfo(symbol);

            if (tokenInfo.IsCapped)
            {
                var sourceSupplies = sourceChain.GetTokenSupplies(symbol);
                var targetSupplies = this.Runtime.Chain.GetTokenSupplies(symbol);

                if (IsAddressOfParentChain(sourceChain.Address))
                {
                    Runtime.Expect(targetSupplies.MoveFromParent(value), "target supply check failed");
                }
                else // child chain
                {
                    Runtime.Expect(targetSupplies.MoveFromChild(this.Runtime.Chain, value), "target supply check failed");
                }
            }

            if (tokenInfo.Flags.HasFlag(TokenFlags.Fungible))
            {
                var balances = this.Runtime.Chain.GetTokenBalances(symbol);
                var supplies = tokenInfo.IsCapped ? this.Runtime.Chain.GetTokenSupplies(symbol) : null;
                Runtime.Expect(Runtime.Nexus.MintTokens(symbol, this.Storage, balances, supplies, targetAddress, value), "mint failed");
            }
            else
            {
                var ownerships = this.Runtime.Chain.GetTokenOwnerships(symbol);
                Runtime.Expect(ownerships.Give(this.Storage, targetAddress, value), "give token failed");
                Runtime.Expect(Runtime.Nexus.MintToken(symbol), "mint failed");

                this.Runtime.Nexus.EditNFTLocation(symbol, value, Runtime.Chain.Address, targetAddress);
            }

            Runtime.Notify(EventKind.TokenReceive, targetAddress, new TokenEventData()
            {
                symbol = symbol, value = value, chainAddress = sourceChain.Address
            });
        }
Beispiel #3
0
        private void DoSettlement(Chain sourceChain, Address targetAddress, TokenEventData data)
        {
            var symbol = data.symbol;
            var value  = data.value;

            Runtime.Expect(value > 0, "value must be greater than zero");
            Runtime.Expect(targetAddress.IsUser, "target must not user address");

            Runtime.Expect(this.Runtime.Nexus.TokenExists(symbol), "invalid token");
            var tokenInfo = this.Runtime.Nexus.GetTokenInfo(symbol);

            if (tokenInfo.IsCapped())
            {
                var supplies = new SupplySheet(symbol, this.Runtime.Chain, Runtime.Nexus);

                if (IsAddressOfParentChain(sourceChain.Address))
                {
                    Runtime.Expect(supplies.MoveFromParent(this.Storage, value), "target supply check failed");
                }
                else // child chain
                {
                    Runtime.Expect(supplies.MoveFromChild(this.Storage, sourceChain.Name, value), "target supply check failed");
                }
            }

            if (tokenInfo.Flags.HasFlag(TokenFlags.Fungible))
            {
                Runtime.Expect(Runtime.Nexus.MintTokens(Runtime, symbol, targetAddress, value, true), "mint failed");
            }
            else
            {
                Runtime.Expect(Runtime.Nexus.MintToken(Runtime, symbol, targetAddress, value, true), "mint failed");
            }

            Runtime.Notify(EventKind.TokenReceive, targetAddress, new TokenEventData()
            {
                symbol = symbol, value = value, chainAddress = sourceChain.Address
            });
        }