Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Herbert on December 07, 2011, 11:55:21 AM



Title: gettransaction for non-wallet transactions?
Post by: Herbert on December 07, 2011, 11:55:21 AM
Hi,

I understand that the gettransactions command only will return transactions concerning the users wallet. Is there a way to query bitcoind for any transaction, independent of the users wallet?

Thanks!


Title: Re: gettransaction for non-wallet transactions?
Post by: etotheipi on December 07, 2011, 01:26:16 PM
Your bitcoind would have to do a full rescan of the blockchain, which it is probably prohibitively slow in the Satoshi client.  I'm sure the client could be hacked to do this, though.


Title: Re: gettransaction for non-wallet transactions?
Post by: dogisland on December 07, 2011, 01:52:54 PM
There's an import/export private key patch.

https://bitcointalk.org/index.php?topic=8091.0

I believe this does a rescan on each import.


Title: Re: gettransaction for non-wallet transactions?
Post by: Pieter Wuille on December 07, 2011, 03:31:41 PM
Not true, you don't need a rescan to find an arbitrary transaction, if you have the block chain database. It's just not implemented.


Title: Re: gettransaction for non-wallet transactions?
Post by: etotheipi on December 07, 2011, 07:18:57 PM
Not true, you don't need a rescan to find an arbitrary transaction, if you have the block chain database. It's just not implemented.


My bad.  I thought you asked about looking up transactions for a given address.  It sounds like you have a tx hash and you want to retrieve the tx.  Yes, that should be an easy modification to bitcoind.


Title: Re: gettransaction for non-wallet transactions?
Post by: Herbert on December 08, 2011, 04:13:53 PM
It sounds like you have a tx hash and you want to retrieve the tx.  Yes, that should be an easy modification to bitcoind.

Yes, that's what i want to do.

Glancing at the code the current implementation is completely wallet-centric. GetTransaction() from main.cpp walks through all wallets and calls wallet->getTransaction(), and also returns wallet-specific CWalletTx object. So it does not really look like a trivial patch :-/

Is there already a patch existing somewhere providing this feature? Alternatively any hints where i should start doing my own patch are welcome ;-)


Title: Re: gettransaction for non-wallet transactions?
Post by: blueadept on December 08, 2011, 04:39:13 PM
It sounds like you have a tx hash and you want to retrieve the tx.  Yes, that should be an easy modification to bitcoind.

Yes, that's what i want to do.

Glancing at the code the current implementation is completely wallet-centric. GetTransaction() from main.cpp walks through all wallets and calls wallet->getTransaction(), and also returns wallet-specific CWalletTx object. So it does not really look like a trivial patch :-/

Is there already a patch existing somewhere providing this feature? Alternatively any hints where i should start doing my own patch are welcome ;-)

I'm not super familiar with the code, but non-wallet transactions HAVE TO BE indexed for validation of incoming transactions/blocks.  Each new transaction contains inputs which are outputs of previous transactions, referenced by the hash of the previous transaction and the index of the output used as the input so fast lookup is essential for validating new transactions/blocks.  You're more likely to find what you want in db.h and db.cpp (look for CTxDB::ReadDiskTx(...) methods).


Title: Re: gettransaction for non-wallet transactions?
Post by: Herbert on December 08, 2011, 09:44:31 PM
Cool, got it working :-)

CMerkleTx is the class to use:
Code:
// construct COutPoint to satisfy ReadFromDisk method
COutPoint dummyOutp(hash, 0);
CMerkleTx mtx;
mtx.ReadFromDisk(dummyOutp);
mtx.SetMerkleBranch(NULL);
Passing NULL into SetMerkleBranch actually triggers reading/loading it from the transactionDB. Spent some time thinking how to obtain a CBlock* untill i realized that  ::)

Wrapped this up in some rpc glue code and got my shiny new "getanytransaction" rpc command running  ;D

Thanks for your help!

Edit:
In case someone finds this usefull - the code is on github: https://github.com/TripleSpeeder/bitcoin