【比特币】序列化


block的序列化,


tx的序列化

13:39:38

getrawtransaction 29b4ff508409c050cec2f7a6ebbb362e5b667ad3377eeede472a4d1815361254


13:39:57

01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0a530101062f503253482fffffffff0100e40b54020000002321037a059b62ec150ae13a61ba3fc4797f4223bfe18d2f1f60a928fc470134aa4298ac00000000


13:40:13

decoderawtransaction 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0a530101062f503253482fffffffff0100e40b54020000002321037a059b62ec150ae13a61ba3fc4797f4223bfe18d2f1f60a928fc470134aa4298ac00000000


01000000 // Transaction's Version, little endian
01 // vecInput's size is 1, compact storage
0000000000000000000000000000000000000000000000000000000000000000 // prevout hash
ffffffff // prevout index
0a // script length
530101062f503253482f // Signature Script, here is coinbase for generation tx.
ffffffff // sequence
01 // vecOutput's size is 1, compact stroage
00e40b5402000000 // 100*100000000 coin, 64bit
23 // pubkey script length
21 // pubkey length
037a059b62ec150ae13a61ba3fc4797f4223bfe18d2f1f60a928fc470134aa4298 // pubkey, der encoded
ac //OP_CHECKSIG
00000000 // locktime

SHA256SUM(01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0a530101062f503253482fffffffff0100e40b54020000002321037a059b62ec150ae13a61ba3fc4797f4223bfe18d2f1f60a928fc470134aa4298ac00000000)
=>SHA256SUM(58761537812989b9774f9b8ea8cbbaf1963dd78661e3f6d4f7d36f93a6fd328a)
=>29b4ff508409c050cec2f7a6ebbb362e5b667ad3377eeede472a4d1815361254

13:40:13

{
"txid" : "29b4ff508409c050cec2f7a6ebbb362e5b667ad3377eeede472a4d1815361254",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"coinbase" : "530101062f503253482f",
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 100.00000000,
"n" : 0,
"scriptPubKey" : {
"asm" : "037a059b62ec150ae13a61ba3fc4797f4223bfe18d2f1f60a928fc470134aa4298 OP_CHECKSIG",
"hex" : "21037a059b62ec150ae13a61ba3fc4797f4223bfe18d2f1f60a928fc470134aa4298ac",
"reqSigs" : 1,
"type" : "pubkey",
"addresses" : [
"FRyTj4Pb8NydW2X2B8nrXwf5sVz7d3x7wB"
]
}
}
]
}

template <unsigned int BITS>
std::string base_uint<BITS>::GetHex() const
{
    char psz[sizeof(pn) * 2 + 1];
    for (unsigned int i = 0; i < sizeof(pn); i++)
        sprintf(psz + i * 2, "%02x", ((unsigned char*)pn)[sizeof(pn) - i - 1]);
    return std::string(psz, psz + sizeof(pn) * 2);
}

base_uint& operator++()
{
	// prefix operator
	int i = 0;
	while (++pn[i] == 0 && i < WIDTH-1)
		i++;
	return *this;
}


coin的序列化


你可能感兴趣的:(serialization,double,hash,transaction,bitcoin)