Skip to content

Commit 1a6accb

Browse files
committed
Add function to get address utxos
1 parent 3821d30 commit 1a6accb

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/main/java/com/danubetech/btc/connection/BitcoinConnection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.danubetech.btc.connection.records.Block;
44
import com.danubetech.btc.connection.records.Tx;
5+
import com.danubetech.btc.connection.records.TxOut;
56

67
import java.util.List;
78
import java.util.Map;
@@ -16,6 +17,7 @@ public interface BitcoinConnection {
1617
Block getBlockByTargetTime(Long targetTime);
1718
Block getBlockByMinConfirmations(Integer confirmations);
1819
List<Tx> getAddressTransactions(String address);
20+
List<TxOut> getAddressUtxos(String address);
1921
Block getBlockByTransaction(Tx tx);
2022
void broadcastRawTransaction(byte[] rawTransaction);
2123
}

src/main/java/com/danubetech/btc/connection/impl/AbstractBitcoinConnection.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.danubetech.btc.connection.Network;
55
import com.danubetech.btc.connection.records.Block;
66
import com.danubetech.btc.connection.records.Tx;
7+
import com.danubetech.btc.connection.records.TxOut;
78

89
import java.util.Collections;
910
import java.util.List;
@@ -52,6 +53,11 @@ public List<Tx> getAddressTransactions(String address) {
5253
throw new RuntimeException("Not implemented");
5354
}
5455

56+
@Override
57+
public List<TxOut> getAddressUtxos(String address) {
58+
throw new RuntimeException("Not implemented");
59+
}
60+
5561
@Override
5662
public Block getBlockByTransaction(Tx tx) {
5763
throw new RuntimeException("Not implemented");

src/main/java/com/danubetech/btc/connection/impl/EsploraElectrsRESTBitcoinConnection.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ public List<Tx> getAddressTransactions(String address) {
6969
return txs;
7070
}
7171

72+
@Override
73+
public List<TxOut> getAddressUtxos(String address) {
74+
URI apiEndpoint = URI.create(this.apiEndpointBase + "address/" + address + "/utxo");
75+
List<Object> response = readArray(apiEndpoint);
76+
List<TxOut> txOuts = response.stream().map(Map.class::cast).map(EsploraElectrsRESTBitcoinConnection::txOutFromMap).toList();
77+
if (log.isDebugEnabled()) log.debug("getAddressUtxos for {}: {}", address, txOuts);
78+
return txOuts;
79+
}
80+
7281
@Override
7382
public Block getBlockByTransaction(Tx tx) {
7483
URI apiEndpoint = URI.create(this.apiEndpointBase + "tx/" + tx.txId());

0 commit comments

Comments
 (0)