|
@ -39,6 +39,13 @@ BlockInfo::BlockInfo(bytesConstRef _block) |
|
|
populate(_block); |
|
|
populate(_block); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BlockInfo BlockInfo::fromHeader(bytesConstRef _block) |
|
|
|
|
|
{ |
|
|
|
|
|
BlockInfo ret; |
|
|
|
|
|
ret.populateFromHeader(RLP(_block)); |
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bytes BlockInfo::createGenesisBlock() |
|
|
bytes BlockInfo::createGenesisBlock() |
|
|
{ |
|
|
{ |
|
|
RLPStream block(3); |
|
|
RLPStream block(3); |
|
@ -79,31 +86,37 @@ void BlockInfo::populateGenesis() |
|
|
populate(&genesisBlock); |
|
|
populate(&genesisBlock); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void BlockInfo::populate(bytesConstRef _block) |
|
|
void BlockInfo::populateFromHeader(RLP const& _header) |
|
|
{ |
|
|
{ |
|
|
RLP root(_block); |
|
|
|
|
|
int field = 0; |
|
|
int field = 0; |
|
|
RLP header = root[0]; |
|
|
|
|
|
if (!header.isList()) |
|
|
|
|
|
throw InvalidBlockFormat(0, header.data()); |
|
|
|
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
hash = eth::sha3(_block); |
|
|
parentHash = _header[field = 0].toHash<h256>(); |
|
|
parentHash = header[field = 0].toHash<h256>(); |
|
|
sha3Uncles = _header[field = 1].toHash<h256>(); |
|
|
sha3Uncles = header[field = 1].toHash<h256>(); |
|
|
coinbaseAddress = _header[field = 2].toHash<Address>(); |
|
|
coinbaseAddress = header[field = 2].toHash<Address>(); |
|
|
stateRoot = _header[field = 3].toHash<h256>(); |
|
|
stateRoot = header[field = 3].toHash<h256>(); |
|
|
sha3Transactions = _header[field = 4].toHash<h256>(); |
|
|
sha3Transactions = header[field = 4].toHash<h256>(); |
|
|
difficulty = _header[field = 5].toInt<u256>(); |
|
|
difficulty = header[field = 5].toInt<u256>(); |
|
|
timestamp = _header[field = 6].toInt<u256>(); |
|
|
timestamp = header[field = 6].toInt<u256>(); |
|
|
extraData = _header[field = 7].toBytes(); |
|
|
extraData = header[field = 7].toBytes(); |
|
|
nonce = _header[field = 8].toHash<h256>(); |
|
|
nonce = header[field = 8].toHash<h256>(); |
|
|
|
|
|
} |
|
|
} |
|
|
catch (RLP::BadCast) |
|
|
catch (RLP::BadCast) |
|
|
{ |
|
|
{ |
|
|
throw InvalidBlockHeaderFormat(field, header[field].data()); |
|
|
throw InvalidBlockHeaderFormat(field, _header[field].data()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void BlockInfo::populate(bytesConstRef _block) |
|
|
|
|
|
{ |
|
|
|
|
|
hash = eth::sha3(_block); |
|
|
|
|
|
|
|
|
|
|
|
RLP root(_block); |
|
|
|
|
|
RLP header = root[0]; |
|
|
|
|
|
if (!header.isList()) |
|
|
|
|
|
throw InvalidBlockFormat(0, header.data()); |
|
|
|
|
|
populateFromHeader(header); |
|
|
|
|
|
|
|
|
if (!root[1].isList()) |
|
|
if (!root[1].isList()) |
|
|
throw InvalidBlockFormat(1, root[1].data()); |
|
|
throw InvalidBlockFormat(1, root[1].data()); |
|
|
if (!root[2].isList()) |
|
|
if (!root[2].isList()) |
|
|