Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rpc and burn fee #174

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions src/blsct/tokens/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,52 @@
#include <util/strencodings.h>
#include <validation.h>

std::vector<RPCResult> tokenInfoResult = {
RPCResult{RPCResult::Type::STR_HEX, "tokenId", "the token id"},
RPCResult{RPCResult::Type::STR_HEX, "publicKey", "the token public key"},
RPCResult{RPCResult::Type::STR, "type", "the token type"},
RPCResult{RPCResult::Type::ANY, "metadata", "the token metadata"},
RPCResult{RPCResult::Type::NUM, "maxSupply", "the token max supply"},
RPCResult{RPCResult::Type::NUM, "currentSupply", true, "the token current supply"},
RPCResult{RPCResult::Type::ANY, "mintedNft", true, "the nfts already minted"},
std::vector<RPCResult> metadataResult = {
{RPCResult::Type::OBJ, "metadata", "", {
{RPCResult::Type::STR, "key", "the metadata key"},
{RPCResult::Type::STR, "value", "the metadata value"},
}}};

std::vector<RPCResult>
tokenInfoResult = {
RPCResult{RPCResult::Type::STR_HEX, "tokenId", "the token id"}, RPCResult{RPCResult::Type::STR_HEX, "publicKey", "the token public key"},
RPCResult{RPCResult::Type::STR, "type", "the token type"},
RPCResult{RPCResult::Type::ARR, "metadata", "the token metadata", metadataResult},
RPCResult{RPCResult::Type::NUM, "maxSupply", "the token max supply"},
RPCResult{RPCResult::Type::NUM, "currentSupply", true, "the token current supply"},
RPCResult{RPCResult::Type::ARR, "mintedNft", true, "the nfts already minted", {{RPCResult::Type::OBJ, "", "", {{RPCResult::Type::STR, "index", "the nft index"}, {RPCResult::Type::ARR, "metadata", "the token metadata", metadataResult}}}}}

};

void TokenToUniValue(UniValue& obj, const blsct::TokenEntry& token)
{
obj.pushKV("publicKey", token.info.publicKey.ToString());
obj.pushKV("type", blsct::TokenTypeToString(token.info.type));
UniValue metadata{UniValue::VOBJ};
UniValue metadata{UniValue::VARR};
for (auto& it : token.info.mapMetadata) {
metadata.pushKV(it.first, it.second);
UniValue metadataObj{UniValue::VOBJ};
metadataObj.pushKV("key", it.first);
metadataObj.pushKV("value", it.second);
metadata.push_back(metadataObj);
}
obj.pushKV("metadata", metadata);
obj.pushKV("maxSupply", token.info.nTotalSupply);
if (token.info.type == blsct::TokenType::TOKEN)
obj.pushKV("currentSupply", token.nSupply);
else if (token.info.type == blsct::TokenType::NFT) {
UniValue mintedNft{UniValue::VOBJ};
UniValue mintedNft{UniValue::VARR};
for (auto& it : token.mapMintedNft) {
UniValue nftMetadata{UniValue::VOBJ};
UniValue nftMetadata{UniValue::VARR};
UniValue nftObject{UniValue::VOBJ};
for (auto& it2 : it.second) {
nftMetadata.pushKV(it2.first, it2.second);
UniValue nftMetadataObj{UniValue::VOBJ};
nftMetadataObj.pushKV("key", it2.first);
nftMetadataObj.pushKV("value", it2.second);
nftMetadata.push_back(nftMetadataObj);
}
mintedNft.pushKV(strprintf("%llu", it.first), nftMetadata);
nftObject.pushKV("index", strprintf("%llu", it.first));
nftObject.pushKV("metadata", nftMetadata);
mintedNft.push_back(nftObject);
}
obj.pushKV("mintedNft", mintedNft);
}
Expand All @@ -62,7 +77,7 @@ gettoken()
},
},
RPCResult{RPCResult::Type::OBJ, "", "", tokenInfoResult},
RPCExamples{HelpExampleCli("gettoken", "ba12afc43322f204fe6236b11a0f85b5d9edcb09f446176c73fe4abe99a17edd")},
RPCExamples{HelpExampleCli("gettoken", "ba12afc43322f204fe6236b11a0f85b5d9edcb09f446176c73fe4abe99a17edd") + HelpExampleRpc("gettoken", "ba12afc43322f204fe6236b11a0f85b5d9edcb09f446176c73fe4abe99a17edd")},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
LOCK(cs_main);
ChainstateManager& chainman = EnsureAnyChainman(request.context);
Expand Down Expand Up @@ -94,7 +109,7 @@ listtokens()
RPCResult{RPCResult::Type::ARR, "", "", {
RPCResult{RPCResult::Type::OBJ, "", "", tokenInfoResult},
}},
RPCExamples{HelpExampleCli("listtokens", "")},
RPCExamples{HelpExampleCli("listtokens", "") + HelpExampleRpc("listtokens", "")},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
LOCK(cs_main);
ChainstateManager& chainman = EnsureAnyChainman(request.context);
Expand Down
15 changes: 11 additions & 4 deletions src/blsct/wallet/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,17 +465,24 @@ RPCHelpMan getnftbalance()

bool avoid_reuse = GetAvoidReuseFlag(*pwallet, request.params[4]);

UniValue ret(UniValue::VOBJ);
UniValue ret(UniValue::VARR);

for (auto& it : token.mapMintedNft) {
const auto bal = GetBalance(*pwallet, min_depth, avoid_reuse, TokenId(token_id, it.first));

if ((bal.m_mine_trusted + (include_watchonly ? bal.m_watchonly_trusted : 0)) > 0) {
UniValue metadata(UniValue::VOBJ);
UniValue retObj(UniValue::VOBJ);

UniValue metadata(UniValue::VARR);
for (auto& md_it : it.second) {
metadata.pushKV(md_it.first, md_it.second);
UniValue metadataObj(UniValue::VOBJ);
metadataObj.pushKV("key", md_it.first);
metadataObj.pushKV("value", md_it.second);
metadata.push_back(metadataObj);
}
ret.pushKV(strprintf("%llu", it.first), metadata);
retObj.pushKV("index", strprintf("%llu", it.first));
retObj.pushKV("metadata", metadata);
ret.push_back(retObj);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/node/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBLSCTBlock(const blsct:

std::vector<blsct::Signature> txSigs;

auto out = blsct::CreateOutput(destination.GetKeys(), nReward + nFees, "Reward");
auto out = blsct::CreateOutput(destination.GetKeys(), nReward, "Reward");

txSigs.push_back(blsct::PrivateKey(out.blindingKey).Sign(out.out.GetHash()));
txSigs.push_back(blsct::PrivateKey(out.gamma.Negate()).SignBalance());
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ static RPCHelpMan getblocktemplate()
result.pushKV("previousblockhash", pblock->hashPrevBlock.GetHex());
result.pushKV("transactions", transactions);
result.pushKV("coinbaseaux", aux);
result.pushKV("coinbasevalue", !consensusParams.fBLSCT ? (int64_t)pblock->vtx[0]->vout[0].nValue : (blockReward - pblocktemplate->vTxFees[0]));
result.pushKV("coinbasevalue", !consensusParams.fBLSCT ? (int64_t)pblock->vtx[0]->vout[0].nValue : (blockReward));
result.pushKV("longpollid", active_chain.Tip()->GetBlockHash().GetHex() + ToString(nTransactionsUpdatedLast));
result.pushKV("target", hashTarget.GetHex());
result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast() + 1);
Expand Down
6 changes: 3 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2683,11 +2683,11 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,

auto blockReward = pindex->nHeight == 1 ? params.GetConsensus().nBLSCTFirstBlockReward : params.GetConsensus().nBLSCTBlockReward;

if (!blsct::VerifyTx(*block.vtx[0], view, tx_state, nFees + blockReward)) {
if (!blsct::VerifyTx(*block.vtx[0], view, tx_state, blockReward)) {
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
return error("ConnectBlock(): VerifyTx on coinbase of block %s failed (fees: %s reward: %s)\n",
block.GetHash().ToString(), FormatMoney(nFees), FormatMoney(blockReward));
return error("ConnectBlock(): VerifyTx on coinbase of block %s failed (reward: %s)\n",
block.GetHash().ToString(), FormatMoney(blockReward));
}
} else if (block.vtx[0]->GetValueOut() > blockReward) {
LogPrintf("ERROR: ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)\n", block.vtx[0]->GetValueOut(), blockReward);
Expand Down
18 changes: 9 additions & 9 deletions test/functional/blsct_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ def run_test(self):
tokens = self.nodes[0].listtokens()
assert len(tokens) == 1, "length of tokens is not 1"

self.log.info(f"Created token: {token['tokenId']}")
self.log.info(f"Created NFT: {token['tokenId']}")

assert tokens[0]['type'] == 'nft', "token type is not token"
assert tokens[0]['metadata'] == {'name': 'Test'}, "incorrect metadata"
assert tokens[0]['metadata'] == [{'key':'name', 'value':'Test'}], "incorrect metadata"
assert tokens[0]['maxSupply'] == 1000, "incorrect max supply"
assert tokens[0]['mintedNft'] == {}, "incorrect current supply"
assert tokens[0]['mintedNft'] == [], "incorrect current supply"

wallet.mintnft(token['tokenId'], 1, blsct_address, {"id": "null"})
block_hashes = self.generatetoblsctaddress(self.nodes[0], 1, blsct_address)

tokenInfo = self.nodes[0].gettoken(token['tokenId'])

assert tokenInfo['type'] == 'nft', "token type is not token"
assert tokenInfo['metadata'] == {'name': 'Test'}, "incorrect metadata"
assert tokenInfo['metadata'] ==[{'key':'name', 'value':'Test'}], "incorrect metadata"
assert tokenInfo['maxSupply'] == 1000, "incorrect max supply"
assert tokenInfo['mintedNft'] == {'1': {'id': 'null'}}, "incorrect current supply"
assert tokenInfo['mintedNft'] == [{'index': '1', 'metadata': [{'key': 'id', 'value': 'null'}]}], "incorrect current supply"

self.log.info(f"Minted 1 NFT")

Expand All @@ -92,8 +92,8 @@ def run_test(self):
self.log.info(f"Balance in NODE 1: {nft_balance}")
self.log.info(f"Balance in NODE 2: {nft_balance_2}")

assert nft_balance == {'1': {'id': 'null'}}, "incorrect nft balance in node 1"
assert nft_balance_2 == {}, "incorrect nft balance in node 2"
assert nft_balance == [{'index': '1', 'metadata': [{'key': 'id', 'value': 'null'}]}], "incorrect nft balance in node 1"
assert nft_balance_2 == [], "incorrect nft balance in node 2"

self.log.info(f"Sending NFT with id #1 to NODE 2")

Expand All @@ -106,8 +106,8 @@ def run_test(self):
self.log.info(f"Balance in NODE 1: {nft_balance}")
self.log.info(f"Balance in NODE 2: {nft_balance_2}")

assert nft_balance_2 == {'1': {'id': 'null'}}, "incorrect nft balance in node 2"
assert nft_balance == {}, "incorrect nft balance in node"
assert nft_balance_2 == [{'index': '1', 'metadata': [{'key': 'id', 'value': 'null'}]}], "incorrect nft balance in node 2"
assert nft_balance == [], "incorrect nft balance in node"


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions test/functional/blsct_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def run_test(self):
self.log.info(f"Created token: {token['tokenId']}")

assert tokens[0]['type'] == 'token', "token type is not token"
assert tokens[0]['metadata'] == {'name': 'Test'}, "incorrect metadata"
assert tokens[0]['metadata'] == [{'key':'name', 'value':'Test'}], "incorrect metadata"
assert tokens[0]['maxSupply'] == 100000000000, "incorrect max supply"
assert tokens[0]['currentSupply'] == 0, "incorrect current supply"

Expand All @@ -80,7 +80,7 @@ def run_test(self):
tokenInfo = self.nodes[0].gettoken(token['tokenId'])

assert tokenInfo['type'] == 'token', "token type is not token"
assert tokenInfo['metadata'] == {'name': 'Test'}, "incorrect metadata"
assert tokenInfo['metadata'] == [{'key':'name', 'value':'Test'}], "incorrect metadata"
assert tokenInfo['maxSupply'] == 100000000000, "incorrect max supply"
assert tokenInfo['currentSupply'] == 100000000, "incorrect current supply"

Expand Down
Loading