Merge pull request #45 from jl777/dev

update dev
This commit is contained in:
ca333
2018-08-04 14:00:07 +02:00
committed by GitHub
26 changed files with 1192 additions and 329 deletions

View File

@@ -266,7 +266,7 @@ libbitcoin_server_a_SOURCES = \
cc/rewards.cpp \ cc/rewards.cpp \
cc/dice.cpp \ cc/dice.cpp \
cc/lotto.cpp \ cc/lotto.cpp \
cc/ponzi.cpp \ cc/fsm.cpp \
cc/auction.cpp \ cc/auction.cpp \
cc/betprotocol.cpp \ cc/betprotocol.cpp \
chain.cpp \ chain.cpp \

View File

@@ -305,6 +305,8 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p
std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal) std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal)
{ {
CMutableTransaction mtx; CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; CMutableTransaction mtx; CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C;
fprintf(stderr,"asset swaps disabled\n");
return(0);
if ( askamount < 0 || pricetotal < 0 ) if ( askamount < 0 || pricetotal < 0 )
{ {
fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount); fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount);
@@ -429,6 +431,12 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt
fprintf(stderr,"negative fillunits %lld\n",(long long)fillunits); fprintf(stderr,"negative fillunits %lld\n",(long long)fillunits);
return(0); return(0);
} }
if ( assetid2 != zeroid )
{
fprintf(stderr,"asset swaps disabled\n");
return(0);
}
cp = CCinit(&C,EVAL_ASSETS); cp = CCinit(&C,EVAL_ASSETS);
if ( txfee == 0 ) if ( txfee == 0 )
txfee = 10000; txfee = 10000;
@@ -461,7 +469,9 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt
CCchange = (inputs - paid_nValue); CCchange = (inputs - paid_nValue);
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,orig_assetoshis - received_assetoshis,GetUnspendable(cp,0))); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,orig_assetoshis - received_assetoshis,GetUnspendable(cp,0)));
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,received_assetoshis,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,received_assetoshis,mypk));
mtx.vout.push_back(CTxOut(paid_nValue,CScript() << origpubkey << OP_CHECKSIG)); if ( assetid2 != zeroid )
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,paid_nValue,origpubkey));
else mtx.vout.push_back(CTxOut(paid_nValue,CScript() << origpubkey << OP_CHECKSIG));
if ( CCchange != 0 ) if ( CCchange != 0 )
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk));
return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet(assetid2!=zeroid?'E':'S',assetid,assetid2,remaining_nValue,origpubkey))); return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet(assetid2!=zeroid?'E':'S',assetid,assetid2,remaining_nValue,origpubkey)));

View File

@@ -20,7 +20,7 @@
#include "CCdice.h" #include "CCdice.h"
#include "CCauction.h" #include "CCauction.h"
#include "CClotto.h" #include "CClotto.h"
#include "CCponzi.h" #include "CCfsm.h"
/* /*
CCcustom has most of the functions that need to be extended to create a new CC contract. CCcustom has most of the functions that need to be extended to create a new CC contract.
@@ -106,13 +106,13 @@ uint8_t LottoCCpriv[32] = { 0xb4, 0xac, 0xc2, 0xd9, 0x67, 0x34, 0xd7, 0x58, 0x80
#undef FUNCNAME #undef FUNCNAME
#undef EVALCODE #undef EVALCODE
// Ponzi // Finite State Machine
#define FUNCNAME IsPonziInput #define FUNCNAME IsFSMInput
#define EVALCODE EVAL_PONZI #define EVALCODE EVAL_FSM
const char *PonziCCaddr = "RUKTbLBeKgHkm3Ss4hKZP3ikuLW1xx7B2x"; const char *FSMCCaddr = "RUKTbLBeKgHkm3Ss4hKZP3ikuLW1xx7B2x";
const char *PonziNormaladdr = "RWSHRbxnJYLvDjpcQ2i8MekgP6h2ctTKaj"; const char *FSMNormaladdr = "RWSHRbxnJYLvDjpcQ2i8MekgP6h2ctTKaj";
char PonziCChexstr[67] = { "039b52d294b413b07f3643c1a28c5467901a76562d8b39a785910ae0a0f3043810" }; char FSMCChexstr[67] = { "039b52d294b413b07f3643c1a28c5467901a76562d8b39a785910ae0a0f3043810" };
uint8_t PonziCCpriv[32] = { 0x11, 0xe1, 0xea, 0x3e, 0xdb, 0x36, 0xf0, 0xa8, 0xc6, 0x34, 0xe1, 0x21, 0xb8, 0x02, 0xb9, 0x4b, 0x12, 0x37, 0x8f, 0xa0, 0x86, 0x23, 0x50, 0xb2, 0x5f, 0xe4, 0xe7, 0x36, 0x0f, 0xda, 0xae, 0xfc }; uint8_t FSMCCpriv[32] = { 0x11, 0xe1, 0xea, 0x3e, 0xdb, 0x36, 0xf0, 0xa8, 0xc6, 0x34, 0xe1, 0x21, 0xb8, 0x02, 0xb9, 0x4b, 0x12, 0x37, 0x8f, 0xa0, 0x86, 0x23, 0x50, 0xb2, 0x5f, 0xe4, 0xe7, 0x36, 0x0f, 0xda, 0xae, 0xfc };
#include "CCcustom.inc" #include "CCcustom.inc"
#undef FUNCNAME #undef FUNCNAME
#undef EVALCODE #undef EVALCODE
@@ -173,13 +173,13 @@ struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode)
cp->validate = LottoValidate; cp->validate = LottoValidate;
cp->ismyvin = IsLottoInput; cp->ismyvin = IsLottoInput;
break; break;
case EVAL_PONZI: case EVAL_FSM:
strcpy(cp->unspendableCCaddr,PonziCCaddr); strcpy(cp->unspendableCCaddr,FSMCCaddr);
strcpy(cp->normaladdr,PonziNormaladdr); strcpy(cp->normaladdr,FSMNormaladdr);
strcpy(cp->CChexstr,PonziCChexstr); strcpy(cp->CChexstr,FSMCChexstr);
memcpy(cp->CCpriv,PonziCCpriv,32); memcpy(cp->CCpriv,FSMCCpriv,32);
cp->validate = PonziValidate; cp->validate = FSMValidate;
cp->ismyvin = IsPonziInput; cp->ismyvin = IsFSMInput;
break; break;
case EVAL_AUCTION: case EVAL_AUCTION:
strcpy(cp->unspendableCCaddr,AuctionCCaddr); strcpy(cp->unspendableCCaddr,AuctionCCaddr);

View File

@@ -24,7 +24,9 @@
bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx);
std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds);
std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t forfeitblocks); std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout);
double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid);
std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks);
std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount);
UniValue DiceInfo(uint256 diceid); UniValue DiceInfo(uint256 diceid);
UniValue DiceList(); UniValue DiceList();

View File

@@ -26,5 +26,6 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
// CCcustom // CCcustom
std::string FaucetFund(uint64_t txfee,uint64_t funds); std::string FaucetFund(uint64_t txfee,uint64_t funds);
std::string FaucetGet(uint64_t txfee); std::string FaucetGet(uint64_t txfee);
UniValue FaucetInfo();
#endif #endif

View File

@@ -14,16 +14,17 @@
******************************************************************************/ ******************************************************************************/
#ifndef CC_PONZI_H #ifndef CC_FSM_H
#define CC_PONZI_H #define CC_FSM_H
#include "CCinclude.h" #include "CCinclude.h"
#define EVAL_PONZI 0xe7 #define EVAL_FSM 0xe7
bool PonziValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx);
std::string PonziBuy(uint64_t txfee,uint64_t amount); std::string FSMList();
std::string PonziClaim(uint64_t txfee); std::string FSMInfo(uint256 fsmtxid);
std::string FSMCreate(uint64_t txfee,std::string name,std::string states);
#endif #endif

View File

@@ -30,6 +30,8 @@
#define SMALLVAL 0.000000000000001 #define SMALLVAL 0.000000000000001
union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; };
typedef union _bits256 bits256;
struct CCcontract_info struct CCcontract_info
{ {
@@ -47,7 +49,14 @@ extern CWallet* pwalletMain;
#endif #endif
bool GetAddressUnspent(uint160 addressHash, int type,std::vector<std::pair<CAddressUnspentKey,CAddressUnspentValue> > &unspentOutputs); bool GetAddressUnspent(uint160 addressHash, int type,std::vector<std::pair<CAddressUnspentKey,CAddressUnspentValue> > &unspentOutputs);
static uint256 zeroid; static const uint256 zeroid;
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock);
int32_t is_hexstr(char *str,int32_t n);
bool myAddtomempool(CTransaction &tx);
//uint64_t myGettxout(uint256 hash,int32_t n);
bool myIsutxo_spentinmempool(uint256 txid,int32_t vout);
int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout);
bool mySendrawtransaction(std::string res);
// CCcustom // CCcustom
CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv);
@@ -70,7 +79,7 @@ bool PreventCC(Eval* eval,const CTransaction &tx,int32_t preventCCvins,int32_t n
bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey);
std::vector<uint8_t> Mypubkey(); std::vector<uint8_t> Mypubkey();
bool Myprivkey(uint8_t myprivkey[]); bool Myprivkey(uint8_t myprivkey[]);
int64_t CCduration(uint256 txid); int64_t CCduration(int32_t &numblocks,uint256 txid);
// CCtx // CCtx
std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret); std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret);
@@ -79,4 +88,10 @@ void SetCCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex
uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,int32_t maxinputs); uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,int32_t maxinputs);
uint64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout); uint64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout);
// curve25519 and sha256
bits256 curve25519_shared(bits256 privkey,bits256 otherpub);
bits256 curve25519_basepoint9();
bits256 curve25519(bits256 mysecret,bits256 basepoint);
void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len);
#endif #endif

View File

@@ -52,7 +52,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
if ( (n= mtx.vin.size()) > 64 ) if ( (n= mtx.vin.size()) > 64 )
{ {
fprintf(stderr,"FinalizeCCTx: %d is too many vins\n",n); fprintf(stderr,"FinalizeCCTx: %d is too many vins\n",n);
return(0); return("0");
} }
Myprivkey(myprivkey); Myprivkey(myprivkey);
unspendablepk = GetUnspendable(cp,unspendablepriv); unspendablepk = GetUnspendable(cp,unspendablepriv);
@@ -82,7 +82,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
} else fprintf(stderr,"FinalizeCCTx couldnt find %s\n",mtx.vin[i].prevout.hash.ToString().c_str()); } else fprintf(stderr,"FinalizeCCTx couldnt find %s\n",mtx.vin[i].prevout.hash.ToString().c_str());
} }
nmask = (1LL << n) - 1; nmask = (1LL << n) - 1;
if ( (mask & nmask) != (CCmask & nmask) ) if ( 0 && (mask & nmask) != (CCmask & nmask) )
fprintf(stderr,"mask.%llx vs CCmask.%llx %llx %llx %llx\n",(long long)(mask & nmask),(long long)(CCmask & nmask),(long long)mask,(long long)CCmask,(long long)nmask); fprintf(stderr,"mask.%llx vs CCmask.%llx %llx %llx %llx\n",(long long)(mask & nmask),(long long)(CCmask & nmask),(long long)mask,(long long)CCmask,(long long)nmask);
if ( totalinputs >= totaloutputs+2*txfee ) if ( totalinputs >= totaloutputs+2*txfee )
{ {
@@ -147,7 +147,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
std::string strHex = EncodeHexTx(mtx); std::string strHex = EncodeHexTx(mtx);
if ( strHex.size() > 0 ) if ( strHex.size() > 0 )
return(strHex); return(strHex);
else return(0); else return("0");
} }
void SetCCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs,char *coinaddr) void SetCCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs,char *coinaddr)
@@ -203,7 +203,7 @@ uint64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout)
uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,int32_t maxinputs) uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,int32_t maxinputs)
{ {
int32_t vout,j,n = 0; uint64_t nValue,totalinputs = 0; uint256 txid; std::vector<COutput> vecOutputs; int32_t vout,j,n = 0; uint64_t nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector<COutput> vecOutputs; CTransaction tx;
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
const CKeyStore& keystore = *pwalletMain; const CKeyStore& keystore = *pwalletMain;
assert(pwalletMain != NULL); assert(pwalletMain != NULL);
@@ -220,12 +220,15 @@ uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,in
break; break;
if ( j != mtx.vin.size() ) if ( j != mtx.vin.size() )
continue; continue;
mtx.vin.push_back(CTxIn(txid,vout,CScript())); if ( myIsutxo_spentinmempool(txid,vout) == 0 )
nValue = out.tx->vout[out.i].nValue; {
totalinputs += nValue; mtx.vin.push_back(CTxIn(txid,vout,CScript()));
n++; nValue = out.tx->vout[out.i].nValue;
if ( totalinputs >= total || n >= maxinputs ) totalinputs += nValue;
break; n++;
if ( totalinputs >= total || n >= maxinputs )
break;
}
} }
} }
if ( totalinputs >= total ) if ( totalinputs >= total )

View File

@@ -193,7 +193,10 @@ bool PreventCC(Eval* eval,const CTransaction &tx,int32_t preventCCvins,int32_t n
for (i=preventCCvouts; i<numvouts; i++) for (i=preventCCvouts; i<numvouts; i++)
{ {
if ( tx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 ) if ( tx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 )
{
fprintf(stderr,"vout.%d is CC\n",i);
return eval->Invalid("invalid CC vout"); return eval->Invalid("invalid CC vout");
}
} }
} }
return(true); return(true);
@@ -252,26 +255,31 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv)
bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector<uint8_t> paramsNull,const CTransaction &ctx, unsigned int nIn) bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector<uint8_t> paramsNull,const CTransaction &ctx, unsigned int nIn)
{ {
CTransaction createTx; uint256 txid,assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; uint64_t amount; std::vector<uint8_t> origpubkey; CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; uint64_t amount; std::vector<uint8_t> origpubkey;
txid = ctx.GetHash(); // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example
if ( txid == cp->prevtxid ) //txid = ctx.GetHash();
return(true); //if ( txid == cp->prevtxid )
// return(true);
//fprintf(stderr,"process CC %02x\n",cp->evalcode);
if ( paramsNull.size() != 0 ) // Don't expect params if ( paramsNull.size() != 0 ) // Don't expect params
return eval->Invalid("Cannot have params"); return eval->Invalid("Cannot have params");
else if ( ctx.vout.size() == 0 ) else if ( ctx.vout.size() == 0 )
return eval->Invalid("no-vouts"); return eval->Invalid("no-vouts");
else if ( (*cp->validate)(cp,eval,ctx) != 0 ) else if ( (*cp->validate)(cp,eval,ctx) != 0 )
{ {
cp->prevtxid = txid; //fprintf(stderr,"done CC %02x\n",cp->evalcode);
//cp->prevtxid = txid;
return(true); return(true);
} }
//fprintf(stderr,"invalid CC %02x\n",cp->evalcode);
return(false); return(false);
} }
int64_t CCduration(uint256 txid) int64_t CCduration(int32_t &numblocks,uint256 txid)
{ {
CTransaction tx; uint256 hashBlock; uint32_t txtime=0; char str[65]; CBlockIndex *pindex; int64_t duration = 0; CTransaction tx; uint256 hashBlock; uint32_t txheight,txtime=0; char str[65]; CBlockIndex *pindex; int64_t duration = 0;
if ( GetTransaction(txid,tx,hashBlock,false) == 0 ) numblocks = 0;
if ( myGetTransaction(txid,tx,hashBlock) == 0 )
{ {
fprintf(stderr,"CCduration cant find duration txid %s\n",uint256_str(str,txid)); fprintf(stderr,"CCduration cant find duration txid %s\n",uint256_str(str,txid));
return(0); return(0);
@@ -281,18 +289,19 @@ int64_t CCduration(uint256 txid)
fprintf(stderr,"CCduration no hashBlock for txid %s\n",uint256_str(str,txid)); fprintf(stderr,"CCduration no hashBlock for txid %s\n",uint256_str(str,txid));
return(0); return(0);
} }
else if ( (pindex= mapBlockIndex[hashBlock]) == 0 || (txtime= pindex->nTime) == 0 ) else if ( (pindex= mapBlockIndex[hashBlock]) == 0 || (txtime= pindex->nTime) == 0 || (txheight= pindex->nHeight) <= 0 )
{ {
fprintf(stderr,"CCduration no txtime %u %p for txid %s\n",txtime,pindex,uint256_str(str,txid)); fprintf(stderr,"CCduration no txtime %u or txheight.%d %p for txid %s\n",txtime,txheight,pindex,uint256_str(str,txid));
return(0); return(0);
} }
else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime ) else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->nHeight <= txheight )
{ {
fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid)); fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight);
return(0); return(0);
} }
numblocks = (pindex->nHeight - txheight);
duration = (pindex->nTime - txtime); duration = (pindex->nTime - txtime);
fprintf(stderr,"duration %d (%u - %u)\n",(int32_t)duration,(uint32_t)pindex->nTime,txtime); fprintf(stderr,"duration %d (%u - %u) numblocks %d (%d - %d)\n",(int32_t)duration,(uint32_t)pindex->nTime,txtime,numblocks,pindex->nHeight,txheight);
return(duration); return(duration);
} }

View File

@@ -250,21 +250,29 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
} }
fprintf(stderr,"fillbuy validated\n"); fprintf(stderr,"fillbuy validated\n");
break; break;
case 'e': // selloffer
break; // disable swaps
case 's': // selloffer case 's': // selloffer
case 'e': // exchange
//vin.0: normal input //vin.0: normal input
//vin.1+: valid CC output for sale //vin.1+: valid CC output for sale
//vout.0: vin.1 assetoshis output to CC to unspendable //vout.0: vin.1 assetoshis output to CC to unspendable
//vout.1: normal output for change (if any) //vout.1: CC output for change (if any)
//vout.2: normal output for change (if any)
//'s'.vout.n-1: opreturn [EVAL_ASSETS] ['s'] [assetid] [amount of native coin required] [origpubkey] //'s'.vout.n-1: opreturn [EVAL_ASSETS] ['s'] [assetid] [amount of native coin required] [origpubkey]
//'e'.vout.n-1: opreturn [EVAL_ASSETS] ['e'] [assetid] [assetid2] [amount of asset2 required] [origpubkey] //'e'.vout.n-1: opreturn [EVAL_ASSETS] ['e'] [assetid] [assetid2] [amount of asset2 required] [origpubkey]
preventCCvouts = 1;
if ( remaining_price == 0 ) if ( remaining_price == 0 )
return eval->Invalid("illegal null remaining_price for selloffer"); return eval->Invalid("illegal null remaining_price for selloffer");
else if ( ConstrainVout(tx.vout[0],1,(char *)cp->unspendableCCaddr,inputs) == 0 ) if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() != 0 )
{
preventCCvouts++;
if ( ConstrainVout(tx.vout[0],1,(char *)cp->unspendableCCaddr,0) == 0 )
return eval->Invalid("mismatched vout0 AssetsCCaddr for selloffer");
else if ( tx.vout[0].nValue+tx.vout[1].nValue != inputs )
return eval->Invalid("mismatched vout0+vout1 total for selloffer");
} else if ( ConstrainVout(tx.vout[0],1,(char *)cp->unspendableCCaddr,inputs) == 0 )
return eval->Invalid("mismatched vout0 AssetsCCaddr for selloffer"); return eval->Invalid("mismatched vout0 AssetsCCaddr for selloffer");
//fprintf(stderr,"remaining.%d for sell\n",(int32_t)remaining_price); //fprintf(stderr,"remaining.%d for sell\n",(int32_t)remaining_price);
preventCCvouts = 1;
break; break;
case 'x': // cancel case 'x': // cancel
@@ -315,6 +323,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
fprintf(stderr,"fill validated\n"); fprintf(stderr,"fill validated\n");
break; break;
case 'E': // fillexchange case 'E': // fillexchange
break; // disable asset swaps
//vin.0: normal input //vin.0: normal input
//vin.1: unspendable.(vout.0 assetoshis from selloffer) sellTx.vout[0] //vin.1: unspendable.(vout.0 assetoshis from selloffer) sellTx.vout[0]
//vin.2+: valid CC assetid2 output that satisfies exchange (*tx.vin[2])->nValue //vin.2+: valid CC assetid2 output that satisfies exchange (*tx.vin[2])->nValue
@@ -341,7 +350,10 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
if ( ConstrainVout(tx.vout[2],1,CCaddr,0) == 0 ) if ( ConstrainVout(tx.vout[2],1,CCaddr,0) == 0 )
return eval->Invalid("vout2 doesnt go to origpubkey fillex"); return eval->Invalid("vout2 doesnt go to origpubkey fillex");
else if ( inputs != tx.vout[2].nValue+tx.vout[3].nValue ) else if ( inputs != tx.vout[2].nValue+tx.vout[3].nValue )
{
fprintf(stderr,"inputs %.8f != %.8f + %.8f\n",(double)inputs/COIN,(double)tx.vout[2].nValue/COIN,(double)tx.vout[3].nValue/COIN);
return eval->Invalid("asset inputs doesnt match vout2+3 fillex"); return eval->Invalid("asset inputs doesnt match vout2+3 fillex");
}
} }
else if ( ConstrainVout(tx.vout[2],1,CCaddr,inputs) == 0 ) else if ( ConstrainVout(tx.vout[2],1,CCaddr,inputs) == 0 )
return eval->Invalid("vout2 doesnt match inputs fillex"); return eval->Invalid("vout2 doesnt match inputs fillex");

View File

@@ -127,6 +127,8 @@ uint64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP
{ {
txid = it->first.txhash; txid = it->first.txhash;
// prevent dup // prevent dup
if ( it->second.satoshis < 1000000 )
continue;
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) if ( GetTransaction(txid,vintx,hashBlock,false) != 0 )
{ {
if ( (nValue= IsAuctionvout(cp,vintx,(int32_t)it->first.index)) > 0 ) if ( (nValue= IsAuctionvout(cp,vintx,(int32_t)it->first.index)) > 0 )

File diff suppressed because it is too large Load Diff

View File

@@ -30,12 +30,15 @@
Eval* EVAL_TEST = 0; Eval* EVAL_TEST = 0;
struct CCcontract_info CCinfos[0x100]; struct CCcontract_info CCinfos[0x100];
extern pthread_mutex_t KOMODO_CC_mutex;
bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn)
{ {
EvalRef eval; EvalRef eval;
pthread_mutex_lock(&KOMODO_CC_mutex);
bool out = eval->Dispatch(cond, tx, nIn); bool out = eval->Dispatch(cond, tx, nIn);
//fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); pthread_mutex_unlock(&KOMODO_CC_mutex);
//fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid());
assert(eval->state.IsValid() == out); assert(eval->state.IsValid() == out);
if (eval->state.IsValid()) return true; if (eval->state.IsValid()) return true;
@@ -95,7 +98,6 @@ bool Eval::GetSpendsConfirmed(uint256 hash, std::vector<CTransaction> &spends) c
bool Eval::GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const bool Eval::GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const
{ {
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock);
// there is a LOCK(cs_main) in the normal GetTransaction(), which leads to deadlocks // there is a LOCK(cs_main) in the normal GetTransaction(), which leads to deadlocks
//bool fAllowSlow = false; // Don't allow slow //bool fAllowSlow = false; // Don't allow slow
//return GetTransaction(hash, txOut, hashBlock, fAllowSlow); //return GetTransaction(hash, txOut, hashBlock, fAllowSlow);

View File

@@ -44,7 +44,7 @@
EVAL(EVAL_FAUCET, 0xe4) \ EVAL(EVAL_FAUCET, 0xe4) \
EVAL(EVAL_REWARDS, 0xe5) \ EVAL(EVAL_REWARDS, 0xe5) \
EVAL(EVAL_DICE, 0xe6) \ EVAL(EVAL_DICE, 0xe6) \
EVAL(EVAL_PONZI, 0xe7) \ EVAL(EVAL_FSM, 0xe7) \
EVAL(EVAL_AUCTION, 0xe8) \ EVAL(EVAL_AUCTION, 0xe8) \
EVAL(EVAL_LOTTO, 0xe9) EVAL(EVAL_LOTTO, 0xe9)

View File

@@ -136,7 +136,7 @@ uint64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPu
// prevent dup // prevent dup
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) if ( GetTransaction(txid,vintx,hashBlock,false) != 0 )
{ {
if ( (nValue= IsFaucetvout(cp,vintx,(int32_t)it->first.index)) > 0 ) if ( (nValue= IsFaucetvout(cp,vintx,(int32_t)it->first.index)) > 1000000 )
{ {
if ( total != 0 && maxinputs != 0 ) if ( total != 0 && maxinputs != 0 )
mtx.vin.push_back(CTxIn(txid,(int32_t)it->first.index,CScript())); mtx.vin.push_back(CTxIn(txid,(int32_t)it->first.index,CScript()));
@@ -187,4 +187,17 @@ std::string FaucetFund(uint64_t txfee,uint64_t funds)
return(0); return(0);
} }
UniValue FaucetInfo()
{
UniValue result(UniValue::VOBJ); char numstr[64];
CMutableTransaction mtx; CPubKey faucetpk; struct CCcontract_info *cp,C; uint64_t funding;
result.push_back(Pair("result","success"));
result.push_back(Pair("name","Faucet"));
cp = CCinit(&C,EVAL_FAUCET);
faucetpk = GetUnspendable(cp,0);
funding = AddFaucetInputs(cp,mtx,faucetpk,0,0);
sprintf(numstr,"%.8f",(double)funding/COIN);
result.push_back(Pair("funding",numstr));
return(result);
}

View File

@@ -13,7 +13,7 @@
* * * *
******************************************************************************/ ******************************************************************************/
#include "CCponzi.h" #include "CCfsm.h"
#include "../txmempool.h" #include "../txmempool.h"
/* /*
@@ -21,7 +21,7 @@
// start of consensus code // 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]; char destaddr[64];
if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) 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); 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; static uint256 zerohash;
CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; 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); //fprintf(stderr,"vini.%d check hash and vout\n",i);
if ( hashBlock == zerohash ) if ( hashBlock == zerohash )
return eval->Invalid("cant ponzi from mempool"); return eval->Invalid("cant FSM from mempool");
if ( (assetoshis= IsPonzivout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) if ( (assetoshis= IsFSMvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 )
inputs += assetoshis; inputs += assetoshis;
} }
} }
@@ -59,7 +59,7 @@ bool PonziExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction
for (i=0; i<numvouts; i++) for (i=0; i<numvouts; i++)
{ {
//fprintf(stderr,"i.%d of numvouts.%d\n",i,numvouts); //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; outputs += assetoshis;
} }
if ( inputs != outputs+COIN+txfee ) if ( inputs != outputs+COIN+txfee )
@@ -70,7 +70,7 @@ bool PonziExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction
else return(true); 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; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval;
numvins = tx.vin.size(); 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 ) 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"); return eval->Invalid("illegal normal vini");
} }
} }
//fprintf(stderr,"check amounts\n"); //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; return false;
} }
else else
{ {
preventCCvouts = 1; preventCCvouts = 1;
if ( IsPonzivout(cp,tx,0) != 0 ) if ( IsFSMvout(cp,tx,0) != 0 )
{ {
preventCCvouts++; preventCCvouts++;
i = 1; i = 1;
} else i = 0; } else i = 0;
if ( tx.vout[i].nValue != COIN ) 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); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts);
if ( retval != 0 ) if ( retval != 0 )
fprintf(stderr,"ponziget validated\n"); fprintf(stderr,"fsmget validated\n");
else fprintf(stderr,"ponziget invalid\n"); else fprintf(stderr,"fsmget invalid\n");
return(retval); 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 // 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; 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; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
@@ -127,9 +127,11 @@ uint64_t AddPonziInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub
{ {
txid = it->first.txhash; txid = it->first.txhash;
// prevent dup // prevent dup
if ( it->second.satoshis < 1000000 )
continue;
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) 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 ) if ( total != 0 && maxinputs != 0 )
mtx.vin.push_back(CTxIn(txid,(int32_t)it->first.index,CScript())); mtx.vin.push_back(CTxIn(txid,(int32_t)it->first.index,CScript()));
@@ -144,39 +146,37 @@ uint64_t AddPonziInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub
return(totalinputs); return(totalinputs);
} }
std::string PonziBuy(uint64_t txfee,uint64_t amount) std::string FSMList()
{ {
CMutableTransaction mtx; CPubKey mypk,ponzipk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; return(0);
cp = CCinit(&C,EVAL_PONZI); }
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 ) if ( txfee == 0 )
txfee = 10000; txfee = 10000;
ponzipk = GetUnspendable(cp,0); fsmpk = GetUnspendable(cp,0);
mypk = pubkey2pk(Mypubkey()); 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 ) if ( inputs > nValue )
CCchange = (inputs - nValue - txfee); CCchange = (inputs - nValue - txfee);
if ( CCchange != 0 ) 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)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); 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); return(0);
} }
std::string PonziClaim(uint64_t txfee) std::string FSMInfo(uint256 fsmtxid)
{ {
CMutableTransaction mtx; CPubKey mypk,ponzipk; uint64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; CMutableTransaction mtx; CPubKey mypk,fsmpk; uint64_t funds = 0; CScript opret; struct CCcontract_info *cp,C;
cp = CCinit(&C,EVAL_PONZI); cp = CCinit(&C,EVAL_FSM);
if ( txfee == 0 )
txfee = 10000;
mypk = pubkey2pk(Mypubkey()); 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));
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret));
}
return(0); return(0);
} }

View File

@@ -127,6 +127,8 @@ uint64_t AddLottoInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub
{ {
txid = it->first.txhash; txid = it->first.txhash;
// prevent dup // prevent dup
if ( it->second.satoshis < 1000000 )
continue;
if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) if ( GetTransaction(txid,vintx,hashBlock,false) != 0 )
{ {
if ( (nValue= IsLottovout(cp,vintx,(int32_t)it->first.index)) > 0 ) if ( (nValue= IsLottovout(cp,vintx,(int32_t)it->first.index)) > 0 )

View File

@@ -68,10 +68,11 @@
uint64_t RewardsCalc(uint64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit) uint64_t RewardsCalc(uint64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit)
{ {
uint64_t duration,reward = 0; int32_t numblocks; uint64_t duration,reward = 0;
fprintf(stderr,"minseconds %llu maxseconds %llu\n",(long long)minseconds,(long long)maxseconds); fprintf(stderr,"minseconds %llu maxseconds %llu\n",(long long)minseconds,(long long)maxseconds);
if ( (duration= CCduration(txid)) < minseconds ) if ( (duration= CCduration(numblocks,txid)) < minseconds )
{ {
fprintf(stderr,"duration %llu < minseconds %llu\n",(long long)duration,(long long)minseconds);
return(0); return(0);
//duration = (uint32_t)time(NULL) - (1532713903 - 3600 * 24); //duration = (uint32_t)time(NULL) - (1532713903 - 3600 * 24);
} else if ( duration > maxseconds ) } else if ( duration > maxseconds )
@@ -273,6 +274,8 @@ uint64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontr
{ {
txid = it->first.txhash; txid = it->first.txhash;
vout = (int32_t)it->first.index; vout = (int32_t)it->first.index;
if ( it->second.satoshis < 1000000 )
continue;
fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN);
for (j=0; j<mtx.vin.size(); j++) for (j=0; j<mtx.vin.size(); j++)
if ( txid == mtx.vin[j].prevout.hash && vout == mtx.vin[j].prevout.n ) if ( txid == mtx.vin[j].prevout.hash && vout == mtx.vin[j].prevout.n )
@@ -355,7 +358,7 @@ bool RewardsPlanExists(struct CCcontract_info *cp,uint64_t refsbits,CPubKey rewa
UniValue RewardsInfo(uint256 rewardsid) UniValue RewardsInfo(uint256 rewardsid)
{ {
UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t APR,minseconds,maxseconds,mindeposit,sbits; char str[67],numstr[65]; UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CCcontract_info *cp,C; char str[67],numstr[65];
if ( GetTransaction(rewardsid,vintx,hashBlock,false) == 0 ) if ( GetTransaction(rewardsid,vintx,hashBlock,false) == 0 )
{ {
fprintf(stderr,"cant find fundingtxid\n"); fprintf(stderr,"cant find fundingtxid\n");
@@ -379,7 +382,10 @@ UniValue RewardsInfo(uint256 rewardsid)
result.push_back(Pair("maxseconds",maxseconds)); result.push_back(Pair("maxseconds",maxseconds));
sprintf(numstr,"%.8f",(double)mindeposit/COIN); sprintf(numstr,"%.8f",(double)mindeposit/COIN);
result.push_back(Pair("mindeposit",numstr)); result.push_back(Pair("mindeposit",numstr));
sprintf(numstr,"%.8f",(double)vintx.vout[0].nValue/COIN); cp = CCinit(&C,EVAL_REWARDS);
rewardspk = GetUnspendable(cp,0);
funding = RewardsPlanFunds(sbits,cp,rewardspk,rewardsid);
sprintf(numstr,"%.8f",(double)funding/COIN);
result.push_back(Pair("funding",numstr)); result.push_back(Pair("funding",numstr));
return(result); return(result);
} }

View File

@@ -676,7 +676,7 @@ int32_t komodo_block2height(CBlock *block)
if ( height2 >= 0 ) if ( height2 >= 0 )
return(height2); return(height2);
} }
if ( block->vtx[0].vin.size() > 0 ) if ( block != 0 && block->vtx[0].vin.size() > 0 )
{ {
#ifdef KOMODO_ZCASH #ifdef KOMODO_ZCASH
ptr = (uint8_t *)block->vtx[0].vin[0].scriptSig.data(); ptr = (uint8_t *)block->vtx[0].vin[0].scriptSig.data();

View File

@@ -1603,6 +1603,26 @@ bool GetAddressUnspent(uint160 addressHash, int type,
return true; return true;
} }
/*uint64_t myGettxout(uint256 hash,int32_t n)
{
CCoins coins;
LOCK2(cs_main,mempool.cs);
CCoinsViewMemPool view(pcoinsTip, mempool);
if (!view.GetCoins(hash, coins))
return(0);
if ( n < 0 || (unsigned int)n >= coins.vout.size() || coins.vout[n].IsNull() )
return(0);
else return(coins.vout[n].nValue);
}*/
bool myAddtomempool(CTransaction &tx)
{
CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false;
if ( mempool.lookup(tx.GetHash(),Ltx) == 0 )
return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees));
else return(true);
}
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock)
{ {
// need a GetTransaction without lock so the validation code for assets can run without deadlock // need a GetTransaction without lock so the validation code for assets can run without deadlock

View File

@@ -346,6 +346,25 @@ UniValue getdifficulty(const UniValue& params, bool fHelp)
return GetNetworkDifficulty(); return GetNetworkDifficulty();
} }
bool myIsutxo_spentinmempool(uint256 txid,int32_t vout)
{
//char *uint256_str(char *str,uint256); char str[65];
LOCK(mempool.cs);
BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx)
{
const CTransaction &tx = e.GetTx();
const uint256 &hash = tx.GetHash();
BOOST_FOREACH(const CTxIn &txin,tx.vin)
{
//fprintf(stderr,"%s/v%d ",uint256_str(str,txin.prevout.hash),txin.prevout.n);
if ( txin.prevout.n == vout && txin.prevout.hash == txid )
return(true);
}
//fprintf(stderr,"are vins for %s\n",uint256_str(str,hash));
}
return(false);
}
UniValue mempoolToJSON(bool fVerbose = false) UniValue mempoolToJSON(bool fVerbose = false)
{ {
if (fVerbose) if (fVerbose)

View File

@@ -119,6 +119,19 @@ UniValue TxJoinSplitToJSON(const CTransaction& tx) {
uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight);
int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout)
{
CSpentIndexValue spentInfo; CSpentIndexKey spentKey(txid,vout);
if ( GetSpentIndex(spentKey,spentInfo) )
{
spenttxid = spentInfo.txid;
return((int32_t)spentInfo.inputIndex);
// out.push_back(Pair("spentHeight", spentInfo.blockHeight));
}
memset(&spenttxid,0,sizeof(spenttxid));
return(-1);
}
void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, int nHeight = 0, int nConfirmations = 0, int nBlockTime = 0) void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, int nHeight = 0, int nConfirmations = 0, int nBlockTime = 0)
{ {
uint256 txid = tx.GetHash(); uint256 txid = tx.GetHash();
@@ -267,6 +280,8 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
vout.push_back(out); vout.push_back(out);
} }
entry.push_back(Pair("vout", vout)); entry.push_back(Pair("vout", vout));
UniValue vjoinsplit = TxJoinSplitToJSON(tx);
entry.push_back(Pair("vjoinsplit", vjoinsplit));
if (!hashBlock.IsNull()) { if (!hashBlock.IsNull()) {
entry.push_back(Pair("blockhash", hashBlock.GetHex())); entry.push_back(Pair("blockhash", hashBlock.GetHex()));

View File

@@ -350,8 +350,11 @@ static const CRPCCommand vRPCCommands[] =
/* lotto */ /* lotto */
{ "lotto", "lottoaddress", &lottoaddress, true }, { "lotto", "lottoaddress", &lottoaddress, true },
/* ponzi */ /* fsm */
{ "ponzi", "ponziaddress", &ponziaddress, true }, { "FSM", "FSMaddress", &FSMaddress, true },
{ "FSMcreate", "FSMcreate", &FSMcreate, true },
{ "FSMlist", "FSMlist", &FSMlist, true },
{ "FSMinfo", "FSMinfo", &FSMinfo, true },
/* rewards */ /* rewards */
{ "rewards", "rewardslist", &rewardslist, true }, { "rewards", "rewardslist", &rewardslist, true },
@@ -363,6 +366,7 @@ static const CRPCCommand vRPCCommands[] =
{ "rewards", "rewardsaddress", &rewardsaddress, true }, { "rewards", "rewardsaddress", &rewardsaddress, true },
/* faucet */ /* faucet */
{ "faucet", "faucetinfo", &faucetinfo, true },
{ "faucet", "faucetfund", &faucetfund, true }, { "faucet", "faucetfund", &faucetfund, true },
{ "faucet", "faucetget", &faucetget, true }, { "faucet", "faucetget", &faucetget, true },
{ "faucet", "faucetaddress", &faucetaddress, true }, { "faucet", "faucetaddress", &faucetaddress, true },
@@ -373,6 +377,8 @@ static const CRPCCommand vRPCCommands[] =
{ "dice", "dicefund", &dicefund, true }, { "dice", "dicefund", &dicefund, true },
{ "dice", "diceaddfunds", &diceaddfunds, true }, { "dice", "diceaddfunds", &diceaddfunds, true },
{ "dice", "dicebet", &dicebet, true }, { "dice", "dicebet", &dicebet, true },
{ "dice", "dicefinish", &dicefinish, true },
{ "dice", "dicestatus", &dicestatus, true },
{ "dice", "diceaddress", &diceaddress, true }, { "dice", "diceaddress", &diceaddress, true },
/* tokens */ /* tokens */
@@ -387,10 +393,10 @@ static const CRPCCommand vRPCCommands[] =
{ "tokens", "tokencancelbid", &tokencancelbid, true }, { "tokens", "tokencancelbid", &tokencancelbid, true },
{ "tokens", "tokenfillbid", &tokenfillbid, true }, { "tokens", "tokenfillbid", &tokenfillbid, true },
{ "tokens", "tokenask", &tokenask, true }, { "tokens", "tokenask", &tokenask, true },
{ "tokens", "tokenswapask", &tokenswapask, true }, //{ "tokens", "tokenswapask", &tokenswapask, true },
{ "tokens", "tokencancelask", &tokencancelask, true }, { "tokens", "tokencancelask", &tokencancelask, true },
{ "tokens", "tokenfillask", &tokenfillask, true }, { "tokens", "tokenfillask", &tokenfillask, true },
{ "tokens", "tokenfillswap", &tokenfillswap, true }, //{ "tokens", "tokenfillswap", &tokenfillswap, true },
/* Address index */ /* Address index */
{ "addressindex", "getaddressmempool", &getaddressmempool, true }, { "addressindex", "getaddressmempool", &getaddressmempool, true },

View File

@@ -221,11 +221,12 @@ extern UniValue tokenfillbid(const UniValue& params, bool fHelp);
extern UniValue tokenask(const UniValue& params, bool fHelp); extern UniValue tokenask(const UniValue& params, bool fHelp);
extern UniValue tokencancelask(const UniValue& params, bool fHelp); extern UniValue tokencancelask(const UniValue& params, bool fHelp);
extern UniValue tokenfillask(const UniValue& params, bool fHelp); extern UniValue tokenfillask(const UniValue& params, bool fHelp);
extern UniValue tokenswapask(const UniValue& params, bool fHelp); //extern UniValue tokenswapask(const UniValue& params, bool fHelp);
extern UniValue tokenfillswap(const UniValue& params, bool fHelp); //extern UniValue tokenfillswap(const UniValue& params, bool fHelp);
extern UniValue faucetfund(const UniValue& params, bool fHelp); extern UniValue faucetfund(const UniValue& params, bool fHelp);
extern UniValue faucetget(const UniValue& params, bool fHelp); extern UniValue faucetget(const UniValue& params, bool fHelp);
extern UniValue faucetaddress(const UniValue& params, bool fHelp); extern UniValue faucetaddress(const UniValue& params, bool fHelp);
extern UniValue faucetinfo(const UniValue& params, bool fHelp);
extern UniValue rewardsinfo(const UniValue& params, bool fHelp); extern UniValue rewardsinfo(const UniValue& params, bool fHelp);
extern UniValue rewardslist(const UniValue& params, bool fHelp); extern UniValue rewardslist(const UniValue& params, bool fHelp);
extern UniValue rewardsaddress(const UniValue& params, bool fHelp); extern UniValue rewardsaddress(const UniValue& params, bool fHelp);
@@ -239,8 +240,13 @@ extern UniValue dicelist(const UniValue& params, bool fHelp);
extern UniValue diceinfo(const UniValue& params, bool fHelp); extern UniValue diceinfo(const UniValue& params, bool fHelp);
extern UniValue diceaddfunds(const UniValue& params, bool fHelp); extern UniValue diceaddfunds(const UniValue& params, bool fHelp);
extern UniValue dicebet(const UniValue& params, bool fHelp); extern UniValue dicebet(const UniValue& params, bool fHelp);
extern UniValue dicefinish(const UniValue& params, bool fHelp);
extern UniValue dicestatus(const UniValue& params, bool fHelp);
extern UniValue lottoaddress(const UniValue& params, bool fHelp); extern UniValue lottoaddress(const UniValue& params, bool fHelp);
extern UniValue ponziaddress(const UniValue& params, bool fHelp); extern UniValue FSMaddress(const UniValue& params, bool fHelp);
extern UniValue FSMcreate(const UniValue& params, bool fHelp);
extern UniValue FSMlist(const UniValue& params, bool fHelp);
extern UniValue FSMinfo(const UniValue& params, bool fHelp);
extern UniValue auctionaddress(const UniValue& params, bool fHelp); extern UniValue auctionaddress(const UniValue& params, bool fHelp);
extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp

View File

@@ -4844,18 +4844,18 @@ int32_t ensure_CCrequirements()
#include "../cc/CCassets.h" #include "../cc/CCassets.h"
#include "../cc/CCrewards.h" #include "../cc/CCrewards.h"
#include "../cc/CCdice.h" #include "../cc/CCdice.h"
#include "../cc/CCponzi.h" #include "../cc/CCfsm.h"
#include "../cc/CCauction.h" #include "../cc/CCauction.h"
#include "../cc/CClotto.h" #include "../cc/CClotto.h"
UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector<unsigned char> &pubkey) UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector<unsigned char> &pubkey)
{ {
UniValue result(UniValue::VOBJ); ; char destaddr[64],str[64],marker[64]; UniValue result(UniValue::VOBJ); ; char destaddr[64],str[64];
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
sprintf(str,"%sCCaddress",name); sprintf(str,"%sCCaddress",name);
sprintf(marker,"%smarker",name); result.push_back(Pair(str,cp->unspendableCCaddr));
if ( GetCCaddress(cp,destaddr,pubkey2pk(pubkey)) != 0 ) sprintf(str,"%smarker",name);
result.push_back(Pair(str,destaddr)); result.push_back(Pair(str,cp->normaladdr));
if ( pubkey.size() == 33 ) if ( pubkey.size() == 33 )
{ {
if ( GetCCaddress(cp,destaddr,pubkey2pk(pubkey)) != 0 ) if ( GetCCaddress(cp,destaddr,pubkey2pk(pubkey)) != 0 )
@@ -4881,17 +4881,17 @@ UniValue lottoaddress(const UniValue& params, bool fHelp)
return(CCaddress(cp,(char *)"Lotto",pubkey)); return(CCaddress(cp,(char *)"Lotto",pubkey));
} }
UniValue ponziaddress(const UniValue& params, bool fHelp) UniValue FSMaddress(const UniValue& params, bool fHelp)
{ {
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey; struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;
cp = CCinit(&C,EVAL_PONZI); cp = CCinit(&C,EVAL_FSM);
if ( fHelp || params.size() > 1 ) if ( fHelp || params.size() > 1 )
throw runtime_error("ponziaddress [pubkey]\n"); throw runtime_error("FSMaddress [pubkey]\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
if ( params.size() == 1 ) if ( params.size() == 1 )
pubkey = ParseHex(params[0].get_str().c_str()); pubkey = ParseHex(params[0].get_str().c_str());
return(CCaddress(cp,(char *)"Ponzi",pubkey)); return(CCaddress(cp,(char *)"FSM",pubkey));
} }
UniValue auctionaddress(const UniValue& params, bool fHelp) UniValue auctionaddress(const UniValue& params, bool fHelp)
@@ -4966,7 +4966,9 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp)
throw runtime_error("rewardscreatefunding name amount APR mindays maxdays mindeposit\n"); throw runtime_error("rewardscreatefunding name amount APR mindays maxdays mindeposit\n");
if ( ensure_CCrequirements() < 0 ) 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"); 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 const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
// default to OOT params
APR = 5 * COIN; APR = 5 * COIN;
minseconds = maxseconds = 60 * 3600 * 24; minseconds = maxseconds = 60 * 3600 * 24;
mindeposit = 100 * COIN; mindeposit = 100 * COIN;
@@ -5002,6 +5004,8 @@ UniValue rewardslock(const UniValue& params, bool fHelp)
throw runtime_error("rewardslock name fundingtxid amount\n"); throw runtime_error("rewardslock name fundingtxid amount\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = (char *)params[0].get_str().c_str(); name = (char *)params[0].get_str().c_str();
fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
amount = atof(params[2].get_str().c_str()) * COIN; amount = atof(params[2].get_str().c_str()) * COIN;
@@ -5021,6 +5025,8 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp)
throw runtime_error("rewardsaddfunding name fundingtxid amount\n"); throw runtime_error("rewardsaddfunding name fundingtxid amount\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = (char *)params[0].get_str().c_str(); name = (char *)params[0].get_str().c_str();
fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
amount = atof(params[2].get_str().c_str()) * COIN; amount = atof(params[2].get_str().c_str()) * COIN;
@@ -5040,6 +5046,8 @@ UniValue rewardsunlock(const UniValue& params, bool fHelp)
throw runtime_error("rewardsunlock name fundingtxid [txid]\n"); throw runtime_error("rewardsunlock name fundingtxid [txid]\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = (char *)params[0].get_str().c_str(); name = (char *)params[0].get_str().c_str();
fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
if ( params.size() > 2 ) if ( params.size() > 2 )
@@ -5075,6 +5083,57 @@ UniValue rewardsinfo(const UniValue& params, bool fHelp)
return(RewardsInfo(fundingtxid)); return(RewardsInfo(fundingtxid));
} }
UniValue FSMcreate(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); std::string name,states,hex;
if ( fHelp || params.size() != 2 )
throw runtime_error("FSMcreate name states\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");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = params[0].get_str();
states = params[1].get_str();
hex = FSMCreate(0,name,states);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else result.push_back(Pair("error", "couldnt create FSM transaction"));
return(result);
}
UniValue FSMlist(const UniValue& params, bool fHelp)
{
uint256 tokenid;
if ( fHelp || params.size() > 0 )
throw runtime_error("FSMlist\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");
return(FSMList());
}
UniValue FSMinfo(const UniValue& params, bool fHelp)
{
uint256 FSMtxid;
if ( fHelp || params.size() != 1 )
throw runtime_error("FSMinfo fundingtxid\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");
FSMtxid = Parseuint256((char *)params[0].get_str().c_str());
return(FSMInfo(FSMtxid));
}
UniValue faucetinfo(const UniValue& params, bool fHelp)
{
uint256 fundingtxid;
if ( fHelp || params.size() != 0 )
throw runtime_error("faucetinfo\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");
return(FaucetInfo());
}
UniValue faucetfund(const UniValue& params, bool fHelp) UniValue faucetfund(const UniValue& params, bool fHelp)
{ {
UniValue result(UniValue::VOBJ); uint64_t funds; std::string hex; UniValue result(UniValue::VOBJ); uint64_t funds; std::string hex;
@@ -5082,6 +5141,8 @@ UniValue faucetfund(const UniValue& params, bool fHelp)
throw runtime_error("faucetfund amount\n"); throw runtime_error("faucetfund amount\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
funds = atof(params[0].get_str().c_str()) * COIN; funds = atof(params[0].get_str().c_str()) * COIN;
hex = FaucetFund(0,funds); hex = FaucetFund(0,funds);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
@@ -5099,6 +5160,8 @@ UniValue faucetget(const UniValue& params, bool fHelp)
throw runtime_error("faucetget\n"); throw runtime_error("faucetget\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
hex = FaucetGet(0); hex = FaucetGet(0);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
@@ -5110,18 +5173,20 @@ UniValue faucetget(const UniValue& params, bool fHelp)
UniValue dicefund(const UniValue& params, bool fHelp) UniValue dicefund(const UniValue& params, bool fHelp)
{ {
UniValue result(UniValue::VOBJ); int64_t funds,minbet,maxbet,maxodds,forfeitblocks; std::string hex; char *name; UniValue result(UniValue::VOBJ); int64_t funds,minbet,maxbet,maxodds,timeoutblocks; std::string hex; char *name;
if ( fHelp || params.size() != 6 ) if ( fHelp || params.size() != 6 )
throw runtime_error("dicefund name funds minbet maxbet maxodds forfeitblocks\n"); throw runtime_error("dicefund name funds minbet maxbet maxodds timeoutblocks\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = (char *)params[0].get_str().c_str(); name = (char *)params[0].get_str().c_str();
funds = atof(params[1].get_str().c_str()) * COIN; funds = atof(params[1].get_str().c_str()) * COIN;
minbet = atof(params[2].get_str().c_str()) * COIN; minbet = atof(params[2].get_str().c_str()) * COIN;
maxbet = atof(params[3].get_str().c_str()) * COIN; maxbet = atof(params[3].get_str().c_str()) * COIN;
maxodds = atol(params[4].get_str().c_str()); maxodds = atol(params[4].get_str().c_str());
forfeitblocks = atol(params[5].get_str().c_str()); timeoutblocks = atol(params[5].get_str().c_str());
hex = DiceCreateFunding(0,name,funds,minbet,maxbet,maxodds,forfeitblocks); hex = DiceCreateFunding(0,name,funds,minbet,maxbet,maxodds,timeoutblocks);
if ( hex.size() > 0 ) if ( hex.size() > 0 )
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
@@ -5137,6 +5202,8 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp)
throw runtime_error("diceaddfunds name fundingtxid amount\n"); throw runtime_error("diceaddfunds name fundingtxid amount\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = (char *)params[0].get_str().c_str(); name = (char *)params[0].get_str().c_str();
fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
amount = atof(params[2].get_str().c_str()) * COIN; amount = atof(params[2].get_str().c_str()) * COIN;
@@ -5156,6 +5223,8 @@ UniValue dicebet(const UniValue& params, bool fHelp)
throw runtime_error("dicebet name fundingtxid amount odds\n"); throw runtime_error("dicebet name fundingtxid amount odds\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = (char *)params[0].get_str().c_str(); name = (char *)params[0].get_str().c_str();
fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
amount = atof(params[2].get_str().c_str()) * COIN; amount = atof(params[2].get_str().c_str()) * COIN;
@@ -5169,6 +5238,68 @@ UniValue dicebet(const UniValue& params, bool fHelp)
return(result); return(result);
} }
UniValue dicefinish(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string hex; int32_t r;
if ( fHelp || params.size() != 3 )
throw runtime_error("dicefinish name fundingtxid bettxid\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");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = (char *)params[0].get_str().c_str();
fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
bettxid = Parseuint256((char *)params[2].get_str().c_str());
hex = DiceBetFinish(&r,0,name,fundingtxid,bettxid,1);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else result.push_back(Pair("error", "couldnt create dicefinish transaction"));
return(result);
}
UniValue dicestatus(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string status; double winnings;
if ( fHelp || (params.size() != 2 && params.size() != 3) )
throw runtime_error("dicestatus name fundingtxid bettxid\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");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = (char *)params[0].get_str().c_str();
fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
memset(&bettxid,0,sizeof(bettxid));
if ( params.size() == 3 )
bettxid = Parseuint256((char *)params[2].get_str().c_str());
winnings = DiceStatus(0,name,fundingtxid,bettxid);
result.push_back(Pair("result", "success"));
if ( winnings >= 0. )
{
if ( winnings > 0. )
{
if ( params.size() == 3 )
{
result.push_back(Pair("status", "win"));
result.push_back(Pair("won", winnings));
}
else
{
result.push_back(Pair("status", "finalized"));
result.push_back(Pair("n", (int64_t)winnings));
}
}
else
{
if ( params.size() == 3 )
result.push_back(Pair("status", "loss"));
else result.push_back(Pair("status", "no pending bets"));
}
} else result.push_back(Pair("status", "invalid bet txid"));
return(result);
}
UniValue dicelist(const UniValue& params, bool fHelp) UniValue dicelist(const UniValue& params, bool fHelp)
{ {
uint256 tokenid; uint256 tokenid;
@@ -5232,6 +5363,7 @@ UniValue tokenbalance(const UniValue& params, bool fHelp)
throw runtime_error("tokenbalance tokenid [pubkey]\n"); throw runtime_error("tokenbalance tokenid [pubkey]\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
LOCK(cs_main);
tokenid = Parseuint256((char *)params[0].get_str().c_str()); tokenid = Parseuint256((char *)params[0].get_str().c_str());
if ( params.size() == 2 ) if ( params.size() == 2 )
pubkey = ParseHex(params[1].get_str().c_str()); pubkey = ParseHex(params[1].get_str().c_str());
@@ -5252,6 +5384,8 @@ UniValue tokencreate(const UniValue& params, bool fHelp)
throw runtime_error("tokencreate name supply description\n"); throw runtime_error("tokencreate name supply description\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = params[0].get_str(); name = params[0].get_str();
supply = atof(params[1].get_str().c_str()) * COIN; supply = atof(params[1].get_str().c_str()) * COIN;
if ( params.size() == 3 ) if ( params.size() == 3 )
@@ -5272,6 +5406,8 @@ UniValue tokentransfer(const UniValue& params, bool fHelp)
throw runtime_error("tokentransfer tokenid destpubkey amount\n"); throw runtime_error("tokentransfer tokenid destpubkey amount\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
tokenid = Parseuint256((char *)params[0].get_str().c_str()); tokenid = Parseuint256((char *)params[0].get_str().c_str());
std::vector<unsigned char> pubkey(ParseHex(params[1].get_str().c_str())); std::vector<unsigned char> pubkey(ParseHex(params[1].get_str().c_str()));
amount = atol(params[2].get_str().c_str()); amount = atol(params[2].get_str().c_str());
@@ -5291,6 +5427,8 @@ UniValue tokenbid(const UniValue& params, bool fHelp)
throw runtime_error("tokenbid numtokens tokenid price\n"); throw runtime_error("tokenbid numtokens tokenid price\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
numtokens = atoi(params[0].get_str().c_str()); numtokens = atoi(params[0].get_str().c_str());
tokenid = Parseuint256((char *)params[1].get_str().c_str()); tokenid = Parseuint256((char *)params[1].get_str().c_str());
price = atof(params[2].get_str().c_str()); price = atof(params[2].get_str().c_str());
@@ -5311,6 +5449,8 @@ UniValue tokencancelbid(const UniValue& params, bool fHelp)
throw runtime_error("tokencancelbid tokenid bidtxid\n"); throw runtime_error("tokencancelbid tokenid bidtxid\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
tokenid = Parseuint256((char *)params[0].get_str().c_str()); tokenid = Parseuint256((char *)params[0].get_str().c_str());
bidtxid = Parseuint256((char *)params[1].get_str().c_str()); bidtxid = Parseuint256((char *)params[1].get_str().c_str());
hex = CancelBuyOffer(0,tokenid,bidtxid); hex = CancelBuyOffer(0,tokenid,bidtxid);
@@ -5329,6 +5469,8 @@ UniValue tokenfillbid(const UniValue& params, bool fHelp)
throw runtime_error("tokenfillbid tokenid bidtxid fillamount\n"); throw runtime_error("tokenfillbid tokenid bidtxid fillamount\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
tokenid = Parseuint256((char *)params[0].get_str().c_str()); tokenid = Parseuint256((char *)params[0].get_str().c_str());
bidtxid = Parseuint256((char *)params[1].get_str().c_str()); bidtxid = Parseuint256((char *)params[1].get_str().c_str());
fillamount = atol(params[2].get_str().c_str()); fillamount = atol(params[2].get_str().c_str());
@@ -5348,6 +5490,8 @@ UniValue tokenask(const UniValue& params, bool fHelp)
throw runtime_error("tokenask numtokens tokenid price\n"); throw runtime_error("tokenask numtokens tokenid price\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
numtokens = atoi(params[0].get_str().c_str()); numtokens = atoi(params[0].get_str().c_str());
tokenid = Parseuint256((char *)params[1].get_str().c_str()); tokenid = Parseuint256((char *)params[1].get_str().c_str());
price = atof(params[2].get_str().c_str()); price = atof(params[2].get_str().c_str());
@@ -5369,6 +5513,8 @@ UniValue tokenswapask(const UniValue& params, bool fHelp)
throw runtime_error("tokenswapask numtokens tokenid otherid price\n"); throw runtime_error("tokenswapask numtokens tokenid otherid price\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
numtokens = atoi(params[0].get_str().c_str()); numtokens = atoi(params[0].get_str().c_str());
tokenid = Parseuint256((char *)params[1].get_str().c_str()); tokenid = Parseuint256((char *)params[1].get_str().c_str());
otherid = Parseuint256((char *)params[2].get_str().c_str()); otherid = Parseuint256((char *)params[2].get_str().c_str());
@@ -5390,6 +5536,8 @@ UniValue tokencancelask(const UniValue& params, bool fHelp)
throw runtime_error("tokencancelask tokenid asktxid\n"); throw runtime_error("tokencancelask tokenid asktxid\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
tokenid = Parseuint256((char *)params[0].get_str().c_str()); tokenid = Parseuint256((char *)params[0].get_str().c_str());
asktxid = Parseuint256((char *)params[1].get_str().c_str()); asktxid = Parseuint256((char *)params[1].get_str().c_str());
hex = CancelSell(0,tokenid,asktxid); hex = CancelSell(0,tokenid,asktxid);
@@ -5409,6 +5557,8 @@ UniValue tokenfillask(const UniValue& params, bool fHelp)
throw runtime_error("tokenfillask tokenid asktxid fillunits\n"); throw runtime_error("tokenfillask tokenid asktxid fillunits\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
tokenid = Parseuint256((char *)params[0].get_str().c_str()); tokenid = Parseuint256((char *)params[0].get_str().c_str());
asktxid = Parseuint256((char *)params[1].get_str().c_str()); asktxid = Parseuint256((char *)params[1].get_str().c_str());
fillunits = atol(params[2].get_str().c_str()); fillunits = atol(params[2].get_str().c_str());
@@ -5429,6 +5579,8 @@ UniValue tokenfillswap(const UniValue& params, bool fHelp)
throw runtime_error("tokenfillswap tokenid otherid asktxid fillunits\n"); throw runtime_error("tokenfillswap tokenid otherid asktxid fillunits\n");
if ( ensure_CCrequirements() < 0 ) 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"); throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
tokenid = Parseuint256((char *)params[0].get_str().c_str()); tokenid = Parseuint256((char *)params[0].get_str().c_str());
otherid = Parseuint256((char *)params[1].get_str().c_str()); otherid = Parseuint256((char *)params[1].get_str().c_str());
asktxid = Parseuint256((char *)params[2].get_str().c_str()); asktxid = Parseuint256((char *)params[2].get_str().c_str());

View File

@@ -2117,7 +2117,7 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(int64_t nTime)
// Don't rebroadcast if newer than nTime: // Don't rebroadcast if newer than nTime:
if (wtx.nTimeReceived > nTime) if (wtx.nTimeReceived > nTime)
continue; continue;
//if ( ASSETCHAINS_SYMBOL[0] == 0 ) if ( ASSETCHAINS_SYMBOL[0] == 0 )
{ {
if ( wtx.nLockTime >= LOCKTIME_THRESHOLD && wtx.nLockTime < now-KOMODO_MAXMEMPOOLTIME ) if ( wtx.nLockTime >= LOCKTIME_THRESHOLD && wtx.nLockTime < now-KOMODO_MAXMEMPOOLTIME )
{ {