I am new to bitcoinj. I want to print out the list of transactions like as follow for a wallet:
1- Sent 1 BTC to Adress1 on 'A' Time
2- Received 5 BTC from Adress2 on 'B' time
3- Sent 2 BTC to Address 3 on 'C' time
How can I do this?
I am new to bitcoinj. I want to print out the list of transactions like as follow for a wallet:
1- Sent 1 BTC to Adress1 on 'A' Time
2- Received 5 BTC from Adress2 on 'B' time
3- Sent 2 BTC to Address 3 on 'C' time
How can I do this?
Create an object of wallet app kit like:
WalletAppKit kit = new WalletAppKit(params, new File("."), "filename");
kit.startAsync();
kit.awaitRunning();
Iterable<WalletTransaction> walletTransactions = kit.wallet().getWalletTransactions();
this walletTransactions will give you all transactions related to the wallet.
You can get transaction history of any transaction like this
private void txHistory()
{
Set<Transaction> txx = kit.wallet().getTransactions(true);
if (!txx.isEmpty())
{
int i = 1;
for (Transaction tx : txx)
{
System.out.println(i + " ________________________");
System.out.println("Date and Time: " + tx.getUpdateTime().toString());
System.out.println("From Address: " + tx.getOutput(0).getAddressFromP2PKHScript(params));
System.out.println("To Address: " + tx.getOutput(0).getAddressFromP2PKHScript(params));
System.out.println("Amount Sent to me: " + tx.getValueSentToMe(kit.wallet()).toFriendlyString());
System.out.println("Amount Sent from me: " + tx.getValueSentFromMe(kit.wallet()).toFriendlyString());
long fee = (tx.getInputSum().getValue() > 0 ? tx.getInputSum().getValue() - tx.getOutputSum().getValue() : 0);
System.out.println("Fee: " + Coin.valueOf(fee).toFriendlyString());
System.out.println("Transaction Depth: " + tx.getConfidence().getDepthInBlocks());
System.out.println("Transaction Blocks: " + tx.getConfidence().toString());
System.out.println("Tx Hex: " + tx.getHashAsString());
System.out.println("Tx: " + tx.toString());
i++;
}
}
else
{
System.err.println("No Transaction Found");
}
}