Fixes
This commit is contained in:
@@ -24,12 +24,12 @@ uint64_t RewardsCalc(uint64_t claim,uint256 txid)
|
||||
return(reward);
|
||||
}
|
||||
|
||||
uint64_t IsRewardsvout(const CTransaction& tx,int32_t v)
|
||||
uint64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v)
|
||||
{
|
||||
char destaddr[64];
|
||||
if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 )
|
||||
{
|
||||
if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,RewardsCCaddr) == 0 )
|
||||
if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 )
|
||||
return(tx.vout[v].nValue);
|
||||
}
|
||||
return(0);
|
||||
@@ -51,7 +51,7 @@ bool RewardsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio
|
||||
{
|
||||
if ( hashBlock == zerohash )
|
||||
return eval->Invalid("cant rewards from mempool");
|
||||
if ( (assetoshis= IsRewardsvout(vinTx,tx.vin[i].prevout.n)) != 0 )
|
||||
if ( (assetoshis= IsRewardsvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 )
|
||||
inputs += assetoshis;
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ bool RewardsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio
|
||||
for (i=0; i<numvouts; i++)
|
||||
{
|
||||
//fprintf(stderr,"i.%d of numvouts.%d\n",i,numvouts);
|
||||
if ( (assetoshis= IsRewardsvout(tx,i)) != 0 )
|
||||
if ( (assetoshis= IsRewardsvout(cp,tx,i)) != 0 )
|
||||
outputs += assetoshis;
|
||||
}
|
||||
if ( inputs != outputs+COIN+txfee )
|
||||
@@ -90,7 +90,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t
|
||||
else
|
||||
{
|
||||
preventCCvouts = 1;
|
||||
if ( IsRewardsvout(tx,0) != 0 )
|
||||
if ( IsRewardsvout(cp,tx,0) != 0 )
|
||||
{
|
||||
preventCCvouts++;
|
||||
i = 1;
|
||||
@@ -124,18 +124,18 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t
|
||||
return(false);
|
||||
}*/
|
||||
|
||||
uint64_t AddRewardsInputs(CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs)
|
||||
uint64_t AddRewardsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs)
|
||||
{
|
||||
char coinaddr[64]; uint64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector<uint8_t> origpubkey; CTransaction vintx; int32_t n = 0;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(EVAL_REWARDS,coinaddr,pk);
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
SetCCunspents(unspentOutputs,coinaddr);
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 )
|
||||
{
|
||||
if ( (nValue= IsRewardsvout(vintx,(int32_t)it->first.index)) > 0 )
|
||||
if ( (nValue= IsRewardsvout(cp,vintx,(int32_t)it->first.index)) > 0 )
|
||||
{
|
||||
if ( total != 0 && maxinputs != 0 )
|
||||
mtx.vin.push_back(CTxIn(txid,(int32_t)it->first.index,CScript()));
|
||||
@@ -150,50 +150,13 @@ uint64_t AddRewardsInputs(CMutableTransaction &mtx,CPubKey pk,uint64_t total,int
|
||||
return(totalinputs);
|
||||
}
|
||||
|
||||
// 0.834% every 60 days, min 100, capped at 0.834%
|
||||
|
||||
std::string RewardsFund(uint64_t txfee,uint64_t funds,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit)
|
||||
{
|
||||
CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret;
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
rewardspk = GetUnspendable(EVAL_REWARDS,0);
|
||||
if ( AddNormalinputs(mtx,mypk,funds+2*txfee,64) > 0 )
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_REWARDS,funds,rewardspk));
|
||||
mtx.vout.push_back(CTxOut(APR,CScript() << ParseHex(HexStr(rewardspk)) << OP_CHECKSIG));
|
||||
mtx.vout.push_back(CTxOut(minseconds,CScript() << ParseHex(HexStr(rewardspk)) << OP_CHECKSIG));
|
||||
mtx.vout.push_back(CTxOut(maxseconds,CScript() << ParseHex(HexStr(rewardspk)) << OP_CHECKSIG));
|
||||
mtx.vout.push_back(CTxOut(mindeposit,CScript() << ParseHex(HexStr(rewardspk)) << OP_CHECKSIG));
|
||||
return(FinalizeCCTx(EVAL_REWARDS,mtx,mypk,txfee,opret));
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
std::string RewardsLock(uint64_t txfee,uint64_t amount)
|
||||
{
|
||||
CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret;
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
rewardspk = GetUnspendable(EVAL_REWARDS,0);
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if ( AddNormalinputs(mtx,mypk,amount+2*txfee,64) > 0 )
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_REWARDS,amount,rewardspk));
|
||||
// specify destination pubkey, funding txid
|
||||
//opret = ;//
|
||||
return(FinalizeCCTx(EVAL_REWARDS,mtx,mypk,txfee,opret));
|
||||
} else fprintf(stderr,"cant find rewards inputs\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
std::string RewardsUnlock(uint64_t txfee)
|
||||
{
|
||||
CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t reward,claim,inputs,CCchange=0;
|
||||
CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t reward,claim,inputs,CCchange=0; struct CCcontract_info *cp,C;
|
||||
cp = CCinit(&C,EVAL_REWARDS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
rewardspk = GetUnspendable(EVAL_REWARDS,0);
|
||||
rewardspk = GetUnspendable(cp,0);
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if ( (claim= AddRewardsInputs(mtx,mypk,(1LL << 30),1)) > 0 && (reward= RewardsCalc(claim,mtx.vin[0].prevout.hash)) > txfee )
|
||||
{
|
||||
@@ -204,9 +167,50 @@ std::string RewardsUnlock(uint64_t txfee)
|
||||
if ( CCchange != 0 )
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_REWARDS,CCchange,rewardspk));
|
||||
mtx.vout.push_back(CTxOut(claim+reward,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
||||
return(FinalizeCCTx(EVAL_REWARDS,mtx,mypk,txfee,opret));
|
||||
return(FinalizeCCTx(cp,mtx,mypk,txfee,opret));
|
||||
}
|
||||
} else fprintf(stderr,"cant find rewards inputs\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
// 0.834% every 60 days, min 100, capped at 0.834%
|
||||
|
||||
std::string RewardsFund(uint64_t txfee,uint64_t funds,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit)
|
||||
{
|
||||
CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; struct CCcontract_info *cp,C;
|
||||
cp = CCinit(&C,EVAL_REWARDS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
rewardspk = GetUnspendable(cp,0);
|
||||
if ( AddNormalinputs(mtx,mypk,funds+2*txfee,64) > 0 )
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_REWARDS,funds,rewardspk));
|
||||
mtx.vout.push_back(CTxOut(APR,CScript() << ParseHex(HexStr(rewardspk)) << OP_CHECKSIG));
|
||||
mtx.vout.push_back(CTxOut(minseconds,CScript() << ParseHex(HexStr(rewardspk)) << OP_CHECKSIG));
|
||||
mtx.vout.push_back(CTxOut(maxseconds,CScript() << ParseHex(HexStr(rewardspk)) << OP_CHECKSIG));
|
||||
mtx.vout.push_back(CTxOut(mindeposit,CScript() << ParseHex(HexStr(rewardspk)) << OP_CHECKSIG));
|
||||
return(FinalizeCCTx(cp,mtx,mypk,txfee,opret));
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
std::string RewardsLock(uint64_t txfee,uint64_t amount)
|
||||
{
|
||||
CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; struct CCcontract_info *cp,C;
|
||||
cp = CCinit(&C,EVAL_REWARDS);
|
||||
if ( txfee == 0 )
|
||||
txfee = 10000;
|
||||
rewardspk = GetUnspendable(cp,0);
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if ( AddNormalinputs(mtx,mypk,amount+2*txfee,64) > 0 )
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_REWARDS,amount,rewardspk));
|
||||
// specify destination pubkey, funding txid
|
||||
//opret = ;//
|
||||
return(FinalizeCCTx(cp,mtx,mypk,txfee,opret));
|
||||
} else fprintf(stderr,"cant find rewards inputs\n");
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user