Exemplo n.º 1
0
        public async Task <string> SignTransactionExternallyAsync(TransactionInput transaction,
                                                                  CancellationToken cancellationToken = default(CancellationToken))
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }
            if (!string.Equals(transaction.From.EnsureHexPrefix(), Account.Address.EnsureHexPrefix(), StringComparison.CurrentCultureIgnoreCase))
            {
                throw new Exception("Invalid account used signing");
            }
            SetDefaultGasPriceAndCostIfNotSet(transaction);

            var nonce = transaction.Nonce;

            if (nonce == null)
            {
                throw new ArgumentNullException(nameof(transaction), "Transaction nonce has not been set");
            }

            var gasPrice = transaction.GasPrice;
            var gasLimit = transaction.Gas;

            var value = transaction.Value ?? new HexBigInteger(0);

            string signedTransaction;

            var externalSigner = ((ExternalAccount)Account).ExternalSigner;

            if (ChainId == null)
            {
                signedTransaction = await _transactionSigner.SignTransactionAsync(externalSigner,
                                                                                  transaction.To,
                                                                                  value.Value, nonce,
                                                                                  gasPrice.Value, gasLimit.Value, transaction.Data).ConfigureAwait(false);
            }
            else
            {
                signedTransaction = await _transactionSigner.SignTransactionAsync(externalSigner, ChainId.Value,
                                                                                  transaction.To,
                                                                                  value.Value, nonce,
                                                                                  gasPrice.Value, gasLimit.Value, transaction.Data);
            }

            return(signedTransaction);
        }
        public async Task <string> SignTransactionExternallyAsync(TransactionInput transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }
            if (!transaction.From.IsTheSameAddress(Account.Address))
            {
                throw new Exception("Invalid account used signing");
            }
            SetDefaultGasPriceAndCostIfNotSet(transaction);

            var nonce = transaction.Nonce;

            if (nonce == null)
            {
                throw new ArgumentNullException(nameof(transaction), "Transaction nonce has not been set");
            }

            var gasPrice = transaction.GasPrice;
            var gasLimit = transaction.Gas;

            var value = transaction.Value ?? new HexBigInteger(0);

            string signedTransaction;

            var externalSigner = ((ExternalAccount)Account).ExternalSigner;

            if (ChainId == null)
            {
                signedTransaction = await _transactionSigner.SignTransactionAsync(externalSigner,
                                                                                  transaction.To,
                                                                                  value.Value, nonce,
                                                                                  gasPrice.Value, gasLimit.Value, transaction.Data).ConfigureAwait(false);
            }
            else
            {
                signedTransaction = await _transactionSigner.SignTransactionAsync(externalSigner, ChainId.Value,
                                                                                  transaction.To,
                                                                                  value.Value, nonce,
                                                                                  gasPrice.Value, gasLimit.Value, transaction.Data);
            }

            return(signedTransaction);
        }