Browse Source

New netinfo tweak bracket

warmup
jl777 5 years ago
parent
commit
a8cc298d5b
  1. 12
      src/komodo_nSPV.h
  2. 4
      src/komodo_nSPV_fullnode.h
  3. 69
      src/komodo_nSPV_superlite.h
  4. 2
      src/komodo_nSPV_wallet.h
  5. 11
      src/wallet/rpcdump.cpp

12
src/komodo_nSPV.h

@ -24,12 +24,6 @@
// need to validate incoming data and update only if it is valid and more recent
// make sure to sanity check all vector lengths on receipt
// bugs:
// got txproof response 1562526470 size.2112 a9ea92a1bbc68ae850b4bedabcbe60132844e5791ba2678bcba520910f1ad0c6 ht.1432768
// got ntzs response 1562526471 size.209 bbf7ac47c67b5f84ddeffa5621dae6a9c3e5e8fad59cfc7359be2aa2937bd135 prev.1432750, 8255451aa5a5f8ba8f06ea8f4f83879f346bfd782d72c16d034693d123aa4b68 next.1432760
// NSPV_gettransaction retval would have been -22
#ifndef KOMODO_NSPV_H
#define KOMODO_NSPV_H
@ -223,7 +217,8 @@ struct NSPV_inforesp
{
struct NSPV_ntz notarization;
uint256 blockhash;
int32_t height,pad32;
int32_t height,hdrheight;
struct NSPV_equihdr H;
};
int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp *ptr)
@ -232,7 +227,8 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp
len += NSPV_rwntz(rwflag,&serialized[len],&ptr->notarization);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->blockhash),(uint8_t *)&ptr->blockhash);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight);
len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H);
return(len);
}

4
src/komodo_nSPV_fullnode.h

@ -32,7 +32,9 @@ int32_t NSPV_notarization_find(struct NSPV_ntzargs *args,int32_t height,int32_t
int32_t ntzheight = 0; uint256 hashBlock; CTransaction tx; Notarisation nota; char *symbol; std::vector<uint8_t> opret;
symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL;
memset(args,0,sizeof(*args));
if ( (args->txidht= (dir < 0 ? ScanNotarisationsDB : ScanNotarisationsDB2)(height,symbol,1440,nota)) == 0 )
if ( dir > 0 )
height += 10;
if ( (args->txidht= ScanNotarisationsDB(height,symbol,1440,nota)) == 0 )
return(-1);
args->txid = nota.first;
if ( !GetTransaction(args->txid,tx,hashBlock,false) || tx.vout.size() < 2 )

69
src/komodo_nSPV_superlite.h

@ -105,7 +105,27 @@ UniValue NSPV_ntz_json(struct NSPV_ntz *ptr)
return(result);
}
UniValue _NSPV_getinfo_json(struct NSPV_inforesp *ptr)
UniValue NSPV_header_json(struct NSPV_equihdr *hdr,int32_t height)
{
UniValue item(UniValue::VOBJ);
item.push_back(Pair("height",(int64_t)height));
item.push_back(Pair("blockhash",NSPV_hdrhash(hdr).GetHex()));
item.push_back(Pair("hashPrevBlock",hdr->hashPrevBlock.GetHex()));
item.push_back(Pair("hashMerkleRoot",hdr->hashMerkleRoot.GetHex()));
item.push_back(Pair("nTime",(int64_t)hdr->nTime));
item.push_back(Pair("nBits",(int64_t)hdr->nBits));
return(item);
}
UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs,int32_t height)
{
UniValue array(UniValue::VARR); int32_t i;
for (i=0; i<numhdrs; i++)
array.push_back(NSPV_header_json(&hdrs[i],height+i));
return(array);
}
UniValue NSPV_getinfo_json(struct NSPV_inforesp *ptr)
{
UniValue result(UniValue::VOBJ); int32_t expiration; uint32_t timestamp = (uint32_t)time(NULL);
result.push_back(Pair("result","success"));
@ -122,6 +142,7 @@ UniValue _NSPV_getinfo_json(struct NSPV_inforesp *ptr)
result.push_back(Pair("height",(int64_t)ptr->height));
result.push_back(Pair("chaintip",ptr->blockhash.GetHex()));
result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization)));
result.push_back(Pair("hdr",NSPV_header_json(&ptr->H)));
return(result);
}
@ -165,23 +186,6 @@ UniValue NSPV_ntzs_json(struct NSPV_ntzsresp *ptr)
return(result);
}
UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs,int32_t height)
{
UniValue array(UniValue::VARR); int32_t i;
for (i=0; i<numhdrs; i++)
{
UniValue item(UniValue::VOBJ);
item.push_back(Pair("height",(int64_t)height+i));
item.push_back(Pair("blockhash",NSPV_hdrhash(&hdrs[i]).GetHex()));
item.push_back(Pair("hashPrevBlock",hdrs[i].hashPrevBlock.GetHex()));
item.push_back(Pair("hashMerkleRoot",hdrs[i].hashMerkleRoot.GetHex()));
item.push_back(Pair("nTime",(int64_t)hdrs[i].nTime));
array.push_back(item);
}
return(array);
}
UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr)
{
UniValue result(UniValue::VOBJ);
@ -267,26 +271,23 @@ UniValue NSPV_login(char *wifstr)
return(result);
}
UniValue NSPV_getinfo_json()
UniValue NSPV_getinfo_req(int32_t reqht)
{
uint8_t msg[64]; int32_t i,iters,len = 0; struct NSPV_inforesp I;
uint8_t msg[64]; int32_t i,len = 0; struct NSPV_inforesp I;
NSPV_inforesp_purge(&NSPV_inforesult);
msg[len++] = NSPV_INFO;
for (iters=0; iters<3; iters++)
len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht);
if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 )
{
//fprintf(stderr,"issue getinfo\n");
if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 )
for (i=0; i<NSPV_POLLITERS; i++)
{
for (i=0; i<NSPV_POLLITERS; i++)
{
usleep(NSPV_POLLMICROS);
if ( NSPV_inforesult.height != 0 )
return(_NSPV_getinfo_json(&NSPV_inforesult));
}
} else sleep(1);
usleep(NSPV_POLLMICROS);
if ( NSPV_inforesult.height != 0 )
return(_NSPV_getinfo_json(&NSPV_inforesult));
}
}
memset(&I,0,sizeof(I));
return(_NSPV_getinfo_json(&NSPV_inforesult));
return(NSPV_getinfo_json(&NSPV_inforesult));
}
UniValue NSPV_addressutxos(char *coinaddr)
@ -299,12 +300,6 @@ UniValue NSPV_addressutxos(char *coinaddr)
result.push_back(Pair("error","invalid address"));
return(result);
}
if ( NSPV_inforesult.height == 0 )
{
msg[0] = NSPV_INFO;
fprintf(stderr,"issue getinfo\n");
NSPV_req(0,msg,1,NODE_NSPV,msg[0]>>1);
}
slen = (int32_t)strlen(coinaddr);
msg[len++] = NSPV_UTXOS;
msg[len++] = slen;

2
src/komodo_nSPV_wallet.h

@ -383,8 +383,10 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages
{
if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 )
{
int32_t reqht = 0;
len = 0;
msg[len++] = NSPV_INFO;
len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht);
NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1);
}
}

11
src/wallet/rpcdump.cpp

@ -972,7 +972,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp)
return EncodeViewingKey(vk);
}
UniValue NSPV_getinfo_json();
UniValue NSPV_getinfo_req(int32_t reqht);
UniValue NSPV_login(char *wifstr);
UniValue NSPV_logout();
UniValue NSPV_addressutxos(char *coinaddr);
@ -987,9 +987,12 @@ extern std::string NSPV_address;
UniValue nspv_getinfo(const UniValue& params, bool fHelp)
{
if ( fHelp || params.size() != 0 )
throw runtime_error("nspv_getinfo\n");
return(NSPV_getinfo_json());
int32_t reqht = 0;
if ( fHelp || params.size() > 1 )
throw runtime_error("nspv_getinfo [hdrheight]\n");
if ( params.size() == 0 )
reqht = atoi((char *)params[0].get_str().c_str());
return(NSPV_getinfo_req(reqht));
}
UniValue nspv_logout(const UniValue& params, bool fHelp)

Loading…
Cancel
Save