Merge pull request #39 from jl777/jl777

Jl777
This commit is contained in:
blackjok3rtt
2019-03-22 15:57:39 +08:00
committed by GitHub

View File

@@ -240,7 +240,7 @@ UniValue payments_rawtxresult(UniValue &result,std::string rawtx,int32_t broadca
cJSON *payments_reparse(int32_t *nump,char *jsonstr)
{
cJSON *params; char *newstr; int32_t i,j;
cJSON *params=0; char *newstr; int32_t i,j;
*nump = 0;
if ( jsonstr != 0 )
{
@@ -263,11 +263,11 @@ cJSON *payments_reparse(int32_t *nump,char *jsonstr)
}
newstr[j] = 0;
params = cJSON_Parse(newstr);
if ( 0 && params != 0 )
if ( 1 && params != 0 )
printf("new.(%s) -> %s\n",newstr,jprint(params,0));
free(newstr);
*nump = cJSON_GetArraySize(params);
} else params = 0;
}
return(params);
}
@@ -295,6 +295,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr)
int32_t latestheight,nextheight = komodo_nextheight();
CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); uint256 createtxid,hashBlock;
CTransaction tx,txO; CPubKey mypk,txidpk,Paymentspk; int32_t i,n,numoprets=0,lockedblocks,minrelease,totalallocations,checkallocations=0,allocation; int64_t inputsum,amount,CCchange=0; CTxOut vout; CScript onlyopret; char txidaddr[64],destaddr[64]; std::vector<uint256> txidoprets; std::string rawtx;
fprintf(stderr,"jsonstr.(%s)\n",jsonstr);
cJSON *params = payments_reparse(&n,jsonstr);
mypk = pubkey2pk(Mypubkey());
Paymentspk = GetUnspendable(cp,0);
@@ -313,12 +314,12 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr)
return(result);
}
latestheight = (nextheight - lockedblocks - 1);
if ( amount < minrelease )
if ( amount < minrelease*COIN )
{
result.push_back(Pair("result","error"));
result.push_back(Pair("error","amount too smal"));
result.push_back(Pair("amount",ValueFromAmount(amount)));
result.push_back(Pair("minrelease",ValueFromAmount(minrelease)));
result.push_back(Pair("minrelease",ValueFromAmount(minrelease*COIN)));
return(result);
}
txidpk = CCtxidaddr(txidaddr,createtxid);
@@ -375,10 +376,12 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr)
mtx.vout[i+1].nValue *= amount;
mtx.vout[i+1].nValue /= totalallocations;
}
fprintf(stderr,"addinputs %.8f\n",(double)amount/COIN);
if ( (inputsum= AddPaymentsInputs(cp,mtx,txidpk,amount+PAYMENTS_TXFEE,60,createtxid,latestheight)) >= amount )
{
if ( (CCchange= (inputsum - amount)) >= PAYMENTS_TXFEE )
mtx.vout[0].nValue = CCchange;
mtx.vout.push_back(CTxOut(0,CScript() << ParseHex(HexStr(txidpk)) << OP_CHECKSIG));
GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk);
CCaddr1of2set(cp,Paymentspk,txidpk,cp->CCpriv,destaddr);
rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,onlyopret);