Merge branch 'jl777' into FSM
# Conflicts: # src/cc/rewards.cpp # src/main.cpp
This commit is contained in:
@@ -301,14 +301,14 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector<uint8_t> param
|
||||
height = KOMODO_CONNECTING;
|
||||
if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation
|
||||
return(true);
|
||||
if ( ASSETCHAINS_CC == 0 || height < KOMODO_CCACTIVATE )
|
||||
if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE )
|
||||
return eval->Invalid("CC are disabled or not active yet");
|
||||
if ( (KOMODO_CONNECTING & (1<<30)) != 0 )
|
||||
{
|
||||
from_mempool = 1;
|
||||
height &= ((1<<30) - 1);
|
||||
}
|
||||
fprintf(stderr,"KOMODO_CONNECTING.%d mempool.%d\n",height,from_mempool);
|
||||
fprintf(stderr,"KOMODO_CONNECTING.%d mempool.%d vs CCactive.%d\n",height,from_mempool,KOMODO_CCACTIVATE);
|
||||
// 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
|
||||
//txid = ctx.GetHash();
|
||||
//if ( txid == cp->prevtxid )
|
||||
|
||||
@@ -1151,7 +1151,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx
|
||||
}
|
||||
CCerror = "couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid);
|
||||
fprintf(stderr,"%s\n", CCerror.c_str());
|
||||
return(0.);
|
||||
return(-1.);
|
||||
}
|
||||
else if ( scriptPubKey == fundingPubKey )
|
||||
res = DiceBetFinish(&result,txfee,planstr,fundingtxid,bettxid,1);
|
||||
|
||||
@@ -194,7 +194,7 @@ bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransactio
|
||||
|
||||
bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
|
||||
{
|
||||
uint256 txid,fundingtxid,hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit,amount,reward,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; uint8_t funcid; CScript scriptPubKey; CTransaction fundingTx,vinTx;
|
||||
uint256 txid,fundingtxid,hashBlock,vinfundingtxid; uint64_t vinsbits,sbits,APR,minseconds,maxseconds,mindeposit,amount,reward,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; uint8_t funcid; CScript scriptPubKey; CTransaction fundingTx,vinTx;
|
||||
numvins = tx.vin.size();
|
||||
numvouts = tx.vout.size();
|
||||
preventCCvins = preventCCvouts = -1;
|
||||
@@ -242,10 +242,20 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t
|
||||
//vout.0: funding CC change or recover normal payout
|
||||
//vout.1: normal output to unlock address
|
||||
//vout.n-1: opreturn 'U' sbits fundingtxid
|
||||
<<<<<<< HEAD
|
||||
if ( fundingtxid == txid )
|
||||
=======
|
||||
//char str[65],str2[65];
|
||||
//fprintf(stderr,"funding.%s vs %s\n",uint256_str(str,fundingtxid),uint256_str(str2,tx.vin[0].prevout.hash));
|
||||
if ( fundingtxid == tx.vin[0].prevout.hash )
|
||||
>>>>>>> jl777
|
||||
return eval->Invalid("cant unlock fundingtxid");
|
||||
else if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 )
|
||||
return eval->Invalid("always should find vin.0, but didnt");
|
||||
else if ( DecodeRewardsOpRet(tx.vin[0].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid) != 'L' )
|
||||
return eval->Invalid("can only unlock locktxid");
|
||||
else if ( fundingtxid != vinfundingtxid )
|
||||
return eval->Invalid("mismatched vinfundingtxid");
|
||||
for (i=0; i<numvins; i++)
|
||||
{
|
||||
if ( (*cp->ismyvin)(tx.vin[i].scriptSig) == 0 )
|
||||
|
||||
10
src/main.cpp
10
src/main.cpp
@@ -1546,7 +1546,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
||||
}
|
||||
if ( flag != 0 )
|
||||
KOMODO_CONNECTING = -1;
|
||||
|
||||
|
||||
// Store transaction in memory
|
||||
if ( komodo_is_notarytx(tx) == 0 )
|
||||
KOMODO_ON_DEMAND++;
|
||||
@@ -3427,7 +3427,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
|
||||
for (int i = 0; i < block.vtx.size(); i++)
|
||||
{
|
||||
CTransaction &tx = block.vtx[i];
|
||||
if ( (i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0 )
|
||||
if ( ASSETCHAINS_STAKED != 0 && (i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0 )
|
||||
{
|
||||
EraseFromWallets(tx.GetHash());
|
||||
}
|
||||
@@ -4181,12 +4181,16 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
|
||||
for (i=0; i<block.vtx.size(); i++)
|
||||
{
|
||||
CTransaction Tx; const CTransaction &tx = (CTransaction)block.vtx[i];
|
||||
if (tx.IsCoinBase() != 0 )
|
||||
if ( tx.IsCoinBase() != 0 )
|
||||
continue;
|
||||
else if ( ASSETCHAINS_STAKED != 0 && (i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0 )
|
||||
continue;
|
||||
Tx = tx;
|
||||
<<<<<<< HEAD
|
||||
if ( myAddtomempool(Tx) == false ) // happens with out of order tx in block on resync
|
||||
=======
|
||||
if ( myAddtomempool(Tx) == false ) // can happen with out of order tx in block on resync
|
||||
>>>>>>> jl777
|
||||
rejects++;
|
||||
}
|
||||
if ( rejects == 0 || rejects == lastrejects )
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "notarisationdb.h"
|
||||
#include "uint256.h"
|
||||
#include "cc/eval.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
@@ -82,3 +83,29 @@ void EraseBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBa
|
||||
batch.Erase(n.second.txHash);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan notarisationsdb backwards for blocks containing a notarisation
|
||||
* for given symbol. Return height of matched notarisation or 0.
|
||||
*/
|
||||
int ScanNotarisationsDB(int height, std::string symbol, int scanLimitBlocks, Notarisation& out)
|
||||
{
|
||||
if (height < 0 || height > chainActive.Height())
|
||||
return false;
|
||||
|
||||
for (int i=0; i<scanLimitBlocks; i++) {
|
||||
if (i > height) break;
|
||||
NotarisationsInBlock notarisations;
|
||||
uint256 blockHash = *chainActive[height-i]->phashBlock;
|
||||
if (!GetBlockNotarisations(blockHash, notarisations))
|
||||
continue;
|
||||
|
||||
BOOST_FOREACH(Notarisation& nota, notarisations) {
|
||||
if (strcmp(nota.second.symbol, symbol.data()) == 0) {
|
||||
out = nota;
|
||||
return height-i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -23,5 +23,6 @@ bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs);
|
||||
bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n);
|
||||
void WriteBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch);
|
||||
void EraseBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch);
|
||||
int ScanNotarisationsDB(int height, std::string symbol, int scanLimitBlocks, Notarisation& out);
|
||||
|
||||
#endif /* NOTARISATIONDB_H */
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "chainparams.h"
|
||||
#include "checkpoints.h"
|
||||
#include "crosschain.h"
|
||||
#include "notarisationdb.h"
|
||||
#include "importcoin.h"
|
||||
#include "base58.h"
|
||||
#include "consensus/validation.h"
|
||||
@@ -251,3 +252,55 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp)
|
||||
|
||||
return HexStr(E_MARSHAL(ss << importTx));
|
||||
}
|
||||
|
||||
|
||||
UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error("getNotarisationsForBlock blockHash\n\n"
|
||||
"Takes a block hash and returns notarisation transactions "
|
||||
"within the block");
|
||||
|
||||
uint256 blockHash = uint256S(params[0].get_str());
|
||||
|
||||
NotarisationsInBlock nibs;
|
||||
GetBlockNotarisations(blockHash, nibs);
|
||||
UniValue out(UniValue::VARR);
|
||||
BOOST_FOREACH(const Notarisation& n, nibs)
|
||||
{
|
||||
UniValue item(UniValue::VARR);
|
||||
item.push_back(n.first.GetHex());
|
||||
item.push_back(HexStr(E_MARSHAL(ss << n.second)));
|
||||
out.push_back(item);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
UniValue scanNotarisationsDB(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 2 || params.size() > 3)
|
||||
throw runtime_error("scanNotarisationsDB blockHeight symbol [blocksLimit=1440]\n\n"
|
||||
"Scans notarisationsdb backwards from height for a notarisation"
|
||||
" of given symbol");
|
||||
int height = atoi(params[0].get_str().c_str());
|
||||
std::string symbol = params[1].get_str().c_str();
|
||||
|
||||
int limit = 1440;
|
||||
if (params.size() > 2) {
|
||||
limit = atoi(params[2].get_str().c_str());
|
||||
}
|
||||
|
||||
if (height == 0) {
|
||||
height = chainActive.Height();
|
||||
}
|
||||
|
||||
Notarisation nota;
|
||||
int matchedHeight = ScanNotarisationsDB(height, symbol, limit, nota);
|
||||
if (!matchedHeight) return NullUniValue;
|
||||
UniValue out(UniValue::VOBJ);
|
||||
out.pushKV("height", matchedHeight);
|
||||
out.pushKV("hash", nota.first.GetHex());
|
||||
out.pushKV("opreturn", HexStr(E_MARSHAL(ss << nota.second)));
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
uint32_t komodo_segid32(char *coinaddr);
|
||||
int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height);
|
||||
int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp);
|
||||
#define KOMODO_VERSION "0.2.0"
|
||||
#define KOMODO_VERSION "0.2.1"
|
||||
extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
|
||||
extern uint32_t ASSETCHAINS_CC;
|
||||
extern uint32_t ASSETCHAINS_MAGIC;
|
||||
|
||||
@@ -313,6 +313,8 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "crosschain", "height_MoM", &height_MoM, true },
|
||||
{ "crosschain", "assetchainproof", &assetchainproof, true },
|
||||
{ "crosschain", "crosschainproof", &crosschainproof, true },
|
||||
{ "crosschain", "getNotarisationsForBlock", &getNotarisationsForBlock, true },
|
||||
{ "crosschain", "scanNotarisationsDB", &scanNotarisationsDB, true },
|
||||
{ "crosschain", "migrate_converttoexport", &migrate_converttoexport, true },
|
||||
{ "crosschain", "migrate_createimporttransaction", &migrate_createimporttransaction, true },
|
||||
{ "crosschain", "migrate_completeimporttransaction", &migrate_completeimporttransaction, true },
|
||||
|
||||
@@ -376,6 +376,8 @@ extern UniValue calc_MoM(const UniValue& params, bool fHelp);
|
||||
extern UniValue height_MoM(const UniValue& params, bool fHelp);
|
||||
extern UniValue assetchainproof(const UniValue& params, bool fHelp);
|
||||
extern UniValue crosschainproof(const UniValue& params, bool fHelp);
|
||||
extern UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp);
|
||||
extern UniValue scanNotarisationsDB(const UniValue& params, bool fHelp);
|
||||
extern UniValue migrate_converttoexport(const UniValue& params, bool fHelp);
|
||||
extern UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp);
|
||||
extern UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp);
|
||||
|
||||
@@ -55,6 +55,9 @@ std::string CCerror;
|
||||
// Private method:
|
||||
UniValue z_getoperationstatus_IMPL(const UniValue&, bool);
|
||||
|
||||
#define PLAN_NAME_MAX 8
|
||||
#define VALID_PLAN_NAME(x) (strlen(x) <= PLAN_NAME_MAX)
|
||||
|
||||
std::string HelpRequiringPassphrase()
|
||||
{
|
||||
return pwalletMain && pwalletMain->IsCrypted()
|
||||
@@ -5467,6 +5470,12 @@ UniValue dicefund(const UniValue& params, bool fHelp)
|
||||
maxbet = atof(params[3].get_str().c_str()) * COIN;
|
||||
maxodds = atol(params[4].get_str().c_str());
|
||||
timeoutblocks = atol(params[5].get_str().c_str());
|
||||
|
||||
if (!VALID_PLAN_NAME(name)) {
|
||||
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
|
||||
return(result);
|
||||
}
|
||||
|
||||
hex = DiceCreateFunding(0,name,funds,minbet,maxbet,maxodds,timeoutblocks);
|
||||
if (CCerror != "") {
|
||||
ERR_RESULT(CCerror);
|
||||
@@ -5491,6 +5500,10 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp)
|
||||
name = (char *)params[0].get_str().c_str();
|
||||
fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
amount = atof(params[2].get_str().c_str()) * COIN;
|
||||
if (!VALID_PLAN_NAME(name)) {
|
||||
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
|
||||
return(result);
|
||||
}
|
||||
if ( amount > 0 ) {
|
||||
hex = DiceAddfunding(0,name,fundingtxid,amount);
|
||||
if (CCerror != "") {
|
||||
@@ -5516,6 +5529,11 @@ UniValue dicebet(const UniValue& params, bool fHelp)
|
||||
fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
amount = atof(params[2].get_str().c_str()) * COIN;
|
||||
odds = atol(params[3].get_str().c_str());
|
||||
|
||||
if (!VALID_PLAN_NAME(name)) {
|
||||
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
|
||||
return(result);
|
||||
}
|
||||
if (amount > 0 && odds > 0) {
|
||||
hex = DiceBet(0,name,fundingtxid,amount,odds);
|
||||
if ( hex.size() > 0 )
|
||||
@@ -5539,6 +5557,10 @@ UniValue dicefinish(const UniValue& params, bool fHelp)
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
name = (char *)params[0].get_str().c_str();
|
||||
if (!VALID_PLAN_NAME(name)) {
|
||||
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
|
||||
return(result);
|
||||
}
|
||||
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);
|
||||
@@ -5563,6 +5585,10 @@ UniValue dicestatus(const UniValue& params, bool fHelp)
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
name = (char *)params[0].get_str().c_str();
|
||||
if (!VALID_PLAN_NAME(name)) {
|
||||
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
|
||||
return(result);
|
||||
}
|
||||
fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
memset(&bettxid,0,sizeof(bettxid));
|
||||
if ( params.size() == 3 )
|
||||
@@ -5686,9 +5712,14 @@ UniValue tokencreate(const UniValue& params, bool fHelp)
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
name = params[0].get_str();
|
||||
supply = atof(params[1].get_str().c_str()) * COIN;
|
||||
if ( name.size() == 0 || supply <= 0 )
|
||||
if ( name.size() == 0 || name.size() > 32)
|
||||
{
|
||||
result.push_back(Pair("error", "invalid parameter"));
|
||||
ERR_RESULT("Token name must not be empty and up to 32 characters");
|
||||
return(result);
|
||||
}
|
||||
if ( supply <= 0 )
|
||||
{
|
||||
ERR_RESULT("Token supply must be positive");
|
||||
return(result);
|
||||
}
|
||||
if ( params.size() == 3 )
|
||||
@@ -5696,7 +5727,7 @@ UniValue tokencreate(const UniValue& params, bool fHelp)
|
||||
description = params[2].get_str();
|
||||
if ( description.size() > 4096 )
|
||||
{
|
||||
result.push_back(Pair("error", "token description longer than 4096"));
|
||||
ERR_RESULT("Token description must be <= 4096 characters");
|
||||
return(result);
|
||||
}
|
||||
}
|
||||
@@ -5721,9 +5752,14 @@ UniValue tokentransfer(const UniValue& params, bool fHelp)
|
||||
tokenid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
std::vector<unsigned char> pubkey(ParseHex(params[1].get_str().c_str()));
|
||||
amount = atol(params[2].get_str().c_str());
|
||||
if ( tokenid == zeroid || amount <= 0 )
|
||||
if ( tokenid == zeroid )
|
||||
{
|
||||
result.push_back(Pair("error", "invalid parameter"));
|
||||
ERR_RESULT("invalid tokenid");
|
||||
return(result);
|
||||
}
|
||||
if ( amount <= 0 )
|
||||
{
|
||||
ERR_RESULT("amount must be positive");
|
||||
return(result);
|
||||
}
|
||||
hex = AssetTransfer(0,tokenid,pubkey,amount);
|
||||
@@ -5752,9 +5788,19 @@ UniValue tokenbid(const UniValue& params, bool fHelp)
|
||||
tokenid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
price = atof(params[2].get_str().c_str());
|
||||
bidamount = (price * numtokens) * COIN + 0.0000000049999;
|
||||
if ( tokenid == zeroid || tokenid == zeroid || price <= 0 || bidamount <= 0 )
|
||||
if ( price <= 0 )
|
||||
{
|
||||
result.push_back(Pair("error", "invalid parameter"));
|
||||
ERR_RESULT("price must be positive");
|
||||
return(result);
|
||||
}
|
||||
if ( tokenid == zeroid )
|
||||
{
|
||||
ERR_RESULT("invalid tokenid");
|
||||
return(result);
|
||||
}
|
||||
if ( bidamount <= 0 )
|
||||
{
|
||||
ERR_RESULT("bid amount must be positive");
|
||||
return(result);
|
||||
}
|
||||
hex = CreateBuyOffer(0,bidamount,tokenid,numtokens);
|
||||
@@ -5763,7 +5809,7 @@ UniValue tokenbid(const UniValue& params, bool fHelp)
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
} else result.push_back(Pair("error", "couldnt create bid"));
|
||||
} else ERR_RESULT("couldnt create bid");
|
||||
} else {
|
||||
ERR_RESULT("price and numtokens must be positive");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user