Exemple #1
0
        /// <summary>Sign raw transaction hash by a specified wallet.</summary>
        /// <param name="client"><see cref="IQuorumTransactionSignerClient"/> instance.</param>
        /// <param name="address">Wallet address (20 bytes) in a hex format (40 hexadecimal symbols) prefixed with 0x.</param>
        /// <param name="rawTxHashes">Raw transaction hashes in the base64 encoding.</param>
        /// <returns>V, R and S parameters of the transaction signature.</returns>
        /// <exception cref="WalletNotFoundException">Throw, if a wallet for the specified address has not been found.</exception>
        public static async Task <List <(byte[] V, byte[] R, byte[] S)> > SignTransactionsAsync(
            [NotNull] this IQuorumTransactionSignerClient client,
            [NotNull] string address,
            [NotNull] List <byte[]> rawTxHashes)
        {
            var hashes   = rawTxHashes.Select(Convert.ToBase64String).ToList();
            var response = await client.WalletsApi.SignTransactionsBatchAsync(address, hashes);

            if (response.Error != SignTransactionError.None)
            {
                throw new WalletNotFoundException(address);
            }

            var result = new List <(byte[], byte[], byte[])>(hashes.Count);

            foreach (var hash in hashes)
            {
                var signedData = response.HashToSignedTxDict[hash];
                var r          = Convert.FromBase64String(signedData.R);
                var s          = Convert.FromBase64String(signedData.S);
                var v          = Convert.FromBase64String(signedData.V);
                result.Add((v, r, s));
            }

            return(result);
        }
Exemple #2
0
        /// <summary>Create new wallet.</summary>
        /// <returns>New wallet address.</returns>
        public static async Task <string> CreateWalletAsync(
            [NotNull] this IQuorumTransactionSignerClient client)
        {
            var response = await client.WalletsApi.CreateWalletAsync();

            return(response.Address);
        }
Exemple #3
0
        public OperationService(
            IEnumerable <IBuildTransactionStrategy> buildTransactionStrategies,
            IBlockchain ethereumApi,
            ILogFactory logFactory,
            IOperationRepository operationRepository,
            ITransactionService transactionService,
            IQuorumTransactionSignerClient transactionSigner,
            int?maxThreadCount = null)
        {
            _buildTransactionStrategies =
                buildTransactionStrategies.ToDictionary(x => x.SupportedOperationType, x => x);
            _ethereumApi         = ethereumApi;
            _log                 = logFactory.CreateLog(this);
            _operationRepository = operationRepository;
            _transactionService  = transactionService;
            _transactionSigner   = transactionSigner;
            _maxThreadCount      = maxThreadCount ?? DefaultMaxThreadCount;

            _sendTransactionRetryPolicy = Policy
                                          .Handle <RpcClientTimeoutException>()
                                          .WaitAndRetryAsync(
                DefaultRetryCount,
                attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)),
                (ex, _) => _log.Error("Sending transaction with retry", ex));
        }
Exemple #4
0
 public WalletsService(
     ILogFactory logFactory,
     ITransactionScopeHandler transactionScopeHandler,
     IWalletOwnersRepository walletOwnersRepository,
     IQuorumTransactionSignerClient quorumTransactionSignerClient,
     IOperationRequestsProducer operationRequestsProducer)
 {
     _transactionScopeHandler       = transactionScopeHandler;
     _walletOwnersRepository        = walletOwnersRepository;
     _quorumTransactionSignerClient = quorumTransactionSignerClient;
     _operationRequestsProducer     = operationRequestsProducer;
     _log = logFactory.CreateLog(this);
 }
 public OperationsService(
     IEthApiTransactionsService ethereumApi,
     IQuorumTransactionSignerClient transactionSigner,
     IOperationsRepository operationsRepository,
     INoncesRepository noncesRepository,
     ITransactionRunner transactionRunner,
     long gasLimit,
     long gasPrice,
     ILogFactory logFactory)
 {
     _ethereumApi          = ethereumApi;
     _transactionSigner    = transactionSigner;
     _operationsRepository = operationsRepository;
     _noncesRepository     = noncesRepository;
     _transactionRunner    = transactionRunner;
     _gasLimit             = gasLimit;
     _gasPrice             = gasPrice;
     _log = logFactory.CreateLog(this);
 }
Exemple #6
0
        /// <summary>Sign raw transaction hash by a specified wallet.</summary>
        /// <param name="client"><see cref="IQuorumTransactionSignerClient"/> instance.</param>
        /// <param name="address">Wallet address (20 bytes) in a hex format (40 hexadecimal symbols) prefixed with 0x.</param>
        /// <param name="rawTxHash">Raw transaction hash in the base64 encoding.</param>
        /// <returns>V, R and S parameters of the transaction signature.</returns>
        /// <exception cref="WalletNotFoundException">Throw, if a wallet for the specified address has not been found.</exception>
        public static async Task <(byte[] V, byte[] R, byte[] S)> SignTransactionAsync(
            [NotNull] this IQuorumTransactionSignerClient client,
            [NotNull] string address,
            [NotNull] byte[] rawTxHash)
        {
            var request = new SignTransactionRequest {
                RawTxHash = Convert.ToBase64String(rawTxHash)
            };
            var response = await client.WalletsApi.SignTransactionAsync(address, request);

            if (response.Error != SignTransactionError.None)
            {
                throw new WalletNotFoundException(address);
            }

            var r = Convert.FromBase64String(response.R);
            var s = Convert.FromBase64String(response.S);
            var v = Convert.FromBase64String(response.V);

            return(v, r, s);
        }
Exemple #7
0
 public WalletsApiTests(
     ClientFixture fixture)
 {
     _client = fixture.Client;
 }