Bitcoin Forum
April 19, 2019, 01:32:20 AM *
News: Latest Bitcoin Core release: 0.17.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: listtransactions in stable order?  (Read 1140 times)
notme
Legendary
*
Offline Offline

Activity: 1904
Merit: 1001


View Profile
October 01, 2014, 06:46:38 PM
 #1

The listtransactions API call allows you to specify an offset of how many transactions are skipped.  My question is this: is the ordering of this list stable such that you can simply track how many transactions you've already recorded and rely on a new call to give you any new information.  Specifically, if I import a private key that has a transaction that happened well in the past, will that transaction show up on my next listtransactions call, or will it be buried underneath causing my call to return a transaction I've already seen previously?

https://www.bitcoin.org/bitcoin.pdf
While no idea is perfect, some ideas are useful.
12jh3odyAAaR2XedPKZNCR4X4sebuotQzN
1555637540
Hero Member
*
Offline Offline

Posts: 1555637540

View Profile Personal Message (Offline)

Ignore
1555637540
Reply with quote  #2

1555637540
Report to moderator
1555637540
Hero Member
*
Offline Offline

Posts: 1555637540

View Profile Personal Message (Offline)

Ignore
1555637540
Reply with quote  #2

1555637540
Report to moderator
1555637540
Hero Member
*
Offline Offline

Posts: 1555637540

View Profile Personal Message (Offline)

Ignore
1555637540
Reply with quote  #2

1555637540
Report to moderator
Is your Paper Seed Safe
from FIRE and FLOOD ?
Stainless Steel Metal Wallet
Nickel Bolts, Metal Box + FREE Passphrase Hex Backup
Free EU shipping!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1000



View Profile WWW
October 02, 2014, 01:02:59 PM
 #2

Quote from: bitcoind help listtransactions
listtransactions ( "account" count from )

Returns up to 'count' most recent transactions skipping the first 'from' transactions for account 'account'.

Arguments:
1. "account"    (string, optional) The account name. If not included, it will list all transactions for all accounts.
                                     If "" is set, it will list transactions for the default account.
2. count          (numeric, optional, default=10) The number of transactions to return
3. from           (numeric, optional, default=0) The number of transactions to skip

Result:
[
  {
    "account":"accountname",       (string) The account name associated with the transaction.
                                                It will be "" for the default account.
    "address":"bitcoinaddress",    (string) The bitcoin address of the transaction. Not present for
                                                move transactions (category = move).
    "category":"send|receive|move", (string) The transaction category. 'move' is a local (off blockchain)
                                                transaction between accounts, and not associated with an address,
                                                transaction id or block. 'send' and 'receive' transactions are
                                                associated with an address, transaction id and block details
    "amount": x.xxx,          (numeric) The amount in btc. This is negative for the 'send' category, and for the
                                         'move' category for moves outbound. It is positive for the 'receive' category,
                                         and for the 'move' category for inbound funds.
    "fee": x.xxx,             (numeric) The amount of the fee in btc. This is negative and only available for the
                                         'send' category of transactions.
    "confirmations": n,       (numeric) The number of confirmations for the transaction. Available for 'send' and
                                         'receive' category of transactions.
    "blockhash": "hashvalue", (string) The block hash containing the transaction. Available for 'send' and 'receive'
                                          category of transactions.
    "blockindex": n,          (numeric) The block index containing the transaction. Available for 'send' and 'receive'
                                          category of transactions.
    "txid": "transactionid", (string) The transaction id. Available for 'send' and 'receive' category of transactions.
    "time": xxx,              (numeric) The transaction time in seconds since epoch (midnight Jan 1 1970 GMT).
    "timereceived": xxx,      (numeric) The time received in seconds since epoch (midnight Jan 1 1970 GMT). Available
                                          for 'send' and 'receive' category of transactions.
    "comment": "...",       (string) If a comment is associated with the transaction.
    "otheraccount": "accountname",  (string) For the 'move' category of transactions, the account the funds came
                                          from (for receiving funds, positive amounts), or went to (for sending funds,
                                          negative amounts).
  }
]

Examples:

List the most recent 10 transactions in the systems
> bitcoin-cli listtransactions

List the most recent 10 transactions for the tabby account
> bitcoin-cli listtransactions "tabby"

List transactions 100 to 120 from the tabby account
> bitcoin-cli listtransactions "tabby" 20 100

As a json rpc call
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listtransactions", "params": ["tabby", 20, 100] }' -H 'content-type: text
/plain;' http://127.0.0.1:8332/

The transaction list comes out of the wallet. It is your own record of the order transactions happened and is the order that transactions were added to the wallet database. It follows that it would return data in the order it appears or was added to the wallet.

BTW, notable in use of the command is that specifying no parameters will show the most recent 10 transactions for all accounts. Undocumented is that if you want to count and skip parameter, you cannot omit the (account) parameter - to show all accounts you use "*" (asterisk) as the indicator for "all accounts".

This could be tested. In a blank wallet, import a privkey that has recent payments and let it reindex. Then import a privkey that received payments in earlier blocks and reindex. I would expect the result of the RPC command to not be in chronological order after importing keys with prior payments.

Reviewing the code, there is no sorting or post-processing in the listtransactions function (rpcwallet.cpp ~line 1200). If  correct chronological order is mandatory, I would recommend getting all transactions and sorting yourself based on time value (or blocktime or timereceived specifically for generates or incoming transactions). This still may have issues as block timestamps could be out-of-order.
notme
Legendary
*
Offline Offline

Activity: 1904
Merit: 1001


View Profile
October 02, 2014, 08:23:42 PM
 #3

Thanks, that was helpful.  I had one thing a little backwards.  The offset is how far away from current you are looking rather than how far from the first transaction.  So I believe I just need to walk from 0 forward until I see a transaction I already know.

https://www.bitcoin.org/bitcoin.pdf
While no idea is perfect, some ideas are useful.
12jh3odyAAaR2XedPKZNCR4X4sebuotQzN
theymos
Administrator
Legendary
*
Offline Offline

Activity: 3360
Merit: 5237


View Profile
October 03, 2014, 04:11:08 AM
Last edit: October 03, 2014, 04:27:55 AM by theymos
 #4

I believe listtransactions is always stable unless you manually mess with your wallet.dat or use -zapwallettxes.

Reviewing the code, there is no sorting or post-processing in the listtransactions function (rpcwallet.cpp ~line 1200).

No, it is ordered. The listtransactions function gets transactions like this:
Code:
CWallet::TxItems txOrdered = pwalletMain->OrderedTxItems(acentries, strAccount);

OrderedTxItems returns a list of all wallet transactions for account strAccount ordered by the transaction's nOrderPos. nOrderPos is set in a way that ensures that all newly-seen transactions are listed later than ones seen earlier, even if the transaction seen later probably came earlier chronologically. I'm not 100% sure that this rule is followed when rescanning, but I think so.

Note that listtransactions internally loops through every wallet transaction each time you call it to ensure the correct ordering, even if you use an offset. This might make it slow for large wallets.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!