示例#1
0
        private void SignAndSendTx(Transaction tx)
        {
            ContractParametersContext context;

            try
            {
                context = new ContractParametersContext(tx);
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine($"Error creating contract params: " + GetExceptionMessage(e));
                throw;
            }
            CurrentWallet.Sign(context);
            if (context.Completed)
            {
                tx.Witnesses = context.GetWitnesses();
                NeoSystem.Blockchain.Tell(tx);
                Console.WriteLine($"Signed and relayed transaction with hash={tx.Hash}");
                return;
            }
            Console.WriteLine($"Failed sending transaction with hash={tx.Hash}");
        }
示例#2
0
        private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160 from = null, UInt160[] signerAccounts = null)
        {
            if (NoWallet())
            {
                return;
            }
            string password = ReadUserInput("password", true);

            if (password.Length == 0)
            {
                Console.WriteLine("Cancelled");
                return;
            }
            if (!CurrentWallet.VerifyPassword(password))
            {
                Console.WriteLine("Incorrect password");
                return;
            }

            Transaction     tx;
            AssetDescriptor descriptor = new AssetDescriptor(asset);

            if (!BigDecimal.TryParse(amount, descriptor.Decimals, out BigDecimal decimalAmount) || decimalAmount.Sign <= 0)
            {
                Console.WriteLine("Incorrect Amount Format");
                return;
            }
            try
            {
                tx = CurrentWallet.MakeTransaction(new[]
                {
                    new TransferOutput
                    {
                        AssetId    = asset,
                        Value      = decimalAmount,
                        ScriptHash = to
                    }
                }, from: from, cosigners: signerAccounts?.Select(p => new Signer
                {
                    // default access for transfers should be valid only for first invocation
                    Scopes  = WitnessScope.CalledByEntry,
                    Account = p
                })
                                                   .ToArray() ?? new Signer[0]);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + GetExceptionMessage(e));
                return;
            }

            if (tx == null)
            {
                Console.WriteLine("Insufficient funds");
                return;
            }

            ContractParametersContext context = new ContractParametersContext(tx);

            CurrentWallet.Sign(context);
            if (context.Completed)
            {
                tx.Witnesses = context.GetWitnesses();
                NeoSystem.Blockchain.Tell(tx);
                Console.WriteLine($"TXID: {tx.Hash}");
            }
            else
            {
                Console.WriteLine("SignatureContext:");
                Console.WriteLine(context.ToString());
            }
        }
示例#3
0
        private bool OnSendCommand(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("error");
                return(true);
            }
            if (NoWallet())
            {
                return(true);
            }
            string password = ReadUserInput("password", true);

            if (password.Length == 0)
            {
                Console.WriteLine("cancelled");
                return(true);
            }
            if (!CurrentWallet.VerifyPassword(password))
            {
                Console.WriteLine("Incorrect password");
                return(true);
            }
            UInt160 assetId;

            switch (args[1].ToLower())
            {
            case "neo":
                assetId = NativeContract.NEO.Hash;
                break;

            case "gas":
                assetId = NativeContract.GAS.Hash;
                break;

            default:
                assetId = UInt160.Parse(args[1]);
                break;
            }
            UInt160         to       = args[2].ToScriptHash();
            var             snapshot = NeoSystem.StoreView;
            Transaction     tx;
            AssetDescriptor descriptor = new AssetDescriptor(snapshot, CliSettings.Default.Protocol, assetId);

            if (!BigDecimal.TryParse(args[3], descriptor.Decimals, out BigDecimal amount) || amount.Sign <= 0)
            {
                Console.WriteLine("Incorrect Amount Format");
                return(true);
            }
            tx = CurrentWallet.MakeTransaction(snapshot, new[]
            {
                new TransferOutput
                {
                    AssetId    = assetId,
                    Value      = amount,
                    ScriptHash = to
                }
            });

            if (tx == null)
            {
                Console.WriteLine("Insufficient funds");
                return(true);
            }

            ContractParametersContext context = new ContractParametersContext(snapshot, tx, CliSettings.Default.Protocol.Network);

            CurrentWallet.Sign(context);
            if (context.Completed)
            {
                tx.Witnesses = context.GetWitnesses();
                NeoSystem.Blockchain.Tell(tx);
                //NeoSystem.LocalNode.Tell(new LocalNode.Relay { Inventory = tx });
                Console.WriteLine($"TXID: {tx.Hash}");
            }
            else
            {
                Console.WriteLine("SignatureContext:");
                Console.WriteLine(context.ToString());
            }

            return(true);
        }