Fix dropped assetoshis

This commit is contained in:
jl777
2018-07-25 07:51:07 -11:00
parent e9d56b2cda
commit eac2c15e5d
3 changed files with 26 additions and 13 deletions

View File

@@ -252,9 +252,9 @@ std::string FillBuyOffer(uint64_t txfee,uint256 assetid,uint256 bidtxid,uint64_t
mtx.vin.push_back(CTxIn(bidtxid,bidvout,CScript()));
if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,fillamount,60)) > 0 )
{
SetAssetFillamounts(0,paid_amount,remaining_required,bidamount,fillamount,origprice);
if ( inputs > fillamount )
CCchange = (inputs - fillamount);
SetAssetFillamounts(0,paid_amount,remaining_required,bidamount,fillamount,origprice);
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,bidamount - paid_amount,GetUnspendable(cp,0)));
mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,fillamount,pubkey2pk(origpubkey)));
@@ -287,9 +287,9 @@ std::string FillSell(uint64_t txfee,uint256 assetid,uint256 assetid2,uint256 ask
else inputs = AddNormalinputs(mtx,mypk,fillamount,60);
if ( inputs > 0 )
{
SetAssetFillamounts(1,paid_amount,remaining_required,askamount,fillamount,totalunits);
if ( assetid2 == zeroid && inputs > fillamount )
CCchange = (inputs - fillamount);
SetAssetFillamounts(1,paid_amount,remaining_required,askamount,fillamount,totalunits);
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,askamount - paid_amount,GetUnspendable(cp,0)));
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,paid_amount,mypk));
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,fillamount,pubkey2pk(origpubkey)));

View File

@@ -81,7 +81,7 @@ uint8_t DecodeRewardsOpRet(const CScript &scriptPubKey,uint64_t &sbits,uint256 &
script = (uint8_t *)vopret.data();
if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> sbits; ss >> fundingtxid) != 0 )
{
if ( e == EVAL_REWARDS && (f == 'L' || f == 'U') )
if ( e == EVAL_REWARDS && (f == 'L' || f == 'U' || f == 'A') )
return(f);
}
return(0);
@@ -215,6 +215,12 @@ uint64_t RewardsPlanFunds(uint64_t &refsbits,struct CCcontract_info *cp,CPubKey
return(totalinputs);
}
bool RewardsPlanExists(uint64_t sbits)
{
// get list of all possible plans
// compare sbits
}
std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid)
{
CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t funding,sbits,reward,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C;
@@ -252,6 +258,11 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,uint64_t funds,uin
txfee = 10000;
mypk = pubkey2pk(Mypubkey());
rewardspk = GetUnspendable(cp,0);
if ( RewardsPlanExists(sbits) != 0 )
{
fprintf(stderr,"Rewards plan %s already exists\n",planstr);
return(0);
}
funding = RewardsPlanFunds(sbits,cp,rewardspk,planstr,zeroid);
if ( AddNormalinputs(mtx,mypk,funds+2*txfee,64) > 0 )
{
@@ -265,21 +276,23 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,uint64_t funds,uin
std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,uint64_t amount)
{
CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,funding; struct CCcontract_info *cp,C;
CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t sbits; struct CCcontract_info *cp,C;
cp = CCinit(&C,EVAL_REWARDS);
if ( txfee == 0 )
txfee = 10000;
mypk = pubkey2pk(Mypubkey());
rewardspk = GetUnspendable(cp,0);
if ( (funding= RewardsPlanFunds(sbits,cp,rewardspk,planstr,fundingtxid)) >= amount )
if ( RewardsPlanExists(sbits) == 0 )
{
if ( AddNormalinputs(mtx,mypk,amount+txfee,64) > 0 )
{
mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,rewardspk));
return(FinalizeCCTx(cp,mtx,mypk,txfee,EncodeRewardsOpRet('L',sbits,fundingtxid)));
} else fprintf(stderr,"cant find enough inputs\n");
fprintf(stderr,"Rewards plan %s doesnt exist\n",planstr);
return(0);
}
fprintf(stderr,"cant find rewards inputs\n");
if ( AddNormalinputs(mtx,mypk,amount+txfee,64) > 0 )
{
mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,rewardspk));
return(FinalizeCCTx(cp,mtx,mypk,txfee,EncodeRewardsOpRet('A',sbits,fundingtxid)));
} else fprintf(stderr,"cant find enough inputs\n");
fprintf(stderr,"cant find fundingtxid\n");
return(0);
}
@@ -291,7 +304,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint64_
txfee = 10000;
mypk = pubkey2pk(Mypubkey());
rewardspk = GetUnspendable(cp,0);
if ( (funding= RewardsPlanFunds(sbits,cp,rewardspk,planstr,fundingtxid)) >= amount )
if ( (funding= RewardsPlanFunds(sbits,cp,rewardspk,planstr,fundingtxid)) >= amount ) // arbitrary cmp
{
if ( AddNormalinputs(mtx,mypk,amount+txfee,64) > 0 )
{

View File

@@ -4961,7 +4961,7 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); char *name; uint64_t funds,APR,minseconds,maxseconds,mindeposit; std::string hex;
if ( fHelp || params.size() > 6 || params.size() < 2 )
throw runtime_error("rewardsfund name amount APR mindays maxdays mindeposit\n");
throw runtime_error("rewardscreatefunding name amount APR mindays maxdays mindeposit\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");
// default to OOT params