Merge pull request #1633 from jl777/jl777

Jl777
This commit is contained in:
jl777
2019-07-24 05:34:44 -11:00
committed by GitHub
19 changed files with 288 additions and 188 deletions

View File

@@ -28,7 +28,6 @@ std::string ImportGatewayWithdraw(uint64_t txfee,uint256 bindtxid,std::string re
std::string ImportGatewayPartialSign(uint64_t txfee,uint256 lasttxid,std::string refcoin, std::string hex);
std::string ImportGatewayCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string refcoin,std::string hex);
std::string ImportGatewayMarkDone(uint64_t txfee,uint256 completetxid,std::string refcoin);
UniValue ImportGatewayPendingDeposits(uint256 bindtxid,std::string refcoin);
UniValue ImportGatewayPendingWithdraws(uint256 bindtxid,std::string refcoin);
UniValue ImportGatewayProcessedWithdraws(uint256 bindtxid,std::string refcoin);
UniValue ImportGatewayExternalAddress(uint256 bindtxid,CPubKey pubkey);

View File

@@ -176,12 +176,14 @@ static const uint256 zeroid;
static uint256 ignoretxid;
static int32_t ignorevin;
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock);
bool NSPV_myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, int32_t &txheight, int32_t &currentheight);
int32_t is_hexstr(char *str,int32_t n);
bool myAddtomempool(CTransaction &tx, CValidationState *pstate = NULL, bool fSkipExpiry = false);
int64_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag,int32_t lockflag);
bool myIsutxo_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,int32_t vout);
bool mytxid_inmempool(uint256 txid);
int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout);
int32_t myGet_mempool_txs(std::vector<CTransaction> &txs,uint8_t evalcode,uint8_t funcid);
int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex);
int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp);

View File

@@ -444,12 +444,19 @@ std::vector<uint8_t> Mypubkey()
}
extern char NSPV_wifstr[],NSPV_pubkeystr[];
extern uint32_t NSPV_logintime;
#define NSPV_AUTOLOGOUT 777
bool Myprivkey(uint8_t myprivkey[])
{
char coinaddr[64],checkaddr[64]; std::string strAddress; char *dest; int32_t i,n; CBitcoinAddress address; CKeyID keyID; CKey vchSecret; uint8_t buf33[33];
if ( KOMODO_NSPV != 0 )
{
if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT )
{
fprintf(stderr,"need to be logged in to get myprivkey\n");
return false;
}
vchSecret = DecodeSecret(NSPV_wifstr);
memcpy(myprivkey,vchSecret.begin(),32);
//for (i=0; i<32; i++)
@@ -605,6 +612,32 @@ int32_t myIs_coinaddr_inmempoolvout(char const *logcategory,char *coinaddr)
return(0);
}
extern struct NSPV_mempoolresp NSPV_mempoolresult;
extern bool NSPV_evalcode_inmempool(uint8_t evalcode,uint8_t funcid);
int32_t myGet_mempool_txs(std::vector<CTransaction> &txs,uint8_t evalcode,uint8_t funcid)
{
int i=0;
if ( KOMODO_NSPV != 0 )
{
CTransaction tx; uint256 hashBlock;
NSPV_evalcode_inmempool(evalcode,funcid);
for (int i=0;i<NSPV_mempoolresult.numtxids;i++)
{
if (myGetTransaction(NSPV_mempoolresult.txids[i],tx,hashBlock)!=0) txs.push_back(tx);
}
return (NSPV_mempoolresult.numtxids);
}
BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx)
{
txs.push_back(e.GetTx());
i++;
}
return(i);
}
int32_t CCCointxidExists(char const *logcategory,uint256 cointxid)
{
char txidaddr[64]; std::string coin; int32_t numvouts; uint256 hashBlock;
@@ -634,33 +667,56 @@ uint256 BitcoinGetProofMerkleRoot(const std::vector<uint8_t> &proofData, std::ve
bool komodo_txnotarizedconfirmed(uint256 txid)
{
char str[65];
uint32_t confirms,notarized=0,txheight;
int32_t confirms,notarized=0,txheight=0,currentheight=0;;
CTransaction tx;
uint256 hashBlock;
CBlockIndex *pindex;
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
if ( myGetTransaction(txid,tx,hashBlock) == 0 )
if (KOMODO_NSPV!=0)
{
fprintf(stderr,"komodo_txnotarizedconfirmed cant find txid %s\n",txid.ToString().c_str());
return(0);
if ( NSPV_myGetTransaction(txid,tx,hashBlock,txheight,currentheight) == 0 )
{
fprintf(stderr,"komodo_txnotarizedconfirmed cant find txid %s\n",txid.ToString().c_str());
return(0);
}
else if (txheight<=0)
{
fprintf(stderr,"komodo_txnotarizedconfirmed no txheight.%d for txid %s\n",txheight,txid.ToString().c_str());
return(0);
}
else if (txheight>currentheight)
{
fprintf(stderr,"komodo_txnotarizedconfirmed backwards heights for txid %s hts.(%d %d)\n",txid.ToString().c_str(),txheight,currentheight);
return(0);
}
confirms=1 + currentheight - txheight;
}
else if ( hashBlock == zeroid )
else
{
fprintf(stderr,"komodo_txnotarizedconfirmed no hashBlock for txid %s\n",txid.ToString().c_str());
return(0);
if ( myGetTransaction(txid,tx,hashBlock) == 0 )
{
fprintf(stderr,"komodo_txnotarizedconfirmed cant find txid %s\n",txid.ToString().c_str());
return(0);
}
else if ( hashBlock == zeroid )
{
fprintf(stderr,"komodo_txnotarizedconfirmed no hashBlock for txid %s\n",txid.ToString().c_str());
return(0);
}
else if ( (pindex= komodo_blockindex(hashBlock)) == 0 || (txheight= pindex->GetHeight()) <= 0 )
{
fprintf(stderr,"komodo_txnotarizedconfirmed no txheight.%d %p for txid %s\n",txheight,pindex,txid.ToString().c_str());
return(0);
}
else if ( (pindex= chainActive.LastTip()) == 0 || pindex->GetHeight() < txheight )
{
fprintf(stderr,"komodo_txnotarizedconfirmed backwards heights for txid %s hts.(%d %d)\n",txid.ToString().c_str(),txheight,(int32_t)pindex->GetHeight());
return(0);
}
confirms=1 + pindex->GetHeight() - txheight;
}
else if ( (pindex= komodo_blockindex(hashBlock)) == 0 || (txheight= pindex->GetHeight()) <= 0 )
{
fprintf(stderr,"komodo_txnotarizedconfirmed no txheight.%d %p for txid %s\n",txheight,pindex,txid.ToString().c_str());
return(0);
}
else if ( (pindex= chainActive.LastTip()) == 0 || pindex->GetHeight() < txheight )
{
fprintf(stderr,"komodo_txnotarizedconfirmed backwards heights for txid %s hts.(%d %d)\n",txid.ToString().c_str(),txheight,(int32_t)pindex->GetHeight());
return(0);
}
confirms=1 + pindex->GetHeight() - txheight;
if ((sp= komodo_stateptr(symbol,dest)) != 0 && (notarized=sp->NOTARIZED_HEIGHT) > 0 && txheight > sp->NOTARIZED_HEIGHT) notarized=0;
#ifdef TESTMODE
notarized=0;

View File

@@ -431,12 +431,14 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C
{
txid=zeroid;
int32_t mindepth=CHANNELS_MAXPAYMENTS;
BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx)
std::vector<CTransaction> tmp_txs;
myGet_mempool_txs(tmp_txs,EVAL_CHANNELS,'P');
for (std::vector<CTransaction>::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++)
{
const CTransaction &txmempool = e.GetTx();
const CTransaction &txmempool = *it;
const uint256 &hash = txmempool.GetHash();
if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) != 0 &&
if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)=='P' &&
tmp_txid==openTx.GetHash() && param1 < mindepth)
{
txid=hash;
@@ -815,10 +817,10 @@ UniValue ChannelsList()
UniValue ChannelsInfo(uint256 channeltxid)
{
UniValue result(UniValue::VOBJ),array(UniValue::VARR); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid,tokenid;
UniValue result(UniValue::VOBJ),array(UniValue::VARR); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,tokenid;
struct CCcontract_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments;
int64_t param2,payment; CPubKey srcpub,destpub,mypk;
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex; std::vector<uint256> txids;
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex; std::vector<CTransaction> txs;
cp = CCinit(&C,EVAL_CHANNELS);
mypk = pubkey2pk(Mypubkey());
@@ -826,7 +828,7 @@ UniValue ChannelsInfo(uint256 channeltxid)
if (myGetTransaction(channeltxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 &&
(DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'O'))
{
GetCCaddress(cp,CCaddr,mypk);
GetCCaddress1of2(cp,CCaddr,srcpub,destpub);
Getscriptaddress(addr,CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG);
result.push_back(Pair("result","success"));
result.push_back(Pair("Channel CC address",CCaddr));
@@ -842,32 +844,33 @@ UniValue ChannelsInfo(uint256 channeltxid)
{
result.push_back(Pair("Denomination (satoshi)",i64tostr(param2)));
result.push_back(Pair("Amount (satoshi)",i64tostr(param1*param2)));
}
}
GetCCaddress(cp,CCaddr,mypk);
SetCCtxids(addressIndex,CCaddr,true);
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
{
if (myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 )
if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==channeltxid || tx.GetHash()==channeltxid))
txids.push_back(it->first.txhash);
if (myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && it->second==CC_MARKER_VALUE &&
DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==channeltxid || tx.GetHash()==channeltxid))
txs.push_back(tx);
}
BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx)
std::vector<CTransaction> tmp_txs;
myGet_mempool_txs(tmp_txs,EVAL_CHANNELS,'P');
for (std::vector<CTransaction>::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++)
{
const CTransaction &txmempool = e.GetTx();
const uint256 &hash = txmempool.GetHash();
const CTransaction &txmempool = *it;
if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) == 'P' && tmp_txid==channeltxid)
txids.push_back(hash);
txs.push_back(txmempool);
}
prevtxid=zeroid;
for (std::vector<uint256>::const_iterator it=txids.begin(); it!=txids.end(); it++)
for (std::vector<CTransaction>::const_iterator it=txs.begin(); it!=txs.end(); it++)
{
txid=*it;
if (txid!=prevtxid && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 )
tx=*it;
if ((numvouts= tx.vout.size()) > 0 )
{
UniValue obj(UniValue::VOBJ);
if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O' && tx.GetHash()==channeltxid)
{
obj.push_back(Pair("Open",txid.GetHex().data()));
obj.push_back(Pair("Open",tx.GetHash().GetHex().data()));
}
else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'P' && opentxid==channeltxid)
{
@@ -875,7 +878,7 @@ UniValue ChannelsInfo(uint256 channeltxid)
DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O')
{
Getscriptaddress(str,tx.vout[3].scriptPubKey);
obj.push_back(Pair("Payment",txid.GetHex().data()));
obj.push_back(Pair("Payment",tx.GetHash().GetHex().data()));
obj.push_back(Pair("Number of payments",param2));
obj.push_back(Pair("Amount",param2*payment));
obj.push_back(Pair("Destination",str));
@@ -885,18 +888,17 @@ UniValue ChannelsInfo(uint256 channeltxid)
}
else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'C' && opentxid==channeltxid)
{
obj.push_back(Pair("Close",txid.GetHex().data()));
obj.push_back(Pair("Close",tx.GetHash().GetHex().data()));
}
else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'R' && opentxid==channeltxid)
{
Getscriptaddress(str,tx.vout[2].scriptPubKey);
obj.push_back(Pair("Refund",txid.GetHex().data()));
obj.push_back(Pair("Refund",tx.GetHash().GetHex().data()));
obj.push_back(Pair("Amount",param1*param2));
obj.push_back(Pair("Destination",str));
}
array.push_back(obj);
}
prevtxid=txid;
}
result.push_back(Pair("Transactions",array));
}

View File

@@ -499,10 +499,11 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256
}
}
}
BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx)
std::vector<CTransaction> tmp_txs;
myGet_mempool_txs(tmp_txs,EVAL_GATEWAYS,'B');
for (std::vector<CTransaction>::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++)
{
const CTransaction &txmempool = e.GetTx();
const uint256 &hash = txmempool.GetHash();
const CTransaction &txmempool = *it;
if ((numvouts=txmempool.vout.size()) > 0 && DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)=='B')
if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) == 'B' &&
@@ -1164,7 +1165,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin
vout = (int32_t)it->first.index;
nValue = (int64_t)it->second.satoshis;
K=0;
if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 &&
if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 &&
(funcid=DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey))!=0 && (funcid=='W' || funcid=='P'))
{
if (funcid=='W' && DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmptokenid,tmpbindtxid,coin,withdrawpub,tmpamount)=='W'
@@ -1503,7 +1504,7 @@ UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin)
txid = it->first.txhash;
vout = (int32_t)it->first.index;
nValue = (int64_t)it->second.satoshis;
if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 &&
if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 &&
DecodeGatewaysDepositOpRet(tx.vout[numvouts-1].scriptPubKey,tmpbindtxid,coin,publishers,txids,height,cointxid,claimvout,hex,proof,destpub,amount) == 'D'
&& tmpbindtxid==bindtxid && refcoin == coin && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0)
{
@@ -1567,7 +1568,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin)
vout = (int32_t)it->first.index;
nValue = (int64_t)it->second.satoshis;
K=0;
if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 &&
if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 &&
(funcid=DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey))!=0 && (funcid=='W' || funcid=='P') && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0)
{
if (funcid=='W')
@@ -1654,7 +1655,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin)
txid = it->first.txhash;
vout = (int32_t)it->first.index;
nValue = (int64_t)it->second.satoshis;
if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 &&
if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 &&
DecodeGatewaysCompleteSigningOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,coin,K,hex) == 'S' && refcoin == coin && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0)
{
if (myGetTransaction(withdrawtxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0

View File

@@ -278,10 +278,11 @@ int32_t ImportGatewayBindExists(struct CCcontract_info *cp,CPubKey importgateway
}
}
}
BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx)
std::vector<CTransaction> tmp_txs;
myGet_mempool_txs(tmp_txs,EVAL_IMPORTGATEWAY,'B');
for (std::vector<CTransaction>::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++)
{
const CTransaction &txmempool = e.GetTx();
const uint256 &hash = txmempool.GetHash();
const CTransaction &txmempool = *it;
if ((numvouts=txmempool.vout.size()) > 0 && DecodeImportGatewayOpRet(tx.vout[numvouts-1].scriptPubKey)=='B')
if (DecodeImportGatewayBindOpRet(burnaddr,tx.vout[numvouts-1].scriptPubKey,coin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) == 'B')
@@ -568,7 +569,7 @@ std::string ImportGatewayDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,
if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID)
{
CCerror = strprintf("CheckGATEWAYimport invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex());
CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex());
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
@@ -645,6 +646,12 @@ std::string ImportGatewayWithdraw(uint64_t txfee,uint256 bindtxid,std::string re
std::vector<CPubKey> msigpubkeys; char burnaddr[64],str[65],coinaddr[64]; struct CCcontract_info *cp,C;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID)
{
CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex());
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
cp = CCinit(&C,EVAL_IMPORTGATEWAY);
if ( txfee == 0 )
txfee = 10000;
@@ -677,7 +684,7 @@ std::string ImportGatewayWithdraw(uint64_t txfee,uint256 bindtxid,std::string re
vout = (int32_t)it->first.index;
nValue = (int64_t)it->second.satoshis;
K=0;
if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 &&
if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 &&
(funcid=DecodeImportGatewayOpRet(tx.vout[numvouts-1].scriptPubKey))!=0 && (funcid=='W' || funcid=='P'))
{
if (funcid=='W' && DecodeImportGatewayWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmpbindtxid,coin,withdrawpub,tmpamount)=='W'
@@ -701,7 +708,7 @@ std::string ImportGatewayWithdraw(uint64_t txfee,uint256 bindtxid,std::string re
if( AddNormalinputs(mtx, mypk, txfee+CC_MARKER_VALUE+amount, 64) > 0 )
{
mtx.vout.push_back(MakeCC1vout(EVAL_IMPORTGATEWAY,CC_MARKER_VALUE,importgatewaypk));
mtx.vout.push_back(MakeCC1vout(EVAL_IMPORTGATEWAY,amount,importgatewaypk));
mtx.vout.push_back(MakeCC1vout(EVAL_IMPORTGATEWAY,amount,CCtxidaddr(str,bindtxid)));
return(FinalizeCCTx(0, cp, mtx, mypk, txfee,EncodeImportGatewayWithdrawOpRet('W',bindtxid,refcoin,withdrawpub,amount)));
}
CCerror = strprintf("cant find enough normal inputs");
@@ -738,6 +745,12 @@ std::string ImportGatewayPartialSign(uint64_t txfee,uint256 lasttxid,std::string
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
else if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID)
{
CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex());
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
else if (komodo_txnotarizedconfirmed(withdrawtxid)==false)
{
CCerror = strprintf("gatewayswithdraw tx not yet confirmed/notarized");
@@ -779,6 +792,12 @@ std::string ImportGatewayPartialSign(uint64_t txfee,uint256 lasttxid,std::string
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
else if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID)
{
CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex());
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
else if (komodo_txnotarizedconfirmed(withdrawtxid)==false)
{
CCerror = strprintf("gatewayswithdraw tx not yet confirmed/notarized");
@@ -844,12 +863,24 @@ std::string ImportGatewayCompleteSigning(uint64_t txfee,uint256 lasttxid,std::st
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
else if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID)
{
CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex());
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
else if (komodo_txnotarizedconfirmed(withdrawtxid)==false)
{
CCerror = strprintf("gatewayswithdraw tx not yet confirmed/notarized");
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
else if (GetTransaction(bindtxid,tmptx,hashBlock,false)==0 || (numvouts=tmptx.vout.size())<=0)
{
CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid));
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
else if (DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,coin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B'
|| refcoin!=coin)
{
@@ -878,6 +909,12 @@ std::string ImportGatewayCompleteSigning(uint64_t txfee,uint256 lasttxid,std::st
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
else if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID)
{
CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex());
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
else if (komodo_txnotarizedconfirmed(withdrawtxid)==false)
{
CCerror = strprintf("gatewayswithdraw tx not yet confirmed/notarized");
@@ -950,6 +987,12 @@ std::string ImportGatewayMarkDone(uint64_t txfee,uint256 completetxid,std::strin
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
else if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID)
{
CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex());
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
else if (myGetTransaction(bindtxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0)
{
CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid));
@@ -974,61 +1017,6 @@ std::string ImportGatewayMarkDone(uint64_t txfee,uint256 completetxid,std::strin
return("");
}
UniValue ImportGatewayPendingDeposits(uint256 bindtxid,std::string refcoin)
{
UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,hex,pub;
CPubKey mypk,importgatewaypk,destpub; std::vector<CPubKey> pubkeys,publishers; std::vector<uint256> txids;
uint256 tmpbindtxid,hashBlock,txid,oracletxid,burntxid; uint8_t M,N,taddr,prefix,prefix2,wiftype;
char burnaddr[65],coinaddr[65],str[65],destaddr[65],txidaddr[65]; std::vector<uint8_t> proof;
int32_t numvouts,vout,claimvout,height; int64_t nValue,amount; struct CCcontract_info *cp,C;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
cp = CCinit(&C,EVAL_IMPORTGATEWAY);
mypk = pubkey2pk(Mypubkey());
importgatewaypk = GetUnspendable(cp,0);
_GetCCaddress(coinaddr,EVAL_IMPORTGATEWAY,mypk);
if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 )
{
CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid));
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
if ( DecodeImportGatewayBindOpRet(burnaddr,tx.vout[numvouts-1].scriptPubKey,coin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin != coin)
{
CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str());
LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl);
return("");
}
SetCCunspents(unspentOutputs,coinaddr,true);
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
{
txid = it->first.txhash;
vout = (int32_t)it->first.index;
nValue = (int64_t)it->second.satoshis;
if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 &&
DecodeImportGatewayDepositOpRet(tx.vout[numvouts-1].scriptPubKey,tmpbindtxid,coin,publishers,txids,height,burntxid,claimvout,hex,proof,destpub,amount) == 'D'
&& tmpbindtxid==bindtxid && refcoin == coin && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0)
{
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("burntxid",uint256_str(str,burntxid)));
obj.push_back(Pair("deposittxid",uint256_str(str,txid)));
CCtxidaddr(txidaddr,txid);
obj.push_back(Pair("deposittxidaddr",txidaddr));
_GetCCaddress(destaddr,EVAL_TOKENS,destpub);
obj.push_back(Pair("depositaddr",burnaddr));
obj.push_back(Pair("tokens_destination_address",destaddr));
pub=HexStr(destpub);
obj.push_back(Pair("claim_pubkey",pub));
obj.push_back(Pair("amount",(double)amount/COIN));
obj.push_back(Pair("confirmed_or_notarized",komodo_txnotarizedconfirmed(txid)));
pending.push_back(obj);
}
}
result.push_back(Pair("coin",refcoin));
result.push_back(Pair("pending",pending));
return(result);
}
UniValue ImportGatewayPendingWithdraws(uint256 bindtxid,std::string refcoin)
{
UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,hex; CPubKey mypk,importgatewaypk,withdrawpub,signerpk;
@@ -1068,7 +1056,7 @@ UniValue ImportGatewayPendingWithdraws(uint256 bindtxid,std::string refcoin)
vout = (int32_t)it->first.index;
nValue = (int64_t)it->second.satoshis;
K=0;
if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 &&
if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 &&
(funcid=DecodeImportGatewayOpRet(tx.vout[numvouts-1].scriptPubKey))!=0 && (funcid=='W' || funcid=='P') && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0)
{
if (funcid=='W')
@@ -1155,7 +1143,7 @@ UniValue ImportGatewayProcessedWithdraws(uint256 bindtxid,std::string refcoin)
txid = it->first.txhash;
vout = (int32_t)it->first.index;
nValue = (int64_t)it->second.satoshis;
if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 &&
if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 &&
DecodeImportGatewayCompleteSigningOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,coin,K,hex) == 'S' && refcoin == coin && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0)
{
if (myGetTransaction(withdrawtxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0

View File

@@ -247,9 +247,11 @@ int64_t OracleDatafee(CScript &scriptPubKey,uint256 oracletxid,CPubKey publisher
static uint256 myIs_baton_spentinmempool(uint256 batontxid,int32_t batonvout)
{
BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx)
std::vector<CTransaction> tmp_txs;
myGet_mempool_txs(tmp_txs,EVAL_ORACLES,'D');
for (std::vector<CTransaction>::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++)
{
const CTransaction &tx = e.GetTx();
const CTransaction &tx = *it;
if ( tx.vout.size() > 0 && tx.vin.size() > 1 && batontxid == tx.vin[1].prevout.hash && batonvout == tx.vin[1].prevout.n )
{
const uint256 &txid = tx.GetHash();
@@ -830,9 +832,11 @@ int64_t AddMyOraclesFunds(struct CCcontract_info *cp,CMutableTransaction &mtx,CP
} else fprintf(stderr,"couldnt find transaction\n");
}
BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx)
std::vector<CTransaction> tmp_txs;
myGet_mempool_txs(tmp_txs,EVAL_ORACLES,'F');
for (std::vector<CTransaction>::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++)
{
const CTransaction &txmempool = e.GetTx();
const CTransaction &txmempool = *it;
const uint256 &hash = txmempool.GetHash();
nValue=txmempool.vout[0].nValue;
@@ -1099,9 +1103,11 @@ UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num)
{
if ( DecodeOraclesCreateOpRet(oracletx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' )
{
BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx)
std::vector<CTransaction> tmp_txs;
myGet_mempool_txs(tmp_txs,EVAL_ORACLES,'D');
for (std::vector<CTransaction>::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++)
{
const CTransaction &txmempool = e.GetTx();
const CTransaction &txmempool = *it;
const uint256 &hash = txmempool.GetHash();
if ((numvouts=txmempool.vout.size())>0 && DecodeOraclesData(txmempool.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D' && reforacletxid == oracletxid )
{

View File

@@ -470,7 +470,7 @@ std::string PegsDecodeAccountTx(CTransaction tx,CPubKey& pk,int64_t &amount,std:
char PegsFindAccount(struct CCcontract_info *cp,CPubKey pk,uint256 pegstxid, uint256 tokenid, uint256 &accounttxid, std::pair<int64_t,int64_t> &account)
{
char coinaddr[64]; int64_t nValue,tmpamount; uint256 txid,hashBlock,tmptokenid,tmppegstxid;
char coinaddr[64]; int64_t nValue,tmpamount; uint256 txid,spenttxid,hashBlock,tmptokenid,tmppegstxid;
CTransaction tx,acctx; int32_t numvouts,vout,ratio; char funcid,f; CPubKey pegspk,tmppk;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
ImportProof proof; CTransaction burntx; std::vector<CTxOut> payouts;
@@ -493,20 +493,15 @@ char PegsFindAccount(struct CCcontract_info *cp,CPubKey pk,uint256 pegstxid, uin
acctx=tx;
}
}
if (accounttxid!=zeroid && myIsutxo_spentinmempool(ignoretxid,ignorevin,accounttxid,1) != 0)
if (accounttxid!=zeroid && myIsutxo_spentinmempool(spenttxid,ignorevin,accounttxid,1) != 0)
{
accounttxid=zeroid;
BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx)
if (myGetTransaction(spenttxid,tx,hashBlock)!=0 && (numvouts=tx.vout.size()) > 0 &&
(f=DecodePegsOpRet(tx,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid && tokenid==tmptokenid)
{
const CTransaction &txmempool = e.GetTx();
const uint256 &hash = txmempool.GetHash();
if ((numvouts=txmempool.vout.size()) > 0 && (f=DecodePegsOpRet(txmempool,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid && tokenid==tmptokenid)
{
funcid=f;
accounttxid=hash;
acctx=txmempool;
}
funcid=f;
accounttxid=spenttxid;
acctx=tx;
}
}
if (accounttxid!=zeroid)

View File

@@ -101,7 +101,7 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->total),&ptr->total);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->interest),&ptr->interest);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->filter),&ptr->filter);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->skipcount),&ptr->skipcount);
if ( rwflag != 0 )
@@ -159,7 +159,7 @@ int32_t NSPV_rwtxidsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_txidsres
len += NSPV_rwtxidresp(rwflag,&serialized[len],&ptr->txids[i]);
}
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->filter),&ptr->filter);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->skipcount),&ptr->skipcount);
if ( rwflag != 0 )
@@ -305,7 +305,7 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout);
len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx);
len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof);
fprintf(stderr,"len %d\n",len);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->hashblock),(uint8_t *)&ptr->hashblock);
return(len);
}
@@ -517,11 +517,11 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33],uint32_t
*/
int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33])
{
uint8_t *script; CTransaction vintx; int64_t rewardsum = 0; int32_t i,j,utxovout,scriptlen,numsigs = 0;
uint8_t *script; CTransaction vintx; int64_t rewardsum = 0; int32_t i,j,utxovout,scriptlen,numsigs = 0,txheight,currentheight; uint256 hashBlock;
for (i=0; i<tx.vin.size(); i++)
{
utxovout = tx.vin[i].prevout.n;
if ( NSPV_gettransaction(1,utxovout,tx.vin[i].prevout.hash,0,vintx,-1,0,rewardsum) != 0 )
if ( NSPV_gettransaction(1,utxovout,tx.vin[i].prevout.hash,0,vintx,hashBlock,txheight,currentheight,-1,0,rewardsum) != 0 )
{
fprintf(stderr,"error getting %s/v%d\n",tx.vin[i].prevout.hash.GetHex().c_str(),utxovout);
return(numsigs);

View File

@@ -18,7 +18,7 @@
#define KOMODO_NSPV_DEFSH
#define NSPV_POLLITERS 100
#define NSPV_POLLMICROS 10000
#define NSPV_POLLMICROS 30000
#define NSPV_MAXVINS 64
#define NSPV_AUTOLOGOUT 777
#define NSPV_BRANCHID 0x76b809bb
@@ -49,7 +49,7 @@
#define NSPV_MEMPOOL_INMEMPOOL 3
#define NSPV_MEMPOOL_CCEVALCODE 4
int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum);
int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,uint256 &hashblock,int32_t &txheight,int32_t &currentheight,int64_t extradata,uint32_t tiptime,int64_t &rewardsum);
UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis);
extern uint256 SIG_TXHASH;
uint32_t NSPV_blocktime(int32_t hdrheight);
@@ -78,7 +78,7 @@ struct NSPV_utxosresp
struct NSPV_utxoresp *utxos;
char coinaddr[64];
int64_t total,interest;
int32_t nodeheight,skipcount,pad32;
int32_t nodeheight,skipcount,filter;
uint16_t numutxos,CCflag;
};
@@ -93,7 +93,7 @@ struct NSPV_txidsresp
{
struct NSPV_txidresp *txids;
char coinaddr[64];
int32_t nodeheight,skipcount,pad32;
int32_t nodeheight,skipcount,filter;
uint16_t numtxids,CCflag;
};
@@ -132,6 +132,7 @@ struct NSPV_txproof
int64_t unspentvalue;
int32_t height,vout,txlen,txprooflen;
uint8_t *tx,*txproof;
uint256 hashblock;
};
struct NSPV_ntzproofshared

View File

@@ -139,7 +139,7 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight)
} else return(-1);
}
int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC,int32_t skipcount) // check mempool
int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC,int32_t skipcount,uint32_t filter)
{
int64_t total = 0,interest=0; uint32_t locktime; int32_t ind=0,tipheight,maxlen,txheight,n = 0,len = 0;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
@@ -148,6 +148,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC
maxlen /= sizeof(*ptr->utxos);
strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1);
ptr->CCflag = isCC;
ptr->filter = filter;
if ( skipcount < 0 )
skipcount = 0;
if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) >= 0 && ptr->numutxos < maxlen )
@@ -198,7 +199,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC
return(0);
}
int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC,int32_t skipcount)
int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC,int32_t skipcount,uint32_t filter)
{
int32_t maxlen,txheight,ind=0,n = 0,len = 0;
std::vector<std::pair<CAddressIndexKey, CAmount> > txids;
@@ -208,6 +209,7 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC
maxlen /= sizeof(*ptr->txids);
strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1);
ptr->CCflag = isCC;
ptr->filter = filter;
if ( skipcount < 0 )
skipcount = 0;
if ( (ptr->numtxids= (int32_t)txids.size()) >= 0 && ptr->numtxids < maxlen )
@@ -408,6 +410,7 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32
return(-1);
ptr->txid = txid;
ptr->vout = vout;
ptr->hashblock = hashBlock;
if ( height == 0 )
ptr->height = komodo_blockheight(hashBlock);
else
@@ -550,23 +553,29 @@ void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> request) // received a req
//fprintf(stderr,"utxos: %u > %u, ind.%d, len.%d\n",timestamp,pfrom->prevtimes[ind],ind,len);
if ( timestamp > pfrom->prevtimes[ind] )
{
struct NSPV_utxosresp U; char coinaddr[64];
if ( len < 64 && (request[1] == len-3 || request[1] == len-7) )
struct NSPV_utxosresp U;
if ( len < 64+5 && (request[1] == len-3 || request[1] == len-7 || request[1] == len-11) )
{
int32_t skipcount = 0; uint8_t isCC = 0;
int32_t skipcount = 0; char coinaddr[64]; uint8_t filter; uint8_t isCC = 0;
memcpy(coinaddr,&request[2],request[1]);
coinaddr[request[1]] = 0;
if ( request[1] == len-3 )
isCC = (request[len-1] != 0);
else
else if ( request[1] == len-7 )
{
isCC = (request[len-5] != 0);
iguana_rwnum(0,&request[len-4],sizeof(skipcount),&skipcount);
}
else
{
isCC = (request[len-9] != 0);
iguana_rwnum(0,&request[len-4],sizeof(skipcount),&skipcount);
iguana_rwnum(0,&request[len-4],sizeof(filter),&filter);
}
if ( isCC != 0 )
fprintf(stderr,"%s isCC.%d skipcount.%d\n",coinaddr,isCC,skipcount);
fprintf(stderr,"utxos %s isCC.%d skipcount.%d filter.%x\n",coinaddr,isCC,skipcount,filter);
memset(&U,0,sizeof(U));
if ( (slen= NSPV_getaddressutxos(&U,coinaddr,isCC,skipcount)) > 0 )
if ( (slen= NSPV_getaddressutxos(&U,coinaddr,isCC,skipcount,filter)) > 0 )
{
response.resize(1 + slen);
response[0] = NSPV_UTXOSRESP;
@@ -584,23 +593,29 @@ void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> request) // received a req
{
if ( timestamp > pfrom->prevtimes[ind] )
{
struct NSPV_txidsresp T; char coinaddr[64];
if ( len < 64+5 && (request[1] == len-3 || request[1] == len-7) )
struct NSPV_txidsresp T;
if ( len < 64+5 && (request[1] == len-3 || request[1] == len-7 || request[1] == len-11) )
{
int32_t skipcount = 0; uint8_t isCC = 0;
int32_t skipcount = 0; char coinaddr[64]; uint32_t filter; uint8_t isCC = 0;
memcpy(coinaddr,&request[2],request[1]);
coinaddr[request[1]] = 0;
if ( request[1] == len-3 )
isCC = (request[len-1] != 0);
else
else if ( request[1] == len-7 )
{
isCC = (request[len-5] != 0);
iguana_rwnum(0,&request[len-4],sizeof(skipcount),&skipcount);
}
else
{
isCC = (request[len-9] != 0);
iguana_rwnum(0,&request[len-4],sizeof(skipcount),&skipcount);
iguana_rwnum(0,&request[len-4],sizeof(filter),&filter);
}
//if ( isCC != 0 )
fprintf(stderr,"%s isCC.%d skipcount.%d\n",coinaddr,isCC,skipcount);
fprintf(stderr,"txids %s isCC.%d skipcount.%d filter.%d\n",coinaddr,isCC,skipcount,filter);
memset(&T,0,sizeof(T));
if ( (slen= NSPV_getaddresstxids(&T,coinaddr,isCC,skipcount)) > 0 )
if ( (slen= NSPV_getaddresstxids(&T,coinaddr,isCC,skipcount,filter)) > 0 )
{
//fprintf(stderr,"slen.%d\n",slen);
response.resize(1 + slen);

View File

@@ -403,6 +403,7 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr)
result.push_back(Pair("balance",(double)ptr->total/COIN));
if ( ASSETCHAINS_SYMBOL[0] == 0 )
result.push_back(Pair("interest",(double)ptr->interest/COIN));
result.push_back(Pair("filter",(int64_t)ptr->filter));
result.push_back(Pair("lastpeer",NSPV_lastpeer));
return(result);
}
@@ -433,6 +434,7 @@ UniValue NSPV_txidsresp_json(struct NSPV_txidsresp *ptr)
result.push_back(Pair("isCC",ptr->CCflag));
result.push_back(Pair("height",(int64_t)ptr->nodeheight));
result.push_back(Pair("numtxids",(int64_t)ptr->numtxids));
result.push_back(Pair("filter",(int64_t)ptr->filter));
result.push_back(Pair("lastpeer",NSPV_lastpeer));
return(result);
}
@@ -580,7 +582,7 @@ uint32_t NSPV_blocktime(int32_t hdrheight)
return(0);
}
UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount)
UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter)
{
UniValue result(UniValue::VOBJ); uint8_t msg[512]; int32_t i,iter,slen,len = 0;
//fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str());
@@ -601,6 +603,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount)
memcpy(&msg[len],coinaddr,slen), len += slen;
msg[len++] = (CCflag != 0);
len += iguana_rwnum(1,&msg[len],sizeof(skipcount),&skipcount);
len += iguana_rwnum(1,&msg[len],sizeof(filter),&filter);
for (iter=0; iter<3; iter++)
if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 )
{
@@ -617,7 +620,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount)
return(result);
}
UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount)
UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter)
{
UniValue result(UniValue::VOBJ); uint8_t msg[512]; int32_t i,iter,slen,len = 0;
if ( NSPV_txidsresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag && skipcount == NSPV_txidsresult.skipcount )
@@ -637,6 +640,7 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount)
memcpy(&msg[len],coinaddr,slen), len += slen;
msg[len++] = (CCflag != 0);
len += iguana_rwnum(1,&msg[len],sizeof(skipcount),&skipcount);
len += iguana_rwnum(1,&msg[len],sizeof(filter),&filter);
//fprintf(stderr,"skipcount.%d\n",skipcount);
for (iter=0; iter<3; iter++)
if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 )

View File

@@ -58,7 +58,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr)
return(0);
}
int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum)
int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,uint256 &hashblock,int32_t &txheight,int32_t &currentheight,int64_t extradata,uint32_t tiptime,int64_t &rewardsum)
{
struct NSPV_txproof *ptr; int32_t i,offset,retval; int64_t rewards = 0; uint32_t nLockTime; std::vector<uint8_t> proof;
retval = skipvalidation != 0 ? 0 : -1;
@@ -69,6 +69,9 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int
NSPV_txproof(vout,txid,height);
ptr = &NSPV_txproofresult;
}
hashblock=ptr->hashblock;
txheight=ptr->height;
currentheight=NSPV_inforesult.height;
if ( ptr->txid != txid )
{
fprintf(stderr,"txproof error %s != %s\n",ptr->txid.GetHex().c_str(),txid.GetHex().c_str());
@@ -236,6 +239,11 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64
bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey,uint32_t nTime)
{
CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; int64_t branchid = NSPV_BRANCHID;
if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT )
{
fprintf(stderr,"need to be logged in to get myprivkey\n");
return false;
}
keystore.AddKey(NSPV_key);
if ( nTime != 0 && nTime < KOMODO_SAPLING_ACTIVATION )
{
@@ -253,7 +261,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C
std::string NSPV_signtx(int64_t &rewardsum,int64_t &interestsum,UniValue &retcodes,CMutableTransaction &mtx,uint64_t txfee,CScript opret,struct NSPV_utxoresp used[])
{
CTransaction vintx; std::string hex; uint256 hashBlock; int64_t interest=0,change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n,validation;
CTransaction vintx; std::string hex; uint256 hashBlock; int64_t interest=0,change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n,validation,txheight,currentheight;
n = mtx.vout.size();
for (i=0; i<n; i++)
totaloutputs += mtx.vout[i].nValue;
@@ -276,7 +284,7 @@ std::string NSPV_signtx(int64_t &rewardsum,int64_t &interestsum,UniValue &retcod
utxovout = mtx.vin[i].prevout.n;
if ( i > 0 )
sleep(1);
validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx,used[i].extradata,NSPV_tiptime,rewardsum);
validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx,hashBlock,txheight,currentheight,used[i].extradata,NSPV_tiptime,rewardsum);
retcodes.push_back(validation);
if ( validation != -1 ) // most others are degraded security
{
@@ -355,7 +363,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a
return(result);
}
if ( NSPV_utxosresult.CCflag != 0 || strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height )
NSPV_addressutxos(srcaddr,0,0);
NSPV_addressutxos(srcaddr,0,0,0);
if ( NSPV_utxosresult.CCflag != 0 || strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height )
{
result.push_back(Pair("result","error"));
@@ -446,7 +454,7 @@ int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total
Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG);
if ( strcmp(ptr->U.coinaddr,coinaddr) != 0 )
{
NSPV_addressutxos(coinaddr,CCflag,0);
NSPV_addressutxos(coinaddr,CCflag,0,0);
NSPV_utxosresp_purge(&ptr->U);
NSPV_utxosresp_copy(&ptr->U,&NSPV_utxosresult);
}
@@ -506,13 +514,15 @@ void NSPV_txids2CCtxids(struct NSPV_txidsresp *ptr,std::vector<std::pair<CAddres
void NSPV_CCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &outputs,char *coinaddr,bool ccflag)
{
NSPV_addressutxos(coinaddr,ccflag,0);
int32_t filter = 0;
NSPV_addressutxos(coinaddr,ccflag,0,filter);
NSPV_utxos2CCunspents(&NSPV_utxosresult,outputs);
}
void NSPV_CCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &txids,char *coinaddr,bool ccflag)
{
NSPV_addresstxids(coinaddr,ccflag,0);
int32_t filter = 0;
NSPV_addresstxids(coinaddr,ccflag,0,filter);
NSPV_txids2CCtxids(&NSPV_txidsresult,txids);
}

View File

@@ -1700,6 +1700,7 @@ void komodo_args(char *argv0)
KOMODO_NSPV = GetArg("-nSPV",0);
memset(ccenables,0,sizeof(ccenables));
memset(disablebits,0,sizeof(disablebits));
memset(ccEnablesHeight,0,sizeof(ccEnablesHeight));
if ( GetBoolArg("-gen", false) != 0 )
{
KOMODO_MININGTHREADS = GetArg("-genproclimit",-1);
@@ -2296,10 +2297,18 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen);
//printf("created (%s)\n",fname);
} else printf("error creating (%s)\n",fname);
#endif
if ( KOMODO_CCACTIVATE != 0 && ASSETCHAINS_CC < 2 )
if ( ASSETCHAINS_CC < 2 )
{
ASSETCHAINS_CC = 2;
fprintf(stderr,"smart utxo CC contracts will activate at height.%d\n",KOMODO_CCACTIVATE);
if ( KOMODO_CCACTIVATE != 0 )
{
ASSETCHAINS_CC = 2;
fprintf(stderr,"smart utxo CC contracts will activate at height.%d\n",KOMODO_CCACTIVATE);
}
else if ( ccEnablesHeight[0] != 0 )
{
ASSETCHAINS_CC = 2;
fprintf(stderr,"smart utxo CC contract %d will activate at height.%d\n",(int32_t)ccEnablesHeight[0],(int32_t)ccEnablesHeight[1]);
}
}
}
else

View File

@@ -2229,14 +2229,14 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo
memset(&hashBlock,0,sizeof(hashBlock));
if ( KOMODO_NSPV != 0 )
{
int64_t rewardsum = 0; int32_t i,retval,txheight = 0,vout = 0;
int64_t rewardsum = 0; int32_t i,retval,txheight,currentheight,height=0,vout = 0;
for (i=0; i<NSPV_U.U.numutxos; i++)
if ( NSPV_U.U.utxos[i].txid == hash )
{
txheight = NSPV_U.U.utxos[i].height;
height = NSPV_U.U.utxos[i].height;
break;
}
retval = NSPV_gettransaction(1,vout,hash,txheight,txOut,0,0,rewardsum);
retval = NSPV_gettransaction(1,vout,hash,height,txOut,hashBlock,txheight,currentheight,0,0,rewardsum);
return(retval != -1);
}
// need a GetTransaction without lock so the validation code for assets can run without deadlock
@@ -2278,6 +2278,24 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo
return false;
}
bool NSPV_myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, int32_t &txheight, int32_t &currentheight)
{
memset(&hashBlock,0,sizeof(hashBlock));
if ( KOMODO_NSPV != 0 )
{
int64_t rewardsum = 0; int32_t i,retval,height=0,vout = 0;
for (i=0; i<NSPV_U.U.numutxos; i++)
if ( NSPV_U.U.utxos[i].txid == hash )
{
height = NSPV_U.U.utxos[i].height;
break;
}
retval = NSPV_gettransaction(1,vout,hash,height,txOut,hashBlock,txheight,currentheight,0,0,rewardsum);
return(retval != -1);
}
return false;
}
/** Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock */
bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow)
{

View File

@@ -754,6 +754,10 @@ UniValue selfimport(const UniValue& params, bool fHelp)
// return(0);
return -1;
}
else if (source == "PEGSCC")
{
return -1;
}
else if (source == "PUBKEY")
{
ImportProof proofNull;
@@ -833,6 +837,10 @@ UniValue importdual(const UniValue& params, bool fHelp)
// confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn
// return(0);
}
else if (source == "PEGSCC")
{
return -1;
}
RETURN_IF_ERROR(CCerror);
if ( hex.size() > 0 )
{
@@ -1054,18 +1062,6 @@ UniValue importgatewaymarkdone(const UniValue& params, bool fHelp)
return(result);
}
UniValue importgatewaypendingdeposits(const UniValue& params, bool fHelp)
{
uint256 bindtxid; std::string coin;
if ( fHelp || params.size() != 2 )
throw runtime_error("importgatewaypendingdeposits bindtxid coin\n");
if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
bindtxid = Parseuint256((char *)params[0].get_str().c_str());
coin = params[1].get_str();
return(ImportGatewayPendingDeposits(bindtxid,coin));
}
UniValue importgatewaypendingwithdraws(const UniValue& params, bool fHelp)
{
uint256 bindtxid; std::string coin;

View File

@@ -370,7 +370,6 @@ static const CRPCCommand vRPCCommands[] =
{ "crosschain", "importgatewaypartialsign", &importgatewaypartialsign, true },
{ "crosschain", "importgatewaycompletesigning", &importgatewaycompletesigning, true },
{ "crosschain", "importgatewaymarkdone", &importgatewaymarkdone, true },
{ "crosschain", "importgatewaypendingdeposits", &importgatewaypendingdeposits, true },
{ "crosschain", "importgatewaypendingwithdraws", &importgatewaypendingwithdraws, true },
{ "crosschain", "importgatewayprocessed", &importgatewayprocessed, true },

View File

@@ -461,7 +461,6 @@ extern UniValue importgatewaywithdraw(const UniValue& params, bool fHelp);
extern UniValue importgatewaypartialsign(const UniValue& params, bool fHelp);
extern UniValue importgatewaycompletesigning(const UniValue& params, bool fHelp);
extern UniValue importgatewaymarkdone(const UniValue& params, bool fHelp);
extern UniValue importgatewaypendingdeposits(const UniValue& params, bool fHelp);
extern UniValue importgatewaypendingwithdraws(const UniValue& params, bool fHelp);
extern UniValue importgatewayprocessed(const UniValue& params, bool fHelp);

View File

@@ -976,8 +976,8 @@ extern int32_t KOMODO_NSPV;
UniValue NSPV_getinfo_req(int32_t reqht);
UniValue NSPV_login(char *wifstr);
UniValue NSPV_logout();
UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount);
UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount);
UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter);
UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter);
UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 txid,int32_t vout);
UniValue NSPV_broadcast(char *hex);
UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis);
@@ -1028,7 +1028,7 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp)
if ( params.size() == 0 )
{
if ( NSPV_address.size() != 0 )
return(NSPV_addressutxos((char *)NSPV_address.c_str(),0,0));
return(NSPV_addressutxos((char *)NSPV_address.c_str(),0,0,0));
else throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n");
}
if ( params.size() >= 1 )
@@ -1037,7 +1037,7 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp)
CCflag = atoi((char *)params[1].get_str().c_str());
if ( params.size() == 3 )
skipcount = atoi((char *)params[2].get_str().c_str());
return(NSPV_addressutxos((char *)params[0].get_str().c_str(),CCflag,skipcount));
return(NSPV_addressutxos((char *)params[0].get_str().c_str(),CCflag,skipcount,0));
}
else throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n");
}
@@ -1073,7 +1073,7 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp)
if ( params.size() == 0 )
{
if ( NSPV_address.size() != 0 )
return(NSPV_addresstxids((char *)NSPV_address.c_str(),0,0));
return(NSPV_addresstxids((char *)NSPV_address.c_str(),0,0,0));
else throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n");
}
if ( params.size() >= 1 )
@@ -1083,7 +1083,7 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp)
if ( params.size() == 3 )
skipcount = atoi((char *)params[2].get_str().c_str());
//fprintf(stderr,"call txids cc.%d skip.%d\n",CCflag,skipcount);
return(NSPV_addresstxids((char *)params[0].get_str().c_str(),CCflag,skipcount));
return(NSPV_addresstxids((char *)params[0].get_str().c_str(),CCflag,skipcount,0));
}
else throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n");
}