11package com .danubetech .btc .connection .impl ;
22
3- import com .danubetech .btc .connection .*;
3+ import com .danubetech .btc .connection .BitcoinConnection ;
4+ import com .danubetech .btc .connection .Network ;
45import com .danubetech .btc .connection .records .Block ;
56import com .danubetech .btc .connection .records .Tx ;
67import com .danubetech .btc .connection .records .TxIn ;
@@ -40,16 +41,16 @@ public Map<String, Object> getMetadata() {
4041 public Block getBlockByBlockHeight (Integer blockHeight ) {
4142 BitcoinJSONRPCClient bitcoinJSONRPCClient = this .getBitcoinJsonRpcClient ();
4243 wf .bitcoin .javabitcoindrpcclient .BitcoindRpcClient .Block bitcoinjBlock = bitcoinJSONRPCClient .getBlock (blockHeight );
43- List <Tx > txs = bitcoinjBlock .tx ().stream ().map (tx -> txFromBitcoinjRawTransaction (bitcoinJSONRPCClient , tx )).toList ();
44- Block block = blockFromBitcoinjBlock (bitcoinjBlock );
44+ List <Tx > txs = bitcoinjBlock .tx ().stream ().map (tx -> txFromBitcoinRawTransaction (bitcoinJSONRPCClient , tx )).toList ();
45+ Block block = blockFromBitcoinBlock (bitcoinjBlock );
4546 if (log .isDebugEnabled ()) log .debug ("getBlockByBlockHeight for {}: {}" , blockHeight , block );
4647 return block ;
4748 }
4849
4950 @ Override
5051 public Tx getTransactionById (String txId ) {
5152 BitcoinJSONRPCClient bitcoinJSONRPCClient = this .getBitcoinJsonRpcClient ();
52- Tx tx = txFromBitcoinjRawTransaction (bitcoinJSONRPCClient , txId );
53+ Tx tx = txFromBitcoinRawTransaction (bitcoinJSONRPCClient , txId );
5354 if (log .isDebugEnabled ()) log .debug ("getTransactionById for {}: {}" , txId , tx );
5455 return tx ;
5556 }
@@ -62,7 +63,7 @@ public Block getBlockByTargetTime(Long targetTime) {
6263 for (int blockHeight =blocks -1 ; blockHeight >=0 ; blockHeight --) {
6364 wf .bitcoin .javabitcoindrpcclient .BitcoindRpcClient .Block bitcoinjBlock = bitcoinJSONRPCClient .getBlock (blockHeight );
6465 if (bitcoinjBlock .time ().getTime () < targetTime ) {
65- block = blockFromBitcoinjBlock (bitcoinjBlock );
66+ block = blockFromBitcoinBlock (bitcoinjBlock );
6667 break ;
6768 }
6869 }
@@ -78,7 +79,7 @@ public Block getBlockByMinConfirmations(Integer minConfirmations) {
7879 for (int blockHeight =blocks -1 ; blockHeight >=0 ; blockHeight --) {
7980 wf .bitcoin .javabitcoindrpcclient .BitcoindRpcClient .Block bitcoinjBlock = bitcoinJSONRPCClient .getBlock (blockHeight );
8081 if (bitcoinjBlock .confirmations () >= minConfirmations ) {
81- block = blockFromBitcoinjBlock (bitcoinjBlock );
82+ block = blockFromBitcoinBlock (bitcoinjBlock );
8283 break ;
8384 }
8485 }
@@ -90,31 +91,33 @@ public Block getBlockByMinConfirmations(Integer minConfirmations) {
9091 * Helper methods
9192 */
9293
93- private static Block blockFromBitcoinjBlock (wf .bitcoin .javabitcoindrpcclient .BitcoindRpcClient .Block bitcoinjBlock ) {
94+ private static Block blockFromBitcoinBlock (wf .bitcoin .javabitcoindrpcclient .BitcoindRpcClient .Block bitcoinjBlock ) {
9495 return new Block (bitcoinjBlock .height (), bitcoinjBlock .hash (), bitcoinjBlock .time ().getTime (), bitcoinjBlock .confirmations ());
9596 }
9697
97- private static Tx txFromBitcoinjRawTransaction (BitcoinJSONRPCClient bitcoinJSONRPCClient , String txId ) {
98+ private static Tx txFromBitcoinRawTransaction (BitcoinJSONRPCClient bitcoinJSONRPCClient , String txId ) {
9899 if (Tx .COINBASE_TX_IDENTIFIER .equals (txId ) || Tx .GENESIS_TX_IDENTIFIER .equals (txId )) {
99100 return new Tx (txId , null , null );
100101 }
101- wf .bitcoin .javabitcoindrpcclient .BitcoindRpcClient .RawTransaction bitcoinjRawTransaction = bitcoinJSONRPCClient .getRawTransaction (txId );
102- List <TxIn > txIns = bitcoinjRawTransaction .vIn ().stream ().map (BitcoindRPCBitcoinConnection ::txInFromBitcoinjIn ).toList ();
103- List <TxOut > txOuts = bitcoinjRawTransaction .vOut ().stream ().map (BitcoindRPCBitcoinConnection ::txOutFromBitcoinjOut ).toList ();
102+ wf .bitcoin .javabitcoindrpcclient .BitcoindRpcClient .RawTransaction bitcoinRawTransaction = bitcoinJSONRPCClient .getRawTransaction (txId );
103+ List <TxIn > txIns = bitcoinRawTransaction .vIn ().stream ().map (BitcoindRPCBitcoinConnection ::txInFromBitcoinIn ).toList ();
104+ List <TxOut > txOuts = bitcoinRawTransaction .vOut ().stream ().map (BitcoindRPCBitcoinConnection ::txOutFromBitcoinOut ).toList ();
104105 return new Tx (txId , txIns , txOuts );
105106 }
106107
107- private static TxIn txInFromBitcoinjIn (wf .bitcoin .javabitcoindrpcclient .BitcoindRpcClient .RawTransaction .In in ) {
108+ private static TxIn txInFromBitcoinIn (wf .bitcoin .javabitcoindrpcclient .BitcoindRpcClient .RawTransaction .In in ) {
108109 var txId = in .txid ();
109110 Integer vout = txId == null ? null : in .getTransactionOutput ().n ();
110111 return new TxIn (txId , vout );
111112 }
112113
113- private static TxOut txOutFromBitcoinjOut (wf .bitcoin .javabitcoindrpcclient .BitcoindRpcClient .RawTransaction .Out out ) {
114- String txId = out .transaction ().txId ();
114+ private static TxOut txOutFromBitcoinOut (wf .bitcoin .javabitcoindrpcclient .BitcoindRpcClient .RawTransaction .Out out ) {
115+ String scriptPubKey = out .scriptPubKey ().hex ();
116+ String scriptPubKeyAsm = out .scriptPubKey ().asm ();
117+ String scriptPubKeyType = out .scriptPubKey ().type ();
115118 String scriptPubKeyAddress = out .scriptPubKey ().mapStr ("address" );
116- String asm = out .scriptPubKey ().asm ();
117- return new TxOut (txId , scriptPubKeyAddress , asm );
119+ Long value = out .value ().longValue ();
120+ return new TxOut (scriptPubKey , scriptPubKeyAsm , scriptPubKeyType , scriptPubKeyAddress , value );
118121 }
119122
120123 /*
0 commit comments