public IRpcMethodResult GetTxOut(string txid, int vount, bool unconfirmed = false) { try { GetTxOutOM result = null; var txComponent = new TransactionComponent(); var blockComponent = new BlockComponent(); string blockHash = null; TransactionMsg tx = txComponent.GetTransactionMsgFromDB(txid, out blockHash); if (tx == null && unconfirmed) { tx = txComponent.GetTransactionMsgFromPool(txid); } if (tx != null && tx.OutputCount > vount) { var output = tx.Outputs[vount]; long confirmations = 0; if (!string.IsNullOrWhiteSpace(blockHash)) { var block = blockComponent.GetBlockMsgByHash(blockHash); if (block != null) { var latestHeight = blockComponent.GetLatestHeight(); if (latestHeight > block.Header.Height) { confirmations = latestHeight - block.Header.Height; } } } result = new GetTxOutOM(); result.bestblock = blockHash; result.confirmations = confirmations; result.value = output.Amount; result.scriptPubKey = output.LockScript; result.version = tx.Version; result.coinbase = (tx.InputCount == 0 && tx.Inputs[0].OutputTransactionHash == Base16.Encode(HashHelper.EmptyHash())); } return(Ok(result)); } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
public GetTxOutOM GetTxOut(string txid, int vount, bool unconfirmed = false) { GetTxOutOM result = null; TransactionMsg tx = null; tx = TransactionDac.Default.GetTransaction(txid); if (tx == null && unconfirmed) { tx = TransactionPoolDac.Default.Get(txid); } if (tx == null) { return(result); } if (!unconfirmed) { var utxo = UtxoSetDac.Default.Get(txid, vount); if (utxo == null) { return(result); } result = new GetTxOutOM(); result.bestblock = utxo.BlockHash; result.coinbase = utxo.IsCoinbase; result.confirmations = GlobalParameters.LocalHeight - utxo.BlockHeight; result.scriptPubKey = utxo.LockScript; result.value = utxo.Amount; } else { var output = tx.Outputs[vount]; result.bestblock = null; result.coinbase = false; result.confirmations = 0; result.scriptPubKey = output.LockScript; result.value = output.Amount; } result.version = Versions.EngineVersion; return(result); }