Beispiel #1
0
        public async Task <string> CrossChainTransferToken(bool isFungible, KeyPair keyPair, string addressTo,
                                                           string chainName, string destinationChain, string symbol, string amountId)
        {
            try
            {
                var toChain            = PhantasmaChains.Find(p => p.Name == destinationChain);
                var destinationAddress = Address.FromText(addressTo);
                int decimals           = PhantasmaTokens.SingleOrDefault(t => t.Symbol == symbol).Decimals;
                var bigIntAmount       = UnitConversion.ToBigInteger(decimal.Parse(amountId), decimals);
                var fee = UnitConversion.ToBigInteger(0.0001m, 8);

                var script = isFungible
                    ? ScriptUtils.BeginScript()
                             .AllowGas(keyPair.Address, Address.Null, 1, 9999)
                             .CrossTransferToken(Address.FromText(toChain.Address), symbol, keyPair.Address,
                                                 keyPair.Address, fee)
                             .CrossTransferToken(Address.FromText(toChain.Address), symbol, keyPair.Address,
                                                 destinationAddress, bigIntAmount)
                             .SpendGas(keyPair.Address)
                             .EndScript()

                    : ScriptUtils.BeginScript()
                             .AllowGas(keyPair.Address, Address.Null, 1, 9999)
                             .CrossTransferNFT(Address.FromText(toChain.Address), symbol, keyPair.Address,
                                               destinationAddress, bigIntAmount)
                             .SpendGas(keyPair.Address)
                             .EndScript();

                var nexusName = "simnet";

                var tx = new Blockchain.Transaction(nexusName, chainName, script, DateTime.UtcNow + TimeSpan.FromHours(1));
                tx.Sign(keyPair);

                var txResult = await _phantasmaRpcService.SendRawTx.SendRequestAsync(tx.ToByteArray(true).Encode());

                return(txResult);
            }
            catch (RpcResponseException rpcEx)
            {
                Debug.WriteLine($"RPC Exception occurred: {rpcEx.RpcError.Message}");
                return(null);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception occurred: {ex.Message}");
                return(null);
            }
        }
Beispiel #2
0
        public async Task <string> SettleBlockTransfer(KeyPair keyPair, string sourceChainAddress, string blockHash,
                                                       string destinationChainAddress)
        {
            try
            {
                var sourceChain          = Address.FromText(sourceChainAddress);
                var destinationChainName =
                    PhantasmaChains.SingleOrDefault(c => c.Address == destinationChainAddress).Name;
                var nexusName = "simnet";

                var block = Hash.Parse(blockHash);

                var settleTxScript = ScriptUtils.BeginScript()
                                     .CallContract("token", "SettleBlock", sourceChain, block)
                                     .AllowGas(keyPair.Address, Address.Null, 1, 9999)
                                     .SpendGas(keyPair.Address)
                                     .EndScript();

                var settleTx = new Blockchain.Transaction(nexusName, destinationChainName, settleTxScript, DateTime.UtcNow + TimeSpan.FromHours(1));
                settleTx.Sign(keyPair);

                var settleResult =
                    await _phantasmaRpcService.SendRawTx.SendRequestAsync(settleTx.ToByteArray(true).Encode());

                return(settleResult);
            }
            catch (RpcResponseException rpcEx)
            {
                Debug.WriteLine($"RPC Exception occurred: {rpcEx.RpcError.Message}");
                return(null);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception occurred: {ex.Message}");
                return(null);
            }
        }