Skip to content

Commit

Permalink
Fetch all transactions for given address
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrasulov committed Mar 31, 2023
1 parent aa88f67 commit bd4633b
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions ecashkit/src/main/kotlin/io/horizontalsystems/ecash/ChronikApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,35 @@ class ChronikApi : IInitialSyncApi {

for (address in addresses) {
try {
val get = apiManager.get("script/p2pkh/$address/history")
val txHistoryPage = Chronik.TxHistoryPage.parseFrom(get)
transactionItems.addAll(
txHistoryPage.txsList.map {
TransactionItem(
blockHash = it.block.hash.toByteArray().toReversedHex(),
blockHeight = it.block.height,
txOutputs = it.outputsList.map { txOutput ->
TransactionOutputItem(
script = txOutput.outputScript.toByteArray().toReversedHex(),
address = ""
)
}
)
}
)
var page = 0

while (true) {
Thread.sleep(10)
val get = apiManager.get("script/p2pkh/$address/history?page=$page")
val txHistoryPage = Chronik.TxHistoryPage.parseFrom(get)
transactionItems.addAll(
txHistoryPage.txsList.map {
TransactionItem(
blockHash = it.block.hash.toByteArray().toReversedHex(),
blockHeight = it.block.height,
txOutputs = it.outputsList.map { txOutput ->
TransactionOutputItem(
script = txOutput.outputScript.toByteArray().toReversedHex(),
address = ""
)
}
)
}
)

page++

if (txHistoryPage.numPages < page + 1)
break
}
} catch (e: Throwable) {
continue
}
Thread.sleep(10)
}

return transactionItems
Expand Down

0 comments on commit bd4633b

Please # to comment.