Merge branch 'jl777' into nSPV

This commit is contained in:
jl777
2019-07-20 00:05:51 -11:00
5 changed files with 34 additions and 8 deletions

View File

@@ -286,7 +286,7 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight);
len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H);
//fprintf(stderr,"hdr rwlen.%d\n",len);
fprintf(stderr,"hdr rwlen.%d\n",len);
return(len);
}

View File

@@ -520,15 +520,16 @@ void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> request) // received a req
if ( len == 1+sizeof(reqheight) )
iguana_rwnum(0,&request[1],sizeof(reqheight),&reqheight);
else reqheight = 0;
//fprintf(stderr,"request height.%d\n",reqheight);
fprintf(stderr,"request height.%d\n",reqheight);
memset(&I,0,sizeof(I));
if ( (slen= NSPV_getinfo(&I,reqheight)) > 0 )
{
response.resize(1 + slen);
response[0] = NSPV_INFORESP;
//fprintf(stderr,"slen.%d\n",slen);
fprintf(stderr,"slen.%d\n",slen);
if ( NSPV_rwinforesp(1,&response[1],&I) == slen )
{
fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id);
pfrom->PushMessage("nSPV",response);
pfrom->prevtimes[ind] = timestamp;
}

View File

@@ -442,7 +442,7 @@ UniValue NSPV_mempoolresp_json(struct NSPV_mempoolresp *ptr)
UniValue result(UniValue::VOBJ),array(UniValue::VARR); int32_t i;
result.push_back(Pair("result","success"));
for (i=0; i<ptr->numtxids; i++)
array.push_back(Pair("txid",ptr->txids[i].GetHex().c_str()));
array.push_back(ptr->txids[i].GetHex().c_str());
result.push_back(Pair("txids",array));
result.push_back(Pair("address",ptr->coinaddr));
result.push_back(Pair("isCC",ptr->CCflag));
@@ -476,7 +476,7 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr)
result.push_back(Pair("prevtxlen",(int64_t)ptr->prevtxlen));
result.push_back(Pair("nexttxid",ptr->nexttxid.GetHex()));
result.push_back(Pair("nexttxidht",(int64_t)ptr->nexttxidht));
result.push_back(Pair("nexttxlen",(int64_t)ptr->prevtxlen));
result.push_back(Pair("nexttxlen",(int64_t)ptr->nexttxlen));
result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs));
result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs,ptr->common.prevht)));
result.push_back(Pair("lastpeer",NSPV_lastpeer));

View File

@@ -7091,7 +7091,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id);
//if ( KOMODO_NSPV != 0 )
//if ( strCommand != "version" && strCommand != "verack" )
// fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId());
// fprintf(stderr, "recv: %s (%u bytes) peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)vRecv.size(), (int32_t)pfrom->GetId());
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
{
LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n");
@@ -7287,7 +7287,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
else if (pfrom->nVersion < chainparams.GetConsensus().vUpgrades[
CurrentEpoch(GetHeight(), chainparams.GetConsensus())].nProtocolVersion)
{
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion);
LogPrintf("peer=%d using obsolete version %i vs %d; disconnecting\n", pfrom->id, pfrom->nVersion,(int32_t)chainparams.GetConsensus().vUpgrades[
CurrentEpoch(GetHeight(), chainparams.GetConsensus())].nProtocolVersion);
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
strprintf("Version must be %d or greater",
chainparams.GetConsensus().vUpgrades[

View File

@@ -992,6 +992,8 @@ UniValue nspv_getinfo(const UniValue& params, bool fHelp)
int32_t reqht = 0;
if ( fHelp || params.size() > 1 )
throw runtime_error("nspv_getinfo [hdrheight]\n");
if ( KOMODO_NSPV == 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
if ( params.size() == 1 )
reqht = atoi((char *)params[0].get_str().c_str());
return(NSPV_getinfo_req(reqht));
@@ -1001,6 +1003,8 @@ UniValue nspv_logout(const UniValue& params, bool fHelp)
{
if ( fHelp || params.size() != 0 )
throw runtime_error("nspv_logout\n");
if ( KOMODO_NSPV == 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
return(NSPV_logout());
}
@@ -1008,6 +1012,8 @@ UniValue nspv_login(const UniValue& params, bool fHelp)
{
if ( fHelp || params.size() != 1 )
throw runtime_error("nspv_login wif\n");
if ( KOMODO_NSPV == 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
return(NSPV_login((char *)params[0].get_str().c_str()));
}
@@ -1016,6 +1022,8 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp)
int32_t skipcount = 0,CCflag = 0;
if ( fHelp || params.size() > 3 )
throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n");
if ( KOMODO_NSPV == 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
if ( params.size() == 0 )
{
if ( NSPV_address.size() != 0 )
@@ -1039,6 +1047,8 @@ UniValue nspv_mempool(const UniValue& params, bool fHelp)
memset(&txid,0,sizeof(txid));
if ( fHelp || params.size() > 5 )
throw runtime_error("nspv_mempool func(0 all, 1 address recv, 2 txid/vout spent, 3 txid inmempool) address isCC [txid vout]]]\n");
if ( KOMODO_NSPV == 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
funcid = atoi((char *)params[0].get_str().c_str());
coinaddr = (char *)params[1].get_str().c_str();
CCflag = atoi((char *)params[2].get_str().c_str());
@@ -1057,6 +1067,8 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp)
int32_t skipcount = 0,CCflag = 0;
if ( fHelp || params.size() > 3 )
throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n");
if ( KOMODO_NSPV == 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
if ( params.size() == 0 )
{
if ( NSPV_address.size() != 0 )
@@ -1080,6 +1092,8 @@ UniValue nspv_spentinfo(const UniValue& params, bool fHelp)
uint256 txid; int32_t vout;
if ( fHelp || params.size() != 2 )
throw runtime_error("nspv_spentinfo txid vout\n");
if ( KOMODO_NSPV == 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
txid = Parseuint256((char *)params[0].get_str().c_str());
vout = atoi((char *)params[1].get_str().c_str());
return(NSPV_spentinfo(txid,vout));
@@ -1090,6 +1104,8 @@ UniValue nspv_notarizations(const UniValue& params, bool fHelp)
int32_t height;
if ( fHelp || params.size() != 1 )
throw runtime_error("nspv_notarizations height\n");
if ( KOMODO_NSPV == 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
height = atoi((char *)params[0].get_str().c_str());
return(NSPV_notarizations(height));
}
@@ -1099,6 +1115,8 @@ UniValue nspv_hdrsproof(const UniValue& params, bool fHelp)
int32_t prevheight,nextheight;
if ( fHelp || params.size() != 2 )
throw runtime_error("nspv_hdrsproof prevheight nextheight\n");
if ( KOMODO_NSPV == 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
prevheight = atoi((char *)params[0].get_str().c_str());
nextheight = atoi((char *)params[1].get_str().c_str());
return(NSPV_hdrsproof(prevheight,nextheight));
@@ -1109,6 +1127,8 @@ UniValue nspv_txproof(const UniValue& params, bool fHelp)
uint256 txid; int32_t height;
if ( fHelp || params.size() != 2 )
throw runtime_error("nspv_txproof txid height\n");
if ( KOMODO_NSPV == 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
txid = Parseuint256((char *)params[0].get_str().c_str());
height = atoi((char *)params[1].get_str().c_str());
return(NSPV_txproof(0,txid,height));
@@ -1118,7 +1138,9 @@ UniValue nspv_spend(const UniValue& params, bool fHelp)
{
uint64_t satoshis;
if ( fHelp || params.size() != 2 )
throw runtime_error("nspv_spend destaddr amount\n");
throw runtime_error("nspv_spend address amount\n");
if ( KOMODO_NSPV == 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
if ( NSPV_address.size() == 0 )
throw runtime_error("to nspv_send you need an active nspv_login\n");
satoshis = atof(params[1].get_str().c_str())*COIN + 0.0000000049;
@@ -1132,5 +1154,7 @@ UniValue nspv_broadcast(const UniValue& params, bool fHelp)
{
if ( fHelp || params.size() != 1 )
throw runtime_error("nspv_broadcast hex\n");
if ( KOMODO_NSPV == 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
return(NSPV_broadcast((char *)params[0].get_str().c_str()));
}