I'm trying to figure out the relationship between the base 58 address, the public key hash, and the scriptPubKey on a standard transaction output.
I know the base 58 address is basically a 25-byte wrapper for the 20-byte double hash of the public key (with version prefix and check sum suffix), encoded to a 17-byte address. I know the public key hash is also part of the scriptPubKey, but that's where my questions arise.
As an example, on testnet (block 487805), I had bitcoins sent to base 58 address mjj4MR1aeTjWSRqHuixfoCGRDRwabbK3zv
The raw transaction is
010000000105287a343ffb315b10c03574975535badbe801cf6ffdf73c79ac22da215d095b01000 0006a4730440220670ef406032cc1c20c284da8ccc2a40d5b135776dac672ce04e8cbb9036fec15 022011e6f589e5ca946f974b3ff69523497d06262a7e75be38ae99a85e493940ea8401210278072 1cc016aaf0434878f95bce130147ccdc4bd88478222bcba2018294e99d4ffffffff02c09e0a0000 0000001976a9142e2a8d353ea825de6bc2b081324f412764e53e5788ac85351931100000001976a914c73c92961d27fb399e1d408c94f1dade2860394588ac00000000
If the bold font comes through, you can see these bytes, which I believe are the scriptPubKey:
76a9142e2a8d353ea825de6bc2b081324f412764e53e5788ac
When I decode the transaction I see this output:
{ "value" : 0.00696000, "n" : 0, "scriptPubKey" : { "asm" : "OP_DUP OP_HASH160 2e2a8d353ea825de6bc2b081324f412764e53e57 OP_EQUALVERIFY OP_CHECKSIG", "hex" : "76a9142e2a8d353ea825de6bc2b081324f412764e53e5788ac", "reqSigs" : 1, "type" : "pubkeyhash", "addresses" : [ "mjj4MR1aeTjWSRqHuixfoCGRDRwabbK3zv" ] } },
There's the base 58 address again, along with the script in hex. Since the base 58 address isn't part of the raw transaction, and since the hex script is 25 bytes, I assumed that if I encoded the script, I'd get the base 58 address, and if I decoded the base 58 address, I'd get the script. But that doesn't work (at least using the Base58 class from bitcoinj).
So what is the relationship between the script and the base 58 address? How does the network even know about the base 58 address, when it's not part of the raw transaction? And what is the asm value, which looks like an actual script but with yet another set of bytes?
|