From ba8a98f2e7a03bdffcdf001f0859fb6e6a9449ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Jul 2018 00:17:47 -1100 Subject: [PATCH] Test --- src/cc/CCassetsCore.cpp | 8 ++++---- src/cc/CCassetstx.cpp | 6 ++++-- src/wallet/rpcwallet.cpp | 16 ++++++++-------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index d8ab4f44d..73836e144 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -101,7 +101,7 @@ bool SetBidFillamounts(uint64_t &received_nValue,uint64_t &remaining_units,uint6 bool SetAskFillamounts(uint64_t &received_assetoshis,uint64_t &remaining_nValue,uint64_t orig_assetoshis,uint64_t &paid_nValue,uint64_t total_nValue) { - uint64_t remaining_assetoshis,unitprice; + uint64_t remaining_assetoshis; double dunitprice; if ( total_nValue == 0 ) { received_assetoshis = remaining_nValue = paid_nValue = 0; @@ -128,10 +128,10 @@ bool SetAskFillamounts(uint64_t &received_assetoshis,uint64_t &remaining_nValue, "totalrequired": "1000.00000000", "price": "100.00000000" },*/ - unitprice = (total_nValue / orig_assetoshis); - received_assetoshis = (paid_nValue / unitprice); + dunitprice = ((double)total_nValue / orig_assetoshis); + received_assetoshis = (paid_nValue / dunitprice); fprintf(stderr,"remaining_nValue %.8f (%.8f - %.8f)\n",(double)remaining_nValue/COIN,(double)total_nValue/COIN,(double)paid_nValue/COIN); - fprintf(stderr,"unitprice %.8f received_assetoshis %llu orig %llu\n",(double)unitprice/COIN,(long long)received_assetoshis,(long long)orig_assetoshis); + fprintf(stderr,"unitprice %.8f received_assetoshis %llu orig %llu\n",unitprice,(long long)received_assetoshis,(long long)orig_assetoshis); if ( unitprice > 0 && received_assetoshis > 0 && received_assetoshis <= orig_assetoshis ) { remaining_assetoshis = (orig_assetoshis - received_assetoshis); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index d59d32d5c..13e5fa2ca 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -297,9 +297,9 @@ std::string FillBuyOffer(uint64_t txfee,uint256 assetid,uint256 bidtxid,uint64_t return("no normal coins left"); } -std::string FillSell(uint64_t txfee,uint256 assetid,uint256 assetid2,uint256 asktxid,uint64_t paid_nValue) +std::string FillSell(uint64_t txfee,uint256 assetid,uint256 assetid2,uint256 asktxid,uint64_t fillunits) { - CTransaction vintx,filltx; uint256 hashBlock; CMutableTransaction mtx; CPubKey mypk; std::vector origpubkey; int32_t askvout=0; uint64_t received_assetoshis,total_nValue,orig_assetoshis,remaining_nValue,inputs,CCchange=0; struct CCcontract_info *cp,C; + CTransaction vintx,filltx; uint256 hashBlock; CMutableTransaction mtx; CPubKey mypk; std::vector origpubkey; double dprice; int32_t askvout=0; uint64_t received_assetoshis,total_nValue,orig_assetoshis,paid_nValue,remaining_nValue,inputs,CCchange=0; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) txfee = 10000; @@ -310,6 +310,8 @@ std::string FillSell(uint64_t txfee,uint256 assetid,uint256 assetid2,uint256 ask { orig_assetoshis = vintx.vout[askvout].nValue; SetAssetOrigpubkey(origpubkey,total_nValue,vintx); + dprice = (double)total_nValue / (COIN * orig_assetoshis); + paid_nValue = dprice * fillunits; mtx.vin.push_back(CTxIn(asktxid,askvout,CScript())); if ( assetid2 != zeroid ) inputs = AddAssetInputs(cp,mtx,mypk,assetid2,paid_nValue,60); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index dcce4324e..d1fef5092 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5316,15 +5316,15 @@ UniValue tokencancelask(const UniValue& params, bool fHelp) UniValue tokenfillask(const UniValue& params, bool fHelp) { static uint256 zeroid; - UniValue result(UniValue::VOBJ); uint64_t fillamount; std::string hex; uint256 tokenid,asktxid; + UniValue result(UniValue::VOBJ); uint64_t fillunits; std::string hex; uint256 tokenid,asktxid; if ( fHelp || params.size() != 3 ) - throw runtime_error("tokenfillask tokenid asktxid fillamount\n"); + throw runtime_error("tokenfillask tokenid asktxid fillunits\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); tokenid = Parseuint256((char *)params[0].get_str().c_str()); asktxid = Parseuint256((char *)params[1].get_str().c_str()); - fillamount = atof(params[2].get_str().c_str()) * COIN; - hex = FillSell(0,tokenid,zeroid,asktxid,fillamount); + fillunits = atol(params[2].get_str().c_str()); + hex = FillSell(0,tokenid,zeroid,asktxid,fillunits); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -5336,16 +5336,16 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) UniValue tokenfillswap(const UniValue& params, bool fHelp) { static uint256 zeroid; - UniValue result(UniValue::VOBJ); uint64_t fillamount; std::string hex; uint256 tokenid,otherid,asktxid; + UniValue result(UniValue::VOBJ); uint64_t fillunits; std::string hex; uint256 tokenid,otherid,asktxid; if ( fHelp || params.size() != 4 ) - throw runtime_error("tokenfillswap tokenid otherid asktxid fillamount\n"); + throw runtime_error("tokenfillswap tokenid otherid asktxid fillunits\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); tokenid = Parseuint256((char *)params[0].get_str().c_str()); otherid = Parseuint256((char *)params[1].get_str().c_str()); asktxid = Parseuint256((char *)params[2].get_str().c_str()); - fillamount = atol(params[3].get_str().c_str()); - hex = FillSell(0,tokenid,otherid,asktxid,fillamount); + fillunits = atol(params[3].get_str().c_str()); + hex = FillSell(0,tokenid,otherid,asktxid,fillunits); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success"));