コード例 #1
0
        public async Task <Transaction> GetAsync(uint256 txId)
        {
            while (true)
            {
                using (HttpClient client = new HttpClient())
                {
                    var response = await client.GetAsync(BlockrAddress + "tx/raw/" + txId).ConfigureAwait(false);

                    if (response.StatusCode == HttpStatusCode.NotFound)
                    {
                        return(null);
                    }
                    var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    var json   = JObject.Parse(result);
                    var status = json["status"];
                    var code   = json["code"];
                    if (status != null && status.ToString() == "error")
                    {
                        throw new BlockrException(json);
                    }
                    var tx = Transaction.Parse(json["data"]["tx"]["hex"].ToString());
                    return(tx);
                }
            }
        }
コード例 #2
0
        public async Task <IBlockchainTransaction> GetTransactionAsync(
            string txId,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Info.Blockchain.API.Models.Transaction tx;

            try
            {
                tx = await _explorer
                     .GetTransactionByHashAsync(txId)
                     .ConfigureAwait(false);
            }
            catch (ServerApiException e)
            {
                Log.Warning("Server api exception while get transaction by id {@txId}: {@message}",
                            txId,
                            ResolveExceptionMessage(e));

                return(null);
            }

            return(new BitcoinBasedTransaction(
                       currency: _currency,
                       tx: Transaction.Parse(await GetTxHexAsync(txId).ConfigureAwait(false), _currency.Network),
                       blockInfo: new BlockInfo
            {
                Fees = await GetTxFeeAsync(txId).ConfigureAwait(false),
                Confirmations = (int)(await GetBlockCountAsync().ConfigureAwait(false) - tx.BlockHeight + 1),
                BlockHeight = tx.BlockHeight,
                FirstSeen = tx.Time,
                BlockTime = tx.Time
            }));
        }
コード例 #3
0
        /// <inheritdoc />
        public bool SendTransaction(string transactionHex)
        {
            // TODO move this to a behavior on the full node
            // parse transaction
            Transaction transaction = Transaction.Parse(transactionHex);
            TxPayload   payload     = new TxPayload(transaction);

            foreach (var node in this.connectionManager.ConnectedNodes)
            {
                node.SendMessage(payload);
            }

            return(true);
        }
コード例 #4
0
        /// <inheritdoc />
        public bool SendTransaction(string transactionHex)
        {
            Guard.NotEmpty(transactionHex, nameof(transactionHex));

            // TODO move this to a behavior to a dedicated interface
            // parse transaction
            Transaction transaction = Transaction.Parse(transactionHex);

            // replace this we a dedicated WalletBroadcast interface
            // in a fullnode implementation this will validate with the
            // mempool and broadcast, in a lightnode this will push to
            // the wallet and then broadcast (we might add some basic validation
            if (this.mempoolValidator == null)
            {
                this.ProcessTransaction(transaction);
            }
            else
            {
                var state = new MempoolValidationState(false);
                if (!this.mempoolValidator.AcceptToMemoryPool(state, transaction).GetAwaiter().GetResult())
                {
                    return(false);
                }
                this.ProcessTransaction(transaction);
            }

            // broadcast to peers
            TxPayload payload = new TxPayload(transaction);

            foreach (var node in this.connectionManager.ConnectedNodes)
            {
                node.SendMessage(payload);
            }

            // we might want to create a behaviour that tracks how many times
            // the broadcast trasnactions was sent back to us by other peers
            return(true);
        }