Fix SetCCtxids for nSPV (#31)
This commit is contained in:
committed by
GitHub
parent
ad5f6f8489
commit
feb16224f8
@@ -292,7 +292,7 @@ extern std::vector<CPubKey> NULL_pubkeys;
|
||||
std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector<CPubKey> pubkeys = NULL_pubkeys);
|
||||
void SetCCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs,char *coinaddr,bool CCflag = true);
|
||||
void SetCCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,char *coinaddr,bool CCflag = true);
|
||||
void SetCCtxids_NSPV(std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,char *coinaddr,bool ccflag, uint8_t evalcode, uint256 filtertxid);
|
||||
void SetCCtxids(std::vector<uint256> &txids,char *coinaddr,bool ccflag, uint8_t evalcode, uint256 filtertxid, uint8_t func);
|
||||
int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr);
|
||||
int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs);
|
||||
int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs);
|
||||
|
||||
@@ -340,7 +340,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
|
||||
|
||||
void NSPV_CCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs,char *coinaddr,bool ccflag);
|
||||
void NSPV_CCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &txids,char *coinaddr,bool ccflag);
|
||||
void NSPV_CCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &txids,char *coinaddr,bool ccflag,uint8_t evalcode,uint256 filtertxid);
|
||||
void NSPV_CCtxids(std::vector<uint256> &txids,char *coinaddr,bool ccflag, uint8_t evalcode,uint256 filtertxid, uint8_t func);
|
||||
|
||||
void SetCCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs,char *coinaddr,bool ccflag)
|
||||
{
|
||||
@@ -390,14 +390,30 @@ void SetCCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex
|
||||
}
|
||||
}
|
||||
|
||||
void SetCCtxids_NSPV(std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,char *coinaddr,bool ccflag, uint8_t evalcode, uint256 filtertxid)
|
||||
void SetCCtxids(std::vector<uint256> &txids,char *coinaddr,bool ccflag, uint8_t evalcode, uint256 filtertxid, uint8_t func)
|
||||
{
|
||||
int32_t type=0,i,n; char *ptr; std::string addrstr; uint160 hashBytes; std::vector<std::pair<uint160, int> > addresses;
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
NSPV_CCtxids(addressIndex,coinaddr,ccflag,evalcode,filtertxid);
|
||||
NSPV_CCtxids(txids,coinaddr,ccflag,evalcode,filtertxid,func);
|
||||
return;
|
||||
}
|
||||
else SetCCtxids(addressIndex,coinaddr,ccflag);
|
||||
n = (int32_t)strlen(coinaddr);
|
||||
addrstr.resize(n+1);
|
||||
ptr = (char *)addrstr.data();
|
||||
for (i=0; i<=n; i++)
|
||||
ptr[i] = coinaddr[i];
|
||||
CBitcoinAddress address(addrstr);
|
||||
if ( address.GetIndexKey(hashBytes, type, ccflag) == 0 )
|
||||
return;
|
||||
addresses.push_back(std::make_pair(hashBytes,type));
|
||||
for (std::vector<std::pair<uint160, int> >::iterator it = addresses.begin(); it != addresses.end(); it++)
|
||||
{
|
||||
if ( GetAddressIndex((*it).first, (*it).second, addressIndex) == 0 )
|
||||
return;
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it1=addressIndex.begin(); it1!=addressIndex.end(); it1++) txids.push_back(it1->first.txhash);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCflag)
|
||||
|
||||
@@ -787,22 +787,20 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid)
|
||||
|
||||
UniValue ChannelsList()
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); std::vector<std::pair<CAddressIndexKey, CAmount> > txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid;
|
||||
UniValue result(UniValue::VOBJ); std::vector<uint256> txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid;
|
||||
CTransaction tx; char myCCaddr[65],addr[65],str[256]; CPubKey mypk,srcpub,destpub; int32_t vout,numvouts,param1;
|
||||
int64_t nValue,param2;
|
||||
|
||||
cp = CCinit(&C,EVAL_CHANNELS);
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
GetCCaddress(cp,myCCaddr,mypk);
|
||||
SetCCtxids(txids,myCCaddr,true);
|
||||
SetCCtxids(txids,myCCaddr,true,EVAL_CHANNELS,zeroid,'O');
|
||||
result.push_back(Pair("result","success"));
|
||||
result.push_back(Pair("name","Channels List"));
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
for (std::vector<uint256>::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
vout = (int32_t)it->first.index;
|
||||
nValue = (int64_t)it->second;
|
||||
if ( (vout == 1 || vout == 2) && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 )
|
||||
txid = *it;
|
||||
if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 )
|
||||
{
|
||||
if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O')
|
||||
{
|
||||
@@ -820,7 +818,7 @@ UniValue ChannelsInfo(uint256 channeltxid)
|
||||
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<CTransaction> txs;
|
||||
std::vector<uint256> txids; std::vector<CTransaction> txs;
|
||||
|
||||
cp = CCinit(&C,EVAL_CHANNELS);
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
@@ -846,10 +844,10 @@ UniValue ChannelsInfo(uint256 channeltxid)
|
||||
result.push_back(Pair("Amount (satoshi)",i64tostr(param1*param2)));
|
||||
}
|
||||
GetCCaddress(cp,CCaddr,mypk);
|
||||
SetCCtxids_NSPV(addressIndex,CCaddr,true,EVAL_CHANNELS,opentxid);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
|
||||
SetCCtxids(txids,CCaddr,true,EVAL_CHANNELS,channeltxid,0);
|
||||
for (std::vector<uint256>::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
{
|
||||
if (myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && it->second==CC_MARKER_VALUE &&
|
||||
if (myGetTransaction(*it,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 &&
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -481,13 +481,13 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256
|
||||
{
|
||||
char markeraddr[64],depositaddr[64]; std::string coin; int32_t numvouts; int64_t totalsupply; uint256 tokenid,oracletxid,hashBlock;
|
||||
uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys; CTransaction tx;
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
std::vector<uint256> txids;
|
||||
|
||||
_GetCCaddress(markeraddr,EVAL_GATEWAYS,gatewayspk);
|
||||
SetCCtxids(addressIndex,markeraddr,true);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
|
||||
SetCCtxids(txids,markeraddr,true,EVAL_GATEWAYS,zeroid,'B');
|
||||
for (std::vector<uint256>::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
{
|
||||
if ( myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)=='B' )
|
||||
if ( myGetTransaction(*it,tx,hashBlock) != 0 && (numvouts= tx.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' )
|
||||
{
|
||||
@@ -1676,12 +1676,12 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin)
|
||||
|
||||
UniValue GatewaysList()
|
||||
{
|
||||
UniValue result(UniValue::VARR); std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys;
|
||||
UniValue result(UniValue::VARR); std::vector<uint256> txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector<CPubKey> pubkeys;
|
||||
cp = CCinit(&C,EVAL_GATEWAYS);
|
||||
SetCCtxids(addressIndex,cp->unspendableCCaddr,true);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
|
||||
SetCCtxids(txids,cp->unspendableCCaddr,true,EVAL_GATEWAYS,zeroid,'B');
|
||||
for (std::vector<uint256>::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
txid = *it;
|
||||
if ( myGetTransaction(txid,vintx,hashBlock) != 0 )
|
||||
{
|
||||
if ( vintx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,vintx.vout[vintx.vout.size()-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 0 )
|
||||
|
||||
@@ -792,13 +792,13 @@ int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,uint
|
||||
int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubKey publisher)
|
||||
{
|
||||
char coinaddr[64]; CPubKey pk; int64_t total=0,num; uint256 txid,hashBlock,subtxid; CTransaction subtx;
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
std::vector<uint256> txids;
|
||||
GetCCaddress(cp,coinaddr,publisher);
|
||||
SetCCtxids_NSPV(addressIndex,coinaddr,true,EVAL_ORACLES,oracletxid);
|
||||
SetCCtxids(txids,coinaddr,true,EVAL_ORACLES,oracletxid,'S');
|
||||
//fprintf(stderr,"scan lifetime of %s\n",coinaddr);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
|
||||
for (std::vector<uint256>::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
txid = *it;
|
||||
if ( myGetTransaction(txid,subtx,hashBlock) != 0 )
|
||||
{
|
||||
if ( subtx.vout.size() > 0 && DecodeOraclesOpRet(subtx.vout[subtx.vout.size()-1].scriptPubKey,subtxid,pk,num) == 'S' && subtxid == oracletxid && pk == publisher )
|
||||
@@ -1097,7 +1097,7 @@ UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ),b(UniValue::VARR); CTransaction tx,oracletx; uint256 txid,hashBlock,btxid,oracletxid;
|
||||
CPubKey pk; std::string name,description,format; int32_t numvouts,n=0,vout; std::vector<uint8_t> data; char *formatstr = 0;
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex; int64_t nValue;
|
||||
std::vector<uint256> txids; int64_t nValue;
|
||||
|
||||
result.push_back(Pair("result","success"));
|
||||
if ( myGetTransaction(reforacletxid,oracletx,hashBlock) != 0 && (numvouts=oracletx.vout.size()) > 0 )
|
||||
@@ -1122,15 +1122,13 @@ UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num)
|
||||
break;
|
||||
}
|
||||
}
|
||||
SetCCtxids(addressIndex,batonaddr,true);
|
||||
if (addressIndex.size()>0)
|
||||
SetCCtxids(txids,batonaddr,true,EVAL_ORACLES,zeroid,'D');
|
||||
if (txids.size()>0)
|
||||
{
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.end()-1; it!=addressIndex.begin(); it--)
|
||||
for (std::vector<uint256>::const_iterator it=txids.end()-1; it!=txids.begin(); it--)
|
||||
{
|
||||
txid=it->first.txhash;
|
||||
vout = (int32_t)it->first.index;
|
||||
nValue = (int64_t)it->second;
|
||||
if (vout==1 && nValue==10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size()) > 0 )
|
||||
txid=*it;
|
||||
if (myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size()) > 0 )
|
||||
{
|
||||
if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D' && reforacletxid == oracletxid )
|
||||
{
|
||||
@@ -1224,12 +1222,12 @@ UniValue OracleInfo(uint256 origtxid)
|
||||
|
||||
UniValue OraclesList()
|
||||
{
|
||||
UniValue result(UniValue::VARR); std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65];
|
||||
UniValue result(UniValue::VARR); std::vector<uint256> txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65];
|
||||
cp = CCinit(&C,EVAL_ORACLES);
|
||||
SetCCtxids(addressIndex,cp->normaladdr,false);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
|
||||
SetCCtxids(txids,cp->normaladdr,false,EVAL_ORACLES,zeroid,'C');
|
||||
for (std::vector<uint256>::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
txid = *it;
|
||||
if ( myGetTransaction(txid,createtx,hashBlock) != 0 )
|
||||
{
|
||||
if ( createtx.vout.size() > 0 && DecodeOraclesCreateOpRet(createtx.vout[createtx.vout.size()-1].scriptPubKey,name,description,format) == 'C' )
|
||||
|
||||
@@ -1225,7 +1225,7 @@ UniValue PegsAccountHistory(uint256 pegstxid)
|
||||
{
|
||||
char coinaddr[64]; int64_t nValue,amount; uint256 txid,accounttxid,hashBlock,tmptokenid,tmppegstxid;
|
||||
CTransaction tx; int32_t numvouts,vout; char funcid; CPubKey mypk,pegspk,pk; std::map<uint256,std::pair<int64_t,int64_t>> accounts;
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > txids; std::pair<int64_t,int64_t> account;
|
||||
std::vector<uint256> txids; std::pair<int64_t,int64_t> account;
|
||||
UniValue result(UniValue::VOBJ),acc(UniValue::VARR); struct CCcontract_info *cp,C;
|
||||
|
||||
result.push_back(Pair("result","success"));
|
||||
@@ -1234,13 +1234,11 @@ UniValue PegsAccountHistory(uint256 pegstxid)
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
pegspk = GetUnspendable(cp,0);
|
||||
GetCCaddress1of2(cp,coinaddr,mypk,pegspk);
|
||||
SetCCtxids_NSPV(txids,coinaddr,true,EVAL_PEGS,pegstxid);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
SetCCtxids(txids,coinaddr,true,EVAL_PEGS,pegstxid,0);
|
||||
for (std::vector<uint256>::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
vout = (int32_t)it->first.index;
|
||||
nValue = (int64_t)it->second;
|
||||
if (vout == 1 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 &&
|
||||
txid = *it;
|
||||
if (myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 &&
|
||||
(funcid=DecodePegsOpRet(tx,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid)
|
||||
{
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
|
||||
Reference in New Issue
Block a user