From 1cdfa0b54b1c9996a4e2c73899ef38c0bd1ef065 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 27 Jul 2018 01:25:50 -1100 Subject: [PATCH] Test --- src/cc/CCassetstx.cpp | 25 ++++++++++++++++++++++++- src/cc/CCinclude.h | 1 + src/cc/CCutils.cpp | 14 +++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 646c8f66a..2dc9790b7 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -57,12 +57,35 @@ int64_t GetAssetBalance(CPubKey pk,uint256 tokenid) return(AddAssetInputs(cp,mtx,pk,tokenid,0,0)); } -UniValue AssetInfo(uint256 refassetid) +UniValue AssetInfo(uint256 assetid) { + UniValue result(UniValue::VARR); uint256 hashBlock; CTransaction vintx; std::vector origpubkey; std::string name,description; char str[67],numstr[65]; + if ( GetTransaction(assetid,vintx,hashBlock,false) == 0 ) + { + fprintf(stderr,"cant find assetid\n"); + result.push_back(Pair("error","cant find assetid")); + return(0); + } + if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) + { + fprintf(stderr,"assetid isnt assetcreation txid\n"); + result.push_back(Pair("error","assetid isnt assetcreation txid")); + } + result.push_back(Pair("result","success")); + result.push_back(Pair("tokenid",uint256_str(str,assetid))); + result.push_back(Pair("owner",pubkey33_str(str,origpubkey.data()))); + result.push_back(Pair("name",name)); + sprintf(numstr,"%.8f",(double)vintx.vout[0].nValue/COIN); + result.push_back(Pair("supply",numstr)); + result.push_back(Pair("description",description)); + result.push_back(Pair("result","success")); + return(result); } UniValue AssetList() { + UniValue result(UniValue::VARR); + return(result); } UniValue AssetOrders(uint256 refassetid) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index da1cf252e..c0bd56c64 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -60,6 +60,7 @@ int32_t unstringbits(char *buf,uint64_t bits); uint64_t stringbits(char *str); uint256 revuint256(uint256 txid); char *uint256_str(char *dest,uint256 txid); +char *pubkey33_str(char *dest,uint8_t *pubkey33); uint256 Parseuint256(char *hexstr); CPubKey pubkey2pk(std::vector pubkey); bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index d9672c61d..039f5cbd9 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -92,7 +92,19 @@ char *uint256_str(char *dest,uint256 txid) int32_t i,j=0; for (i=31; i>=0; i--) sprintf(&dest[j++ * 2],"%02x",((uint8_t *)&txid)[i]); - return(dest); + dest[64] = 0; + return(dest); +} + +char *pubkey33_str(char *dest,uint8_t *pubkey33) +{ + int32_t i; + if ( pubkey33 != 0 ) + { + for (i=0; i<33; i++) + sprintf(&dest[i * 2],"%02x",pubkey33[i]); + } else dest[0] = 0; + return(dest); } uint256 Parseuint256(char *hexstr)