public void SendToken(Address targetChainAddress, Address from, Address to, string symbol, BigInteger tokenID) { Runtime.Expect(IsWitness(from), "invalid witness"); Runtime.Expect(IsAddressOfParentChain(targetChainAddress) || IsAddressOfChildChain(targetChainAddress), "source must be parent or child chain"); Runtime.Expect(!to.IsInterop, "destination cannot be interop address"); var targetChain = this.Runtime.Nexus.FindChainByAddress(targetChainAddress); Runtime.Expect(this.Runtime.Nexus.TokenExists(symbol), "invalid token"); var tokenInfo = this.Runtime.Nexus.GetTokenInfo(symbol); Runtime.Expect(!tokenInfo.Flags.HasFlag(TokenFlags.Fungible), "must be non-fungible token"); if (tokenInfo.IsCapped()) { var supplies = new SupplySheet(symbol, this.Runtime.Chain, Runtime.Nexus); BigInteger amount = 1; if (IsAddressOfParentChain(targetChainAddress)) { Runtime.Expect(supplies.MoveToParent(this.Storage, amount), "source supply check failed"); } else // child chain { Runtime.Expect(supplies.MoveToChild(this.Storage, this.Runtime.Chain.Name, amount), "source supply check failed"); } } Runtime.Expect(Runtime.Nexus.TransferToken(Runtime, symbol, from, targetChainAddress, tokenID), "take token failed"); Runtime.Notify(EventKind.TokenBurn, from, new TokenEventData() { symbol = symbol, value = tokenID, chainAddress = Runtime.Chain.Address }); Runtime.Notify(EventKind.TokenEscrow, to, new TokenEventData() { symbol = symbol, value = tokenID, chainAddress = targetChainAddress }); }
public void SendTokens(Address targetChainAddress, Address from, Address to, string symbol, BigInteger amount) { Runtime.Expect(IsWitness(from), "invalid witness"); Runtime.Expect(IsAddressOfParentChain(targetChainAddress) || IsAddressOfChildChain(targetChainAddress), "target must be parent or child chain"); var targetChain = this.Runtime.Nexus.FindChainByAddress(targetChainAddress); Runtime.Expect(this.Runtime.Nexus.TokenExists(symbol), "invalid token"); var tokenInfo = this.Runtime.Nexus.GetTokenInfo(symbol); Runtime.Expect(tokenInfo.Flags.HasFlag(TokenFlags.Fungible), "must be fungible token"); 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, this.Runtime.Chain.Name, amount), "source supply check failed"); } } Runtime.Expect(Runtime.Nexus.BurnTokens(symbol, this.Storage, this.Runtime.Chain, from, amount), "burn failed"); Runtime.Notify(EventKind.TokenBurn, from, new TokenEventData() { symbol = symbol, value = amount, chainAddress = Runtime.Chain.Address }); Runtime.Notify(EventKind.TokenEscrow, to, new TokenEventData() { symbol = symbol, value = amount, chainAddress = targetChainAddress }); }