diff --git a/src/blsct/tokens/rpc.cpp b/src/blsct/tokens/rpc.cpp index 7744f686bdeda..c418cf941891c 100644 --- a/src/blsct/tokens/rpc.cpp +++ b/src/blsct/tokens/rpc.cpp @@ -11,14 +11,20 @@ #include #include -std::vector 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 metadataResult = { + {RPCResult::Type::OBJ, "metadata", "", { + {RPCResult::Type::STR, "key", "the metadata key"}, + {RPCResult::Type::STR, "value", "the metadata value"}, + }}}; + +std::vector + 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}}}}} }; @@ -26,22 +32,31 @@ 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); } @@ -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); @@ -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); diff --git a/src/blsct/wallet/rpc.cpp b/src/blsct/wallet/rpc.cpp index cd30076709f14..6fe25af3722e4 100644 --- a/src/blsct/wallet/rpc.cpp +++ b/src/blsct/wallet/rpc.cpp @@ -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); } } diff --git a/src/node/miner.cpp b/src/node/miner.cpp index abd18ab4e7af1..3fc1d559d6d83 100644 --- a/src/node/miner.cpp +++ b/src/node/miner.cpp @@ -267,7 +267,7 @@ std::unique_ptr BlockAssembler::CreateNewBLSCTBlock(const blsct: std::vector 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()); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 0b1b401a755b1..08d999ae2c7d7 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -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); diff --git a/src/validation.cpp b/src/validation.cpp index 3712aa2106c01..09a0634f8e7d2 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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); diff --git a/test/functional/blsct_nft.py b/test/functional/blsct_nft.py index a6b72d796d9ea..decad9a0d761a 100755 --- a/test/functional/blsct_nft.py +++ b/test/functional/blsct_nft.py @@ -67,12 +67,12 @@ 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) @@ -80,9 +80,9 @@ def run_test(self): 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") @@ -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") @@ -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__': diff --git a/test/functional/blsct_token.py b/test/functional/blsct_token.py index 5c7f9cbbcadc0..ed958e7a5a535 100755 --- a/test/functional/blsct_token.py +++ b/test/functional/blsct_token.py @@ -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" @@ -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"