Merge remote-tracking branch 'origin/jl777' into cctests

This commit is contained in:
Jonathan "Duke" Leto
2018-08-24 02:24:36 +02:00
7 changed files with 32 additions and 14 deletions

View File

@@ -28,7 +28,7 @@
#include <univalue.h> #include <univalue.h>
#include <exception> #include <exception>
extern int32_t KOMODO_CONNECTING; extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE;
#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; }; union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; };

View File

@@ -256,9 +256,11 @@ 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 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector<uint8_t> origpubkey; CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector<uint8_t> origpubkey;
height = KOMODO_CONNECTING;
if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation
return(true); return(true);
height = KOMODO_CONNECTING; if ( ASSETCHAINS_CC == 0 || height < KOMODO_CCACTIVATE )
return eval->Invalid("CC are disabled or not active yet");
if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) if ( (KOMODO_CONNECTING & (1<<30)) != 0 )
{ {
from_mempool = 1; from_mempool = 1;

View File

@@ -665,6 +665,8 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit
{ {
char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0; uint8_t funcid; char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0; uint8_t funcid;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
entropyval = 0;
entropytxid = zeroid;
if ( GetTransaction(reffundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) != 0 ) if ( GetTransaction(reffundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) != 0 )
{ {
fundingPubKey = tx.vout[1].scriptPubKey; fundingPubKey = tx.vout[1].scriptPubKey;
@@ -743,20 +745,21 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit
bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontract_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontract_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks)
{ {
char CCaddr[64]; uint64_t sbits; uint256 txid,hashBlock; CTransaction tx; char CCaddr[64]; uint64_t sbits=0; uint256 txid,hashBlock; CTransaction tx;
std::vector<std::pair<CAddressIndexKey, CAmount> > txids; std::vector<std::pair<CAddressIndexKey, CAmount> > txids;
GetCCaddress(cp,CCaddr,dicepk); GetCCaddress(cp,CCaddr,dicepk);
SetCCtxids(txids,cp->normaladdr); SetCCtxids(txids,cp->normaladdr);
if ( fundingtxid != zeroid ) // avoid scan unless creating new funding plan if ( fundingtxid != zeroid ) // avoid scan unless creating new funding plan
{ {
//fprintf(stderr,"check fundingtxid\n");
if ( GetTransaction(fundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) if ( GetTransaction(fundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 )
{ {
if ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) if ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits )
{ {
fundingPubKey = tx.vout[1].scriptPubKey; fundingPubKey = tx.vout[1].scriptPubKey;
return(true); return(true);
} } else fprintf(stderr,"error decoding opret or sbits mismatch %llx vs %llx\n",(long long)sbits,(long long)refsbits);
} } else fprintf(stderr,"couldnt get funding tx\n");
return(false); return(false);
} }
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=txids.begin(); it!=txids.end(); it++) for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=txids.begin(); it!=txids.end(); it++)
@@ -795,7 +798,7 @@ struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,s
else cmpflag = 1; else cmpflag = 1;
if ( DicePlanExists(fundingPubKey,reffundingtxid,cp,sbits,dicepk,minbet,maxbet,maxodds,timeoutblocks) != cmpflag ) if ( DicePlanExists(fundingPubKey,reffundingtxid,cp,sbits,dicepk,minbet,maxbet,maxodds,timeoutblocks) != cmpflag )
{ {
fprintf(stderr,"Dice plan (%s) already exists cmpflag.%d\n",planstr,cmpflag); fprintf(stderr,"Dice plan (%s) exists.%d vs cmpflag.%d\n",planstr,!cmpflag,cmpflag);
return(0); return(0);
} }
return(cp); return(cp);
@@ -863,10 +866,16 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t
fprintf(stderr,"%s\n", CCerror.c_str() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }
if ( funds < 100*COIN )
{
CCerror = "dice plan needs at least 100 coins";
fprintf(stderr,"%s\n", CCerror.c_str() );
return("");
}
memset(&zero,0,sizeof(zero)); memset(&zero,0,sizeof(zero));
if ( (cp= Diceinit(fundingPubKey,zero,&C,planstr,txfee,mypk,dicepk,sbits,a,b,c,d)) == 0 ) if ( (cp= Diceinit(fundingPubKey,zero,&C,planstr,txfee,mypk,dicepk,sbits,a,b,c,d)) == 0 )
{ {
CCerror = "Diceinit error"; CCerror = "Diceinit error in create funding";
fprintf(stderr,"%s\n", CCerror.c_str() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }
@@ -964,7 +973,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet
mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,dicepk)); mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,dicepk));
mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('B',sbits,fundingtxid,entropy,zeroid))); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('B',sbits,fundingtxid,entropy,zeroid)));
} else fprintf(stderr,"cant find enough inputs %.8f note enough for %.8f\n",(double)funding/COIN,(double)bet/COIN); } else fprintf(stderr,"cant find enough normal inputs for %.8f, plan funding %.8f\n",(double)bet/COIN,(double)funding/COIN);
} }
if ( entropyval == 0 && funding != 0 ) if ( entropyval == 0 && funding != 0 )
CCerror = "cant find dice entropy inputs"; CCerror = "cant find dice entropy inputs";
@@ -981,7 +990,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256
//char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid)); //char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid));
if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
{ {
CCerror = "Diceinit error"; CCerror = "Diceinit error in finish";
fprintf(stderr,"%s\n", CCerror.c_str() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }
@@ -1094,7 +1103,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx
CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res;
if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
{ {
CCerror = "Diceinit error"; CCerror = "Diceinit error in status";
fprintf(stderr,"%s\n", CCerror.c_str() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(0.); return(0.);
} }

View File

@@ -46,7 +46,7 @@ struct komodo_state KOMODO_STATES[34];
int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1;
int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1;
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY;
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE;

View File

@@ -1544,6 +1544,7 @@ void komodo_args(char *argv0)
} }
KOMODO_STOPAT = GetArg("-stopat",0); KOMODO_STOPAT = GetArg("-stopat",0);
ASSETCHAINS_CC = GetArg("-ac_cc",0); ASSETCHAINS_CC = GetArg("-ac_cc",0);
KOMODO_CCACTIVATE = GetArg("-ac_ccactivate",0);
ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0);
ASSETCHAINS_PRIVATE = GetArg("-ac_private",0); ASSETCHAINS_PRIVATE = GetArg("-ac_private",0);
if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 ) if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 )
@@ -1650,6 +1651,11 @@ void komodo_args(char *argv0)
//printf("created (%s)\n",fname); //printf("created (%s)\n",fname);
} else printf("error creating (%s)\n",fname); } else printf("error creating (%s)\n",fname);
#endif #endif
if ( KOMODO_CCACTIVATE != 0 && ASSETCHAINS_CC == 0 )
{
ASSETCHAINS_CC = 2;
fprintf(stderr,"smart utxo CC contracts will activate at height.%d\n",KOMODO_CCACTIVATE);
}
} }
else else
{ {

View File

@@ -104,8 +104,8 @@ static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
//static const bool DEFAULT_ADDRESSINDEX = false; //static const bool DEFAULT_ADDRESSINDEX = false;
//static const bool DEFAULT_SPENTINDEX = false; //static const bool DEFAULT_SPENTINDEX = false;
#define DEFAULT_ADDRESSINDEX (GetArg("-ac_cc",0) != 0) #define DEFAULT_ADDRESSINDEX (GetArg("-ac_cc",0) != 0 || GetArg("-ac_ccactivate",0) != 0)
#define DEFAULT_SPENTINDEX (GetArg("-ac_cc",0) != 0) #define DEFAULT_SPENTINDEX (GetArg("-ac_cc",0) != 0 || GetArg("-ac_ccactivate",0) != 0)
static const bool DEFAULT_TIMESTAMPINDEX = false; static const bool DEFAULT_TIMESTAMPINDEX = false;
static const unsigned int DEFAULT_DB_MAX_OPEN_FILES = 1000; static const unsigned int DEFAULT_DB_MAX_OPEN_FILES = 1000;
static const bool DEFAULT_DB_COMPRESSION = true; static const bool DEFAULT_DB_COMPRESSION = true;

View File

@@ -4836,6 +4836,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
int32_t ensure_CCrequirements() int32_t ensure_CCrequirements()
{ {
extern uint8_t NOTARY_PUBKEY33[]; extern uint8_t NOTARY_PUBKEY33[];
CCerror = "";
if ( NOTARY_PUBKEY33[0] == 0 ) if ( NOTARY_PUBKEY33[0] == 0 )
return(-1); return(-1);
else if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) == 0 ) else if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) == 0 )
@@ -5289,7 +5290,7 @@ UniValue dicebet(const UniValue& params, bool fHelp)
{ {
result.push_back(Pair("result", "success")); result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex)); result.push_back(Pair("hex", hex));
} else ERR_RESULT("couldnt create dice bet transaction"); } else ERR_RESULT("couldnt create dice bet transaction. make sure your address has funds");
} else { } else {
ERR_RESULT("amount and odds must be positive"); ERR_RESULT("amount and odds must be positive");
} }