diff --git a/src/blsct/tokens/rpc.cpp b/src/blsct/tokens/rpc.cpp index b5870563c4226..c418cf941891c 100644 --- a/src/blsct/tokens/rpc.cpp +++ b/src/blsct/tokens/rpc.cpp @@ -11,16 +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::OBJ_DYN, "metadata", "the token metadata", { - {RPCResult::Type::STR, "", "the metadata value"}, - }}, - RPCResult{RPCResult::Type::NUM, "maxSupply", "the token max supply"}, RPCResult{RPCResult::Type::NUM, "currentSupply", true, "the token current supply"}, RPCResult{RPCResult::Type::OBJ_DYN, "mintedNft", true, "the nfts already minted", {{RPCResult::Type::OBJ, "", "", { - {RPCResult::Type::STR, "", "the metadata value"}, - }}}} +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}}}}} }; @@ -28,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); } 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/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"