I'm trying to come up with this function: CTransaction getTxFromPrevout(COutPoint prevo);
The idea being... when a new transaction is about to be validated, it will go through all of it's tx.vin[i].prevout
and check for them funds (utxo
).
So I want to find and identify the CTransaction tx
such that tx.vout
(of type vector<CTxOut>
) has any i
element such that it's CScript
is a normal payment (tx.vout[i].scriptPubKey.IsNormalPayment() == true
) and the tx.vout[i].scriptPubKey
has within it a match for the prevo
If I use a web based explorer I can take the prevo
and extract the hash from it, then search the web for the tx
... but that doesn't help me, since I want to be able to use this within the code itself, adding this new function. I tried following the code on an explorer and it uses the rpc api, and it was not easy to follow.
What I'm thinking is that there should be a utxo
database structure or class that will make this easier to crawl through. If I suppose there is such a class named UTxODatabase
- that I know there isn't, but just imagine there is - then the function I need to code would look like this:
CTransaction UTxODatabase::getTxFromPrevout(COutPoint prevo);
/*************************************************/
EDIT 1:
I put this at the very end of the CheckTransaction() function, in main.cpp
BOOST_FOREACH (const CTxIn& txin, tx.vin){
std::cout << "txin.prevPubKey.ToString(): " << txin.prevPubKey.ToString() << std::endl;
Then I've ran the wallet and the output shown for each txin was just: txin.prevPubKey.ToString:
, without any prevPubKey
data.
I am really confused about this.
My thinking was that if I'm able to get those prevPubKey
s from the CTxIn
, then I'll be able to track the utxo
. But why would there be no information on that member of the txin
at that stage?
CCoinsView
class incoins.h
, the functionvirtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const;
(or one of its overloads) might do what you need.virtual
qualifier... the main function you referenced me to was:bool CCoinsView::GetCoins(const uint256& txid, CCoins& coins) const { return false; }
... it just returns false. This seems to be on the right track, tho... and probably one of the other implementations should work... like this one:bool CCoinsViewBacked::GetCoins(const uint256& txid, CCoins& coins) const { return base->GetCoins(txid, coins); }
But the truth is I'm not sure on how to use it Could be something like this?CTransaction CCoinsViewBacked::getTxFromPrevout(COutPoint prevo);