mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-02-04 19:24:20 +00:00
WIP: Fixed extra field deserialization.
This commit is contained in:
parent
adb3502f77
commit
4d44c773c6
@ -594,12 +594,18 @@ namespace cryptonote
|
||||
//---------------------------------------------------------------
|
||||
bool append_keva_block_to_extra(std::vector<uint8_t>& tx_extra, const tx_extra_keva_block& keva_block)
|
||||
{
|
||||
blobdata blob;
|
||||
if (!t_serializable_object_to_blob(keva_block, blob))
|
||||
return false;
|
||||
|
||||
tx_extra.push_back(TX_EXTRA_KEVA_BLOCK_TAG);
|
||||
std::copy(reinterpret_cast<const uint8_t*>(blob.data()), reinterpret_cast<const uint8_t*>(blob.data() + blob.size()), std::back_inserter(tx_extra));
|
||||
// convert to variant
|
||||
tx_extra_field field = tx_extra_keva_block{ keva_block };
|
||||
// serialize
|
||||
std::ostringstream oss;
|
||||
binary_archive<true> ar(oss);
|
||||
bool r = ::do_serialize(ar, field);
|
||||
CHECK_AND_NO_ASSERT_MES_L1(r, false, "failed to serialize tx extra keva block");
|
||||
// append
|
||||
std::string tx_extra_str = oss.str();
|
||||
size_t pos = tx_extra.size();
|
||||
tx_extra.resize(tx_extra.size() + tx_extra_str.size());
|
||||
memcpy(&tx_extra[pos], tx_extra_str.data(), tx_extra_str.size());
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
|
@ -928,6 +928,20 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||
}
|
||||
cn_block.miner_tx = miner_tx;
|
||||
|
||||
// No transactions other than coinbase.
|
||||
cn_block.tx_hashes.clear();
|
||||
|
||||
// Copy keva block to extra so that we can use it in submitblock.
|
||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
|
||||
stream << *pblock;
|
||||
std::string kevaBlockData = stream.str();
|
||||
cryptonote::tx_extra_keva_block extra_keva_block;
|
||||
extra_keva_block.keva_block = kevaBlockData;
|
||||
if (!cryptonote::append_keva_block_to_extra(cn_block.miner_tx.extra, extra_keva_block)) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Internal error: failed to add block");
|
||||
}
|
||||
|
||||
// Now cn_block is finalized, we can calculate the reserved offset position.
|
||||
cryptonote::blobdata block_blob = cryptonote::t_serializable_object_to_blob(cn_block);
|
||||
crypto::public_key tx_pub_key = cryptonote::get_tx_pub_key_from_extra(cn_block.miner_tx);
|
||||
if(tx_pub_key == crypto::null_pkey) {
|
||||
@ -942,21 +956,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||
{
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Internal error: Failed to calculate offset");
|
||||
}
|
||||
|
||||
// No transactions other than coinbase.
|
||||
cn_block.tx_hashes.clear();
|
||||
|
||||
// Copy keva block to extra so that we can use it in submitblock.
|
||||
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
|
||||
stream << *pblock;
|
||||
std::string kevaBlockData = HexStr(stream.begin(), stream.end());
|
||||
cryptonote::tx_extra_keva_block extra_keva_block;
|
||||
extra_keva_block.keva_block = kevaBlockData;
|
||||
if (!cryptonote::append_keva_block_to_extra(cn_block.miner_tx.extra, extra_keva_block)) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Internal error: failed to add block");
|
||||
}
|
||||
cryptonote::blobdata template_blob = cryptonote::block_to_blob(cn_block);
|
||||
std::string hex_template_blob = HexStr(template_blob.begin(), template_blob.end());
|
||||
std::string hex_template_blob = HexStr(block_blob.begin(), block_blob.end());
|
||||
|
||||
UniValue result(UniValue::VOBJ);
|
||||
const uint64_t difficulty = ConvertNBitsToDiff(pblock->nBits);
|
||||
|
Loading…
x
Reference in New Issue
Block a user