How to get the last executed transaction?

0

I work with a Wallet app and using the BitcoinJ for programming. I need to find the last executed transaction from the wallet. In the org.bitcoinj.core.Wallet class, I see there is a method getTransactionsByTime() that returns list of all non-dead, active transactions ordered by recency as List<Transaction>.

Will I access the most recent transaction with index 0 or the last index? I have made some experiments and I likely think that would be with index of 0. Because, it returns the sending info and I have done some recently, but, still weird as the amount doesn't match with performed.

While I have tried with the last index, I think that's obviously not the case as that's returns the info of the incoming transactions.

The way I find the most recent transaction,

    transactions.addAll(wallet.getTransactionsByTime());    
    Transaction ts = size > 0 ? getTransactions().get(0) : null;
    this.transaction = addTransactionHistory(ts);

I print the transaction as the most recent one in console.

Arefe

Posted 2017-06-15T05:37:19.057

Reputation: 203

Answers

1

The first transaction in the list should be the newest one.

The best way to answer such questions is always to read the source code. getTransactionsByTime calls getRecentTransactions, and there is a comment:

Returns an list of N transactions, ordered by increasing age.

You can trace down to find the critical minus sign that ensures this.

You can also find a test that explicitly verifies it works as documented.

Nate Eldredge

Posted 2017-06-15T05:37:19.057

Reputation: 21 420

Thanks a lot for this answer. I'm new to cryptocurrency and developing a customized wallet.Arefe 2017-06-16T08:54:05.817