This commit is contained in:
jl777
2018-07-26 00:17:47 -11:00
parent 6fa0da91a0
commit ba8a98f2e7
3 changed files with 16 additions and 14 deletions

View File

@@ -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);

View File

@@ -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<uint8_t> 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<uint8_t> 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);

View File

@@ -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"));