Hello Dan,

I discussed this a bit on the github issue
https://github.com/btcsuite/btcd/issues/485.

The ExtractPkScriptAddrs can't possibly extract any addresses from a
transaction input (signature script) because transaction inputs do not
have addresses.  As I elaborated on a bit more in the referenced issue,
addresses only exist when a transaction *output* (public key script) is
of a standard form, which it may or may not be.  That is why
ExtractPkScriptAddrs only possibly works with *standard* public key scripts.

In order to figure out what "address" a transaction is spending from, it
is necessary to look up the related *output* that it is consuming since
that is actually what specifies the address (and even then only if it is
one of the standard forms as discussed above).  As you might imagine
however, once an output is spent, it is no longer in the UTXO set which
means the output which contains the information needed is simply no
longer there.

This is the point where the address index comes in.  The address index
essentially keeps track of every transaction which spends to and
consumes from every available address.  Naturally this only works for
standard transactions and has the same caveats discussed above.

So, in order to provide the additional information in the vin list,
you'd have to look it up in the address index and, naturally as a
result, it can only be present when the address index is enabled.

All of that said, the real underlying issue here is that there really is
no notion of a "from" address in Bitcoin. This is a constant source of
confusion for developers and users.  An address is better thought of as
something like the unique ID of a purchase order or receipt.  When
something is sold for an amount of BTC, a unique address should be
generated which uniquely identifies that single transaction (just like a
unique ID on a purchase order or receipt).  The vendor knows a user has
paid once that unique address receives the agreed upon amount of funds
since the address is never again used for anything else.  As you can
see, in this correct usage model, the "from" address is 100% irrelevant
since it's the unique address that identifies the specific order versus
trying to divine who paid by using a realistically non-existent "from"
address to identify the person making the payment.

The address index (and other techniques) are essentially hacks that are
often used to shoehorn this incorrect notion of a "from" address model
into the system.

Regards,

Dave

On 8/15/2015 3:53 PM, Dan Libby wrote:
> Hi.   I recently started using btcd because it seems the best bet for a
> little project I'm working on due to the address index and
> searchrawtransactions API.
> 
> Thanks for creating and maintaining btcd!
> 
> For my project, I am calling searchrawtransactions and I care only about
> inputs and outputs that match the input address.
> 
> For info on my use case, see:
>   https://github.com/dan-da/bitprices
>   https://github.com/btcsuite/btcd/issues/485
> 
> vout provides a list of addresses that my app can easily filter by.
> Unfortunately vin does not.  Only the scriptSig is available.
> 
> I have been hacking on the btcd code attempting to add an address list to
> Vin.  Specifically the function createVinList(), to which I added the arg
> chainParams.
> 
> My first attempt involves calling ExtractPkScriptAddrs() like so:
> 
> scriptClass, addrs, _, err :=
>    txscript.ExtractPkScriptAddrs( v.SignatureScript, chainParams )
> 
> However this does not work.
> 
> scriptClass is always "nonstandard" and err is nil.
> 
> So it seems that parseScript is parsing v.SignatureScript OK but believes
> it is a non-standard transaction.
> 
> I am presently stuck at this point.   Can someone please point me the way?
> 
> 
> ( I know it must be possible because most every block explorer displays
> input addresses, and also various online APIs make them available.)
> 
> 
> thanks.
> 
> Dan
> 

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to