|
|
@ -13,7 +13,7 @@ |
|
|
|
* * |
|
|
|
******************************************************************************/ |
|
|
|
|
|
|
|
#include "CCponzi.h" |
|
|
|
#include "CCfsm.h" |
|
|
|
#include "../txmempool.h" |
|
|
|
|
|
|
|
/*
|
|
|
@ -21,7 +21,7 @@ |
|
|
|
|
|
|
|
// start of consensus code
|
|
|
|
|
|
|
|
uint64_t IsPonzivout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) |
|
|
|
uint64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) |
|
|
|
{ |
|
|
|
char destaddr[64]; |
|
|
|
if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) |
|
|
@ -32,7 +32,7 @@ uint64_t IsPonzivout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
bool PonziExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) |
|
|
|
bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) |
|
|
|
{ |
|
|
|
static uint256 zerohash; |
|
|
|
CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; |
|
|
@ -50,8 +50,8 @@ bool PonziExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction |
|
|
|
{ |
|
|
|
//fprintf(stderr,"vini.%d check hash and vout\n",i);
|
|
|
|
if ( hashBlock == zerohash ) |
|
|
|
return eval->Invalid("cant ponzi from mempool"); |
|
|
|
if ( (assetoshis= IsPonzivout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) |
|
|
|
return eval->Invalid("cant FSM from mempool"); |
|
|
|
if ( (assetoshis= IsFSMvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) |
|
|
|
inputs += assetoshis; |
|
|
|
} |
|
|
|
} |
|
|
@ -59,7 +59,7 @@ bool PonziExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction |
|
|
|
for (i=0; i<numvouts; i++) |
|
|
|
{ |
|
|
|
//fprintf(stderr,"i.%d of numvouts.%d\n",i,numvouts);
|
|
|
|
if ( (assetoshis= IsPonzivout(cp,tx,i)) != 0 ) |
|
|
|
if ( (assetoshis= IsFSMvout(cp,tx,i)) != 0 ) |
|
|
|
outputs += assetoshis; |
|
|
|
} |
|
|
|
if ( inputs != outputs+COIN+txfee ) |
|
|
@ -70,7 +70,7 @@ bool PonziExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction |
|
|
|
else return(true); |
|
|
|
} |
|
|
|
|
|
|
|
bool PonziValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) |
|
|
|
bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) |
|
|
|
{ |
|
|
|
int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; |
|
|
|
numvins = tx.vin.size(); |
|
|
@ -85,30 +85,30 @@ bool PonziValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) |
|
|
|
{ |
|
|
|
if ( IsCCInput(tx.vin[0].scriptSig) == 0 ) |
|
|
|
{ |
|
|
|
fprintf(stderr,"ponziget invalid vini\n"); |
|
|
|
fprintf(stderr,"fsmget invalid vini\n"); |
|
|
|
return eval->Invalid("illegal normal vini"); |
|
|
|
} |
|
|
|
} |
|
|
|
//fprintf(stderr,"check amounts\n");
|
|
|
|
if ( PonziExactAmounts(cp,eval,tx,1,10000) == false ) |
|
|
|
if ( FSMExactAmounts(cp,eval,tx,1,10000) == false ) |
|
|
|
{ |
|
|
|
fprintf(stderr,"ponziget invalid amount\n"); |
|
|
|
fprintf(stderr,"fsmget invalid amount\n"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
preventCCvouts = 1; |
|
|
|
if ( IsPonzivout(cp,tx,0) != 0 ) |
|
|
|
if ( IsFSMvout(cp,tx,0) != 0 ) |
|
|
|
{ |
|
|
|
preventCCvouts++; |
|
|
|
i = 1; |
|
|
|
} else i = 0; |
|
|
|
if ( tx.vout[i].nValue != COIN ) |
|
|
|
return eval->Invalid("invalid ponzi output"); |
|
|
|
return eval->Invalid("invalid fsm output"); |
|
|
|
retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); |
|
|
|
if ( retval != 0 ) |
|
|
|
fprintf(stderr,"ponziget validated\n"); |
|
|
|
else fprintf(stderr,"ponziget invalid\n"); |
|
|
|
fprintf(stderr,"fsmget validated\n"); |
|
|
|
else fprintf(stderr,"fsmget invalid\n"); |
|
|
|
return(retval); |
|
|
|
} |
|
|
|
} |
|
|
@ -117,7 +117,7 @@ bool PonziValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) |
|
|
|
|
|
|
|
// helper functions for rpc calls in rpcwallet.cpp
|
|
|
|
|
|
|
|
uint64_t AddPonziInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs) |
|
|
|
uint64_t AddFSMInputs(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; |
|
|
@ -131,7 +131,7 @@ uint64_t AddPonziInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub |
|
|
|
continue; |
|
|
|
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) |
|
|
|
{ |
|
|
|
if ( (nValue= IsPonzivout(cp,vintx,(int32_t)it->first.index)) > 0 ) |
|
|
|
if ( (nValue= IsFSMvout(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())); |
|
|
@ -146,37 +146,42 @@ uint64_t AddPonziInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub |
|
|
|
return(totalinputs); |
|
|
|
} |
|
|
|
|
|
|
|
std::string PonziBuy(uint64_t txfee,uint64_t amount) |
|
|
|
std::string FSMlist(uint64_t txfee) |
|
|
|
{ |
|
|
|
CMutableTransaction mtx; CPubKey mypk,ponzipk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; |
|
|
|
cp = CCinit(&C,EVAL_PONZI); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
std::string FSMcreate(uint64_t txfee,std::string name,std::string states) |
|
|
|
{ |
|
|
|
CMutableTransaction mtx; CPubKey mypk,fsmpk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; |
|
|
|
cp = CCinit(&C,EVAL_FSM); |
|
|
|
if ( txfee == 0 ) |
|
|
|
txfee = 10000; |
|
|
|
ponzipk = GetUnspendable(cp,0); |
|
|
|
fsmpk = GetUnspendable(cp,0); |
|
|
|
mypk = pubkey2pk(Mypubkey()); |
|
|
|
if ( (inputs= AddPonziInputs(cp,mtx,ponzipk,nValue+txfee,60)) > 0 ) |
|
|
|
if ( (inputs= AddFSMInputs(cp,mtx,fsmpk,nValue+txfee,60)) > 0 ) |
|
|
|
{ |
|
|
|
if ( inputs > nValue ) |
|
|
|
CCchange = (inputs - nValue - txfee); |
|
|
|
if ( CCchange != 0 ) |
|
|
|
mtx.vout.push_back(MakeCC1vout(EVAL_PONZI,CCchange,ponzipk)); |
|
|
|
mtx.vout.push_back(MakeCC1vout(EVAL_FSM,CCchange,fsmpk)); |
|
|
|
mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); |
|
|
|
return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); |
|
|
|
} else fprintf(stderr,"cant find ponzi inputs\n"); |
|
|
|
} else fprintf(stderr,"cant find fsm inputs\n"); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
std::string PonziClaim(uint64_t txfee) |
|
|
|
std::string FSMinfo(uint64_t txfee,uint256 fsmtxid) |
|
|
|
{ |
|
|
|
CMutableTransaction mtx; CPubKey mypk,ponzipk; uint64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; |
|
|
|
cp = CCinit(&C,EVAL_PONZI); |
|
|
|
CMutableTransaction mtx; CPubKey mypk,fsmpk; uint64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; |
|
|
|
cp = CCinit(&C,EVAL_FSM); |
|
|
|
if ( txfee == 0 ) |
|
|
|
txfee = 10000; |
|
|
|
mypk = pubkey2pk(Mypubkey()); |
|
|
|
ponzipk = GetUnspendable(cp,0); |
|
|
|
fsmpk = GetUnspendable(cp,0); |
|
|
|
if ( AddNormalinputs(mtx,mypk,txfee,64) > 0 ) |
|
|
|
{ |
|
|
|
mtx.vout.push_back(MakeCC1vout(EVAL_PONZI,funds,ponzipk)); |
|
|
|
mtx.vout.push_back(MakeCC1vout(EVAL_FSM,funds,fsmpk)); |
|
|
|
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); |
|
|
|
} |
|
|
|
return(0); |