Skip to content

Commit

Permalink
getblock RPC (#2291)
Browse files Browse the repository at this point in the history
* Finalize OP_RETURN default rules

* Cleanup coinbase rewards, getblock

* Cleanup reverse

* Revert "Finalize OP_RETURN default rules"

This reverts commit 87d70f4.

* Add ToUniValue

* Include vminfo on getblock

* Add support for Coinbase

* Multi-layered verbosity

* Refine ToUniValue methods

* Reduce noise

* Avoid confusing names for non UTXO rewards

* Further cleanups

* Minor format cleanup

* Use version terminology

* Pas blockreward by value

* Restore apply/reverse coinbase behaviour

* Update for tokenReward renames

---------

Co-authored-by: Bushstar <[email protected]>
  • Loading branch information
prasannavl and Bushstar authored Aug 7, 2023
1 parent 874a31e commit aa90c87
Show file tree
Hide file tree
Showing 14 changed files with 382 additions and 181 deletions.
80 changes: 40 additions & 40 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ class CMainParams : public CChainParams {
consensus.props.emergencyPeriod = 8640;
consensus.props.feeBurnPct = COIN / 2;

consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::IncentiveFunding, 45 * COIN / 200); // 45 DFI of 200 per block (rate normalized to (COIN == 100%))
consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::AnchorReward, COIN /10 / 200); // 0.1 DFI of 200 per block
consensus.blockTokenRewardsLegacy.emplace(CommunityAccountType::IncentiveFunding, 45 * COIN / 200); // 45 DFI of 200 per block (rate normalized to (COIN == 100%))
consensus.blockTokenRewardsLegacy.emplace(CommunityAccountType::AnchorReward, COIN /10 / 200); // 0.1 DFI of 200 per block

// New coinbase reward distribution
consensus.dist.masternode = 3333; // 33.33%
Expand All @@ -219,12 +219,12 @@ class CMainParams : public CChainParams {
consensus.dist.options = 988; // 9.88%
consensus.dist.unallocated = 173; // 1.73%

consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::AnchorReward, consensus.dist.anchor);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::IncentiveFunding, consensus.dist.liquidity);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Loan, consensus.dist.loan);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Options, consensus.dist.options);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Unallocated, consensus.dist.unallocated);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::CommunityDevFunds, consensus.dist.community);
consensus.blockTokenRewards.emplace(CommunityAccountType::AnchorReward, consensus.dist.anchor);
consensus.blockTokenRewards.emplace(CommunityAccountType::IncentiveFunding, consensus.dist.liquidity);
consensus.blockTokenRewards.emplace(CommunityAccountType::Loan, consensus.dist.loan);
consensus.blockTokenRewards.emplace(CommunityAccountType::Options, consensus.dist.options);
consensus.blockTokenRewards.emplace(CommunityAccountType::Unallocated, consensus.dist.unallocated);
consensus.blockTokenRewards.emplace(CommunityAccountType::CommunityDevFunds, consensus.dist.community);

// EVM chain id
consensus.evmChainId = 1130; // ETH main chain ID
Expand Down Expand Up @@ -483,8 +483,8 @@ class CTestNetParams : public CChainParams {
consensus.props.feeBurnPct = COIN / 2;


consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::IncentiveFunding, 45 * COIN / 200); // 45 DFI @ 200 per block (rate normalized to (COIN == 100%))
consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::AnchorReward, COIN/10 / 200); // 0.1 DFI @ 200 per block
consensus.blockTokenRewardsLegacy.emplace(CommunityAccountType::IncentiveFunding, 45 * COIN / 200); // 45 DFI @ 200 per block (rate normalized to (COIN == 100%))
consensus.blockTokenRewardsLegacy.emplace(CommunityAccountType::AnchorReward, COIN/10 / 200); // 0.1 DFI @ 200 per block

// New coinbase reward distribution
consensus.dist.masternode = 3333; // 33.33%
Expand All @@ -495,12 +495,12 @@ class CTestNetParams : public CChainParams {
consensus.dist.options = 988; // 9.88%
consensus.dist.unallocated = 173; // 1.73%

consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::AnchorReward, consensus.dist.anchor);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::IncentiveFunding, consensus.dist.liquidity);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Loan, consensus.dist.loan);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Options, consensus.dist.options);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Unallocated, consensus.dist.unallocated);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::CommunityDevFunds, consensus.dist.community);
consensus.blockTokenRewards.emplace(CommunityAccountType::AnchorReward, consensus.dist.anchor);
consensus.blockTokenRewards.emplace(CommunityAccountType::IncentiveFunding, consensus.dist.liquidity);
consensus.blockTokenRewards.emplace(CommunityAccountType::Loan, consensus.dist.loan);
consensus.blockTokenRewards.emplace(CommunityAccountType::Options, consensus.dist.options);
consensus.blockTokenRewards.emplace(CommunityAccountType::Unallocated, consensus.dist.unallocated);
consensus.blockTokenRewards.emplace(CommunityAccountType::CommunityDevFunds, consensus.dist.community);

// EVM chain id
consensus.evmChainId = 1131; // test chain ID
Expand Down Expand Up @@ -698,8 +698,8 @@ class CChangiParams : public CChainParams {
consensus.props.emergencyPeriod = 8640;
consensus.props.feeBurnPct = COIN / 2;

consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::IncentiveFunding, 45 * COIN / 200); // 45 DFI @ 200 per block (rate normalized to (COIN == 100%))
consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::AnchorReward, COIN/10 / 200); // 0.1 DFI @ 200 per block
consensus.blockTokenRewardsLegacy.emplace(CommunityAccountType::IncentiveFunding, 45 * COIN / 200); // 45 DFI @ 200 per block (rate normalized to (COIN == 100%))
consensus.blockTokenRewardsLegacy.emplace(CommunityAccountType::AnchorReward, COIN/10 / 200); // 0.1 DFI @ 200 per block

// New coinbase reward distribution
consensus.dist.masternode = 3333; // 33.33%
Expand All @@ -710,12 +710,12 @@ class CChangiParams : public CChainParams {
consensus.dist.options = 988; // 9.88%
consensus.dist.unallocated = 173; // 1.73%

consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::AnchorReward, consensus.dist.anchor);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::IncentiveFunding, consensus.dist.liquidity);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Loan, consensus.dist.loan);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Options, consensus.dist.options);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Unallocated, consensus.dist.unallocated);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::CommunityDevFunds, consensus.dist.community);
consensus.blockTokenRewards.emplace(CommunityAccountType::AnchorReward, consensus.dist.anchor);
consensus.blockTokenRewards.emplace(CommunityAccountType::IncentiveFunding, consensus.dist.liquidity);
consensus.blockTokenRewards.emplace(CommunityAccountType::Loan, consensus.dist.loan);
consensus.blockTokenRewards.emplace(CommunityAccountType::Options, consensus.dist.options);
consensus.blockTokenRewards.emplace(CommunityAccountType::Unallocated, consensus.dist.unallocated);
consensus.blockTokenRewards.emplace(CommunityAccountType::CommunityDevFunds, consensus.dist.community);

// EVM chain id
consensus.evmChainId = 1133; // changi chain ID
Expand Down Expand Up @@ -914,8 +914,8 @@ class CDevNetParams : public CChainParams {
consensus.props.emergencyPeriod = 8640;
consensus.props.feeBurnPct = COIN / 2;

consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::IncentiveFunding, 45 * COIN / 200); // 45 DFI @ 200 per block (rate normalized to (COIN == 100%))
consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::AnchorReward, COIN/10 / 200); // 0.1 DFI @ 200 per block
consensus.blockTokenRewardsLegacy.emplace(CommunityAccountType::IncentiveFunding, 45 * COIN / 200); // 45 DFI @ 200 per block (rate normalized to (COIN == 100%))
consensus.blockTokenRewardsLegacy.emplace(CommunityAccountType::AnchorReward, COIN/10 / 200); // 0.1 DFI @ 200 per block

// New coinbase reward distribution
consensus.dist.masternode = 3333; // 33.33%
Expand All @@ -926,12 +926,12 @@ class CDevNetParams : public CChainParams {
consensus.dist.options = 988; // 9.88%
consensus.dist.unallocated = 173; // 1.73%

consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::AnchorReward, consensus.dist.anchor);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::IncentiveFunding, consensus.dist.liquidity);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Loan, consensus.dist.loan);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Options, consensus.dist.options);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Unallocated, consensus.dist.unallocated);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::CommunityDevFunds, consensus.dist.community);
consensus.blockTokenRewards.emplace(CommunityAccountType::AnchorReward, consensus.dist.anchor);
consensus.blockTokenRewards.emplace(CommunityAccountType::IncentiveFunding, consensus.dist.liquidity);
consensus.blockTokenRewards.emplace(CommunityAccountType::Loan, consensus.dist.loan);
consensus.blockTokenRewards.emplace(CommunityAccountType::Options, consensus.dist.options);
consensus.blockTokenRewards.emplace(CommunityAccountType::Unallocated, consensus.dist.unallocated);
consensus.blockTokenRewards.emplace(CommunityAccountType::CommunityDevFunds, consensus.dist.community);

// EVM chain id
consensus.evmChainId = 1132; // dev chain ID
Expand Down Expand Up @@ -1133,8 +1133,8 @@ class CRegTestParams : public CChainParams {

consensus.vaultCreationFee = 1 * COIN;

consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::IncentiveFunding, 10 * COIN / 50); // normalized to (COIN == 100%) // 10 per block
consensus.nonUtxoBlockSubsidies.emplace(CommunityAccountType::AnchorReward, COIN/10 / 50); // 0.1 per block
consensus.blockTokenRewardsLegacy.emplace(CommunityAccountType::IncentiveFunding, 10 * COIN / 50); // normalized to (COIN == 100%) // 10 per block
consensus.blockTokenRewardsLegacy.emplace(CommunityAccountType::AnchorReward, COIN/10 / 50); // 0.1 per block

// New coinbase reward distribution
consensus.dist.masternode = 3333; // 33.33%
Expand All @@ -1145,12 +1145,12 @@ class CRegTestParams : public CChainParams {
consensus.dist.options = 988; // 9.88%
consensus.dist.unallocated = 173; // 1.73%

consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::AnchorReward, consensus.dist.anchor);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::IncentiveFunding, consensus.dist.liquidity);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Loan, consensus.dist.loan);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Options, consensus.dist.options);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::Unallocated, consensus.dist.unallocated);
consensus.newNonUTXOSubsidies.emplace(CommunityAccountType::CommunityDevFunds, consensus.dist.community);
consensus.blockTokenRewards.emplace(CommunityAccountType::AnchorReward, consensus.dist.anchor);
consensus.blockTokenRewards.emplace(CommunityAccountType::IncentiveFunding, consensus.dist.liquidity);
consensus.blockTokenRewards.emplace(CommunityAccountType::Loan, consensus.dist.loan);
consensus.blockTokenRewards.emplace(CommunityAccountType::Options, consensus.dist.options);
consensus.blockTokenRewards.emplace(CommunityAccountType::Unallocated, consensus.dist.unallocated);
consensus.blockTokenRewards.emplace(CommunityAccountType::CommunityDevFunds, consensus.dist.community);

// EVM chain id
consensus.evmChainId = 1133; // regtest chain ID
Expand Down
4 changes: 2 additions & 2 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ struct Params {
};
CProposalParams props;

std::map<CommunityAccountType, CAmount> nonUtxoBlockSubsidies;
std::map<CommunityAccountType, uint32_t> newNonUTXOSubsidies;
std::map<CommunityAccountType, CAmount> blockTokenRewardsLegacy;
std::map<CommunityAccountType, uint32_t> blockTokenRewards;

uint64_t evmChainId;
};
Expand Down
2 changes: 1 addition & 1 deletion src/core_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
std::string SighashToStr(unsigned char sighash_type);
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
void ScriptToUniv(const CScript& script, UniValue& out, bool include_address);
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0);
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, int verbosity = 0);

#endif // DEFI_CORE_IO_H
64 changes: 35 additions & 29 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,9 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey,
out.pushKV("addresses", a);
}

void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags)
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags, int version)
{
entry.pushKV("txid", tx.GetHash().GetHex());
entry.pushKV("hash", tx.GetWitnessHash().GetHex());
entry.pushKV("version", tx.nVersion);
entry.pushKV("size", (int)::GetSerializeSize(tx, PROTOCOL_VERSION));
entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR);
entry.pushKV("weight", GetTransactionWeight(tx));
entry.pushKV("locktime", (int64_t)tx.nLockTime);

UniValue vin(UniValue::VARR);
for (unsigned int i = 0; i < tx.vin.size(); i++) {
const CTxIn& txin = tx.vin[i];
const auto txInToUniValue = [](const CTransaction& tx, const CTxIn& txin, const unsigned int index, bool include_hex) {
UniValue in(UniValue::VOBJ);
if (tx.IsCoinBase())
in.pushKV("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
Expand All @@ -204,38 +194,54 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
in.pushKV("vout", (int64_t)txin.prevout.n);
UniValue o(UniValue::VOBJ);
o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true));
o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
if (include_hex) {
o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()));
}
in.pushKV("scriptSig", o);
if (!tx.vin[i].scriptWitness.IsNull()) {
if (!tx.vin[index].scriptWitness.IsNull()) {
UniValue txinwitness(UniValue::VARR);
for (const auto& item : tx.vin[i].scriptWitness.stack) {
for (const auto& item : tx.vin[index].scriptWitness.stack) {
txinwitness.push_back(HexStr(item.begin(), item.end()));
}
in.pushKV("txinwitness", txinwitness);
}
}
in.pushKV("sequence", (int64_t)txin.nSequence);
vin.push_back(in);
}
entry.pushKV("vin", vin);

UniValue vout(UniValue::VARR);
for (unsigned int i = 0; i < tx.vout.size(); i++) {
const CTxOut& txout = tx.vout[i];
return in;
};

const auto txOutToUniValue = [](const CTransaction& tx, const CTxOut& txout, const unsigned int index, bool include_hex, int version) {
UniValue out(UniValue::VOBJ);

out.pushKV("value", ValueFromAmount(txout.nValue));
out.pushKV("n", (int64_t)i);

out.pushKV("n", (int64_t)index);
UniValue o(UniValue::VOBJ);
ScriptPubKeyToUniv(txout.scriptPubKey, o, true);
ScriptPubKeyToUniv(txout.scriptPubKey, o, include_hex);
out.pushKV("scriptPubKey", o);
// Start to print tokenId start from version TOKENS_MIN_VERSION
if (tx.nVersion >= CTransaction::TOKENS_MIN_VERSION) {
// We skip this for v3+ as we tokenId field is unused.
if (version <= 2 && tx.nVersion >= CTransaction::TOKENS_MIN_VERSION) {
// Start to print tokenId start from version TOKENS_MIN_VERSION
out.pushKV("tokenId", (uint64_t)txout.nTokenId.v);
}
vout.push_back(out);
return out;
};

entry.pushKV("txid", tx.GetHash().GetHex());
entry.pushKV("hash", tx.GetWitnessHash().GetHex());
entry.pushKV("version", tx.nVersion);
entry.pushKV("size", (int)::GetSerializeSize(tx, PROTOCOL_VERSION));
entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR);
entry.pushKV("weight", GetTransactionWeight(tx));
entry.pushKV("locktime", (int64_t)tx.nLockTime);

UniValue vin(UniValue::VARR);
for (unsigned int i = 0; i < tx.vin.size(); i++) {
vin.push_back(txInToUniValue(tx, tx.vin[i], i, include_hex));
}
entry.pushKV("vin", vin);

UniValue vout(UniValue::VARR);
for (unsigned int i = 0; i < tx.vout.size(); i++) {
vout.push_back(txOutToUniValue(tx, tx.vout[i], i, include_hex, version));
}
entry.pushKV("vout", vout);

Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/incentivefunding.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ inline CommunityAccountType CommunityAccountCodeToType(unsigned char ch) {
return CommunityAccountType::None;
}

inline const char *GetCommunityAccountName(CommunityAccountType t) {
inline const std::string GetCommunityAccountName(const CommunityAccountType t) {
switch (t) {
case CommunityAccountType::IncentiveFunding:
return "IncentiveFunding";
Expand Down
Loading

0 comments on commit aa90c87

Please sign in to comment.