|
|
@ -4,6 +4,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
using namespace Bitcoin; |
|
|
|
using namespace Bitcoin; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// VarInt
|
|
|
|
ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, VarInt& b) |
|
|
|
ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, VarInt& b) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (b.value < 0xfd) { |
|
|
|
if (b.value < 0xfd) { |
|
|
@ -20,7 +21,21 @@ ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, VarInt& b) |
|
|
|
} |
|
|
|
} |
|
|
|
return a; |
|
|
|
return a; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ByteBuffer& Bitcoin::operator>>(ByteBuffer& a, VarInt& b) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
uint8 size = a.Read<uint8>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (size < 0xfd) |
|
|
|
|
|
|
|
b.value = size; |
|
|
|
|
|
|
|
else if (size == 0xfd) |
|
|
|
|
|
|
|
b.value = a.Read<uint16>(); |
|
|
|
|
|
|
|
else if (size == 0xfe) |
|
|
|
|
|
|
|
b.value = a.Read<uint32>(); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
b.value = a.Read<uint64>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Script
|
|
|
|
ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, Script& b) |
|
|
|
ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, Script& b) |
|
|
|
{ |
|
|
|
{ |
|
|
|
VarInt size(b.script.size()); |
|
|
|
VarInt size(b.script.size()); |
|
|
@ -28,14 +43,29 @@ ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, Script& b) |
|
|
|
a << b.script; |
|
|
|
a << b.script; |
|
|
|
return a; |
|
|
|
return a; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ByteBuffer& Bitcoin::operator>>(ByteBuffer& a, Script& b) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
VarInt size; |
|
|
|
|
|
|
|
a >> size; |
|
|
|
|
|
|
|
b.script = a.ReadBytes(size); |
|
|
|
|
|
|
|
return a; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// OutPoint
|
|
|
|
ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, OutPoint& b) |
|
|
|
ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, OutPoint& b) |
|
|
|
{ |
|
|
|
{ |
|
|
|
a << b.hash; |
|
|
|
a << b.hash; |
|
|
|
a << b.n; |
|
|
|
a << b.n; |
|
|
|
return a; |
|
|
|
return a; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ByteBuffer& Bitcoin::operator>>(ByteBuffer& a, OutPoint& b) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
b.hash = a.ReadBytes(32); |
|
|
|
|
|
|
|
b.n = a.Read<uint32>(); |
|
|
|
|
|
|
|
return a; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TxIn
|
|
|
|
ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, TxIn& b) |
|
|
|
ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, TxIn& b) |
|
|
|
{ |
|
|
|
{ |
|
|
|
a << b.prevout; |
|
|
|
a << b.prevout; |
|
|
@ -43,14 +73,29 @@ ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, TxIn& b) |
|
|
|
a << b.n; |
|
|
|
a << b.n; |
|
|
|
return a; |
|
|
|
return a; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ByteBuffer& Bitcoin::operator>>(ByteBuffer& a, TxIn& b) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
a >> b.prevout; |
|
|
|
|
|
|
|
a >> b.script; |
|
|
|
|
|
|
|
b.n = a.Read<uint32>(); |
|
|
|
|
|
|
|
return a; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TxOut
|
|
|
|
ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, TxOut& b) |
|
|
|
ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, TxOut& b) |
|
|
|
{ |
|
|
|
{ |
|
|
|
a << b.value; |
|
|
|
a << b.value; |
|
|
|
a << b.scriptPubKey; |
|
|
|
a << b.scriptPubKey; |
|
|
|
return a; |
|
|
|
return a; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ByteBuffer& Bitcoin::operator>>(ByteBuffer& a, TxOut& b) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
b.value = a.Read<uint64>(); |
|
|
|
|
|
|
|
a >> b.scriptPubKey; |
|
|
|
|
|
|
|
return a; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Transaction
|
|
|
|
ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, Transaction& b) |
|
|
|
ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, Transaction& b) |
|
|
|
{ |
|
|
|
{ |
|
|
|
a << b.version; |
|
|
|
a << b.version; |
|
|
@ -70,3 +115,26 @@ ByteBuffer& Bitcoin::operator<<(ByteBuffer& a, Transaction& b) |
|
|
|
a << b.lockTime; |
|
|
|
a << b.lockTime; |
|
|
|
return a; |
|
|
|
return a; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ByteBuffer& Bitcoin::operator>>(ByteBuffer& a, Transaction& b) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
b.version = a.Read<uint32>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Inputs
|
|
|
|
|
|
|
|
VarInt insize; |
|
|
|
|
|
|
|
a >> insize; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b.in.resize(insize); |
|
|
|
|
|
|
|
for (uint32 i = 0; i < insize; ++i) |
|
|
|
|
|
|
|
a >> b.in[i]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Outputs
|
|
|
|
|
|
|
|
VarInt outsize; |
|
|
|
|
|
|
|
a >> outsize; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b.out.resize(outsize); |
|
|
|
|
|
|
|
for (uint32 i = 0; i < outsize; ++i) |
|
|
|
|
|
|
|
a >> b.out[i]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b.lockTime = a.Read<uint32>(); |
|
|
|
|
|
|
|
return a; |
|
|
|
|
|
|
|
} |
|
|
|