Browse Source

Change hdrsproof to taxied based, add unspentvalue to taproot

warmup
jl777 5 years ago
parent
commit
88617145c6
  1. 2
      src/cc/CCinclude.h
  2. 2
      src/cc/CCtx.cpp
  3. 26
      src/komodo_nSPV.h
  4. 81
      src/komodo_nSPV_fullnode.h
  5. 23
      src/komodo_nSPV_superlite.h
  6. 6
      src/komodo_nSPV_wallet.h
  7. 4
      src/wallet/rpcdump.cpp

2
src/cc/CCinclude.h

@ -174,7 +174,7 @@ static int32_t ignorevin;
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock);
int32_t is_hexstr(char *str,int32_t n);
bool myAddtomempool(CTransaction &tx, CValidationState *pstate = NULL, bool fSkipExpiry = false);
int32_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag,int32_t lockflag);
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);

2
src/cc/CCtx.cpp

@ -365,7 +365,7 @@ int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCf
return(0);
}
int32_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag,int32_t lockflag)
int64_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag,int32_t lockflag)
{
CCoins coins;
//fprintf(stderr,"CCgettxoud %s/v%d\n",txid.GetHex().c_str(),vout);

26
src/komodo_nSPV.h

@ -240,7 +240,8 @@ void NSPV_inforesp_purge(struct NSPV_inforesp *ptr)
struct NSPV_txproof
{
uint256 txid;
int32_t height;
int64_t unspentvalue;
int32_t height,vout;
uint16_t txlen,txprooflen;
uint8_t *tx,*txproof;
};
@ -249,7 +250,9 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p
{
int32_t len = 0;
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->unspentvalue),&ptr->unspentvalue);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height);
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);
return(len);
@ -412,7 +415,7 @@ int32_t NSPV_txextract(CTransaction &tx,uint8_t *data,int32_t datalen)
int32_t NSPV_pubkeysextract(uint8_t pubkeys[64][33],CTransaction tx,uint8_t elected[64][33])
{
int32_t numsigs = 0;
int32_t numsigs = 13;
return(numsigs);
}
@ -429,24 +432,21 @@ uint256 NSPV_opretextract(int32_t *heightp,uint256 *blockhashp,char *symbol,std:
return(desttxid);
}
int32_t NSPV_notarizationextract(int32_t *heightp,uint256 *blockhashp,uint256 *txidp,uint256 *desttxidp,CTransaction tx,int32_t ntzheight)
int32_t NSPV_notarizationextract(int32_t *ntzheightp,uint256 *blockhashp,uint256 *desttxidp,CTransaction tx)
{
int32_t numsigs; uint8_t elected[64][33],sigkeys[64][33]; char *symbol; std::vector<uint8_t> opret;
if ( tx.vout.size() >= 2 )
{
symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL;
komodo_notaries(elected,ntzheight,0);
numsigs = NSPV_pubkeysextract(sigkeys,tx,elected);
GetOpReturnData(tx.vout[1].scriptPubKey,opret);
if ( opret.size() >= 32*2+4*2 )
*desttxidp = NSPV_opretextract(heightp,blockhashp,symbol,opret,tx.GetHash());
/*{
int z;
for (z=0; z<68; z++)
fprintf(stderr,"%02x",opret[z]);
}*/
*txidp = tx.GetHash();
return(0);
{
*desttxidp = NSPV_opretextract(ntzheightp,blockhashp,symbol,opret,tx.GetHash());
komodo_notaries(elected,*ntzheightp,0);
if ( (numsigs= NSPV_pubkeysextract(sigkeys,tx,elected)) < 12 )
return(-3);
return(0);
} else return(-2);
} else return(-1);
}
#endif // KOMODO_NSPV_H

81
src/komodo_nSPV_fullnode.h

@ -21,7 +21,7 @@
#include "notarisationdb.h"
uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height)
/*uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height)
{
uint256 txid; Notarisation nota; char *symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL;
memset(&txid,0,sizeof(txid));
@ -33,7 +33,7 @@ uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height)
txid = nota.first;
}
return(txid);
}
}*/
int32_t komodo_notarized_bracket(uint256 txids[2],int32_t txidhts[2],uint256 desttxids[2],int32_t ntzheights[2],int32_t height)
{
@ -206,12 +206,13 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int
return(sizeof(*ptr));
}
int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height)
int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32_t height)
{
int32_t flag = 0,len = 0; uint256 hashBlock; CBlock block; CBlockIndex *pindex;
if ( (ptr->tx= NSPV_getrawtx(hashBlock,&ptr->txlen,txid)) == 0 )
return(-1);
ptr->txid = txid;
ptr->vout = vout;
ptr->height = height;
if ( (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 )
{
@ -237,6 +238,8 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height)
ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen);
memcpy(ptr->txproof,&proof[0],ptr->txprooflen);
}
//int64_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag,int32_t lockflag);
ptr->unspentvalue = CCgettxout(txid,vout,1,1);
//fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen));
return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen);
}
@ -264,22 +267,40 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height)
return(-1);
}
int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int32_t nextht)
int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,uint256 prevntztxid,uint256 nextntxtxid)
{
int32_t i; uint256 hashBlock;
if ( prevht > nextht || (nextht-prevht) > 1440 )
int32_t i; uint256 hashBlock,bhash0,bhash1,desttxid0,desttxid1; CTransaction tx;
ptr->prevtxid = prevntztxid;
ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevtxlen,ptr->prevtxid);
ptr->prevtxidht = komodo_blockheight(hashBlock);
if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 )
return(-1);
else if ( NSPV_notarizationextract(&ptr->common.prevht,&bhash0,&desttxid0,tx) < 0 )
return(-2);
else if ( komodo_blockheight(bhash0) != ptr->common.prevht )
return(-3);
ptr->nexttxid = nextntztxid;
ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nexttxlen,ptr->nexttxid);
ptr->nexttxidht = komodo_blockheight(hashBlock);
if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 )
return(-4);
else if ( NSPV_notarizationextract(&ptr->common.nextht,&bhash1,&desttxid1,tx) < 0 )
return(-5);
else if ( komodo_blockheight(bhash1) != ptr->common.nextht )
return(-6);
else if ( ptr->common.prevht > ptr->common.nextht || (ptr->common.nextht - ptr->common.prevht) > 1440 )
{
fprintf(stderr,"illegal prevht.%d nextht.%d\n",prevht,nextht);
return(-1);
return(-7);
}
ptr->common.prevht = prevht;
ptr->common.nextht = nextht;
ptr->common.numhdrs = (nextht - prevht + 1);
ptr->common.hdrs = (struct NSPV_equihdr *)calloc(ptr->common.numhdrs,sizeof(*ptr->common.hdrs));
//fprintf(stderr,"prev.%d next.%d allocate numhdrs.%d\n",prevht,nextht,ptr->common.numhdrs);
for (i=0; i<ptr->common.numhdrs; i++)
{
hashBlock = NSPV_hdrhash(&ptr->common.hdrs[i]);
//hashBlock = NSPV_hdrhash(&ptr->common.hdrs[i]);
//fprintf(stderr,"hdr[%d] %s\n",prevht+i,hashBlock.GetHex().c_str());
if ( NSPV_setequihdr(&ptr->common.hdrs[i],prevht+i) < 0 )
{
@ -289,11 +310,6 @@ int32_t NSPV_getntzsproofresp(struct NSPV_ntzsproofresp *ptr,int32_t prevht,int3
return(-1);
}
}
ptr->prevtxid = NSPV_getnotarization_txid(&ptr->prevtxidht,prevht);
ptr->prevntz = NSPV_getrawtx(hashBlock,&ptr->prevtxlen,ptr->prevtxid);
ptr->nexttxid = NSPV_getnotarization_txid(&ptr->nexttxidht,nextht);
ptr->nextntz = NSPV_getrawtx(hashBlock,&ptr->nexttxlen,ptr->nexttxid);
//fprintf(stderr,"ptr->prevht.%d nextht.%d\n",ptr->common.prevht,ptr->common.nextht);
return(sizeof(*ptr) + sizeof(*ptr->common.hdrs)*ptr->common.numhdrs - sizeof(ptr->common.hdrs) - sizeof(ptr->prevntz) - sizeof(ptr->nextntz) + ptr->prevtxlen + ptr->nexttxlen);
}
@ -306,7 +322,7 @@ int32_t NSPV_getspentinfo(struct NSPV_spentinfo *ptr,uint256 txid,int32_t vout)
len = (int32_t)(sizeof(*ptr) - sizeof(ptr->spent.tx) - sizeof(ptr->spent.txproof));
if ( CCgetspenttxid(ptr->spent.txid,ptr->spentvini,ptr->spent.height,txid,vout) == 0 )
{
if ( NSPV_gettxproof(&ptr->spent,ptr->spent.txid,ptr->spent.height) > 0 )
if ( NSPV_gettxproof(&ptr->spent,0,ptr->spent.txid,ptr->spent.height) > 0 )
len += ptr->spent.txlen + ptr->spent.txprooflen;
else
{
@ -398,26 +414,22 @@ void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> request) // received a req
{
if ( timestamp > pfrom->prevtimes[ind] )
{
struct NSPV_ntzsproofresp P; int32_t prevht,nextht;
struct NSPV_ntzsproofresp P; uint256 prevntz,nextntz;
if ( len == 1+sizeof(prevht)+sizeof(nextht) )
{
iguana_rwnum(0,&request[1],sizeof(prevht),&prevht);
iguana_rwnum(0,&request[1+sizeof(prevht)],sizeof(nextht),&nextht);
if ( prevht != 0 && nextht != 0 && nextht >= prevht )
iguana_rwbignum(0,&request[1],sizeof(prevntz),(uint8_t *)&prevntz);
iguana_rwbignum(0,&request[1+sizeof(prevntz)],sizeof(nextntz),(uint8_t *)&nextntz);
memset(&P,0,sizeof(P));
if ( (slen= NSPV_getntzsproofresp(&P,prevntz,nextntz)) > 0 )
{
memset(&P,0,sizeof(P));
if ( (slen= NSPV_getntzsproofresp(&P,prevht,nextht)) > 0 )
response.resize(1 + slen);
response[0] = NSPV_NTZSPROOFRESP;
if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen )
{
response.resize(1 + slen);
response[0] = NSPV_NTZSPROOFRESP;
P.common.numhdrs = (nextht - prevht + 1);
if ( NSPV_rwntzsproofresp(1,&response[1],&P) == slen )
{
pfrom->PushMessage("nSPV",response);
pfrom->prevtimes[ind] = timestamp;
}
NSPV_ntzsproofresp_purge(&P);
pfrom->PushMessage("nSPV",response);
pfrom->prevtimes[ind] = timestamp;
}
NSPV_ntzsproofresp_purge(&P);
}
}
}
@ -426,14 +438,15 @@ void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> request) // received a req
{
if ( timestamp > pfrom->prevtimes[ind] )
{
struct NSPV_txproof P; uint256 txid; int32_t height;
struct NSPV_txproof P; uint256 txid; int32_t height,vout;
if ( len == 1+sizeof(txid)+sizeof(height) )
{
iguana_rwnum(0,&request[1],sizeof(height),&height);
iguana_rwbignum(0,&request[1+sizeof(height)],sizeof(txid),(uint8_t *)&txid);
iguana_rwnum(0,&request[1+sizeof(height)],sizeof(vout),&vout);
iguana_rwbignum(0,&request[1+sizeof(height)+sizeof(vout)],sizeof(txid),(uint8_t *)&txid);
//fprintf(stderr,"got txid ht.%d\n",txid.GetHex().c_str(),height);
memset(&P,0,sizeof(P));
if ( (slen= NSPV_gettxproof(&P,txid,height)) > 0 )
if ( (slen= NSPV_gettxproof(&P,vout,txid,height)) > 0 )
{
response.resize(1 + slen);
response[0] = NSPV_TXPROOFRESP;

23
src/komodo_nSPV_superlite.h

@ -344,20 +344,18 @@ UniValue NSPV_notarizations(int32_t height)
return(NSPV_ntzs_json(&N));
}
UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight)
UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid)
{
uint8_t msg[64]; int32_t i,len = 0; struct NSPV_ntzsproofresp H;
if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight )
return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult));
msg[len++] = NSPV_NTZSPROOF;
len += iguana_rwnum(1,&msg[len],sizeof(prevheight),&prevheight);
len += iguana_rwnum(1,&msg[len],sizeof(nextheight),&nextheight);
len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid);
len += iguana_rwbignum(1,&msg[len],sizeof(nexttxid),(uint8_t *)&nexttxid);
if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 )
{
for (i=0; i<NSPV_POLLITERS; i++)
{
usleep(NSPV_POLLMICROS);
if ( NSPV_ntzsproofresult.common.prevht == prevheight && NSPV_ntzsproofresult.common.nextht >= nextheight )
if ( NSPV_ntzsproofresult.prevtxid == prevtxid && NSPV_ntzsproofresult.nexttxid == nexttxid )
return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult));
}
}
@ -365,13 +363,24 @@ UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight)
return(NSPV_ntzsproof_json(&H));
}
UniValue NSPV_txproof(uint256 txid,int32_t height)
UniValue NSPV_hdrsproof(int32_t prevht,int32_t nextht)
{
uint256 prevtxid,nexttxid;
NSPV_notarizations(prevht);
prevtxid = NSPV_ntzsresult.prevntz.txid;
NSPV_notarizations(nextht);
nexttxid = NSPV_ntzsresult.nextntz.txid;
return(NSPV_txidhdrsproof(prevtxid,nexttxid));
}
UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height)
{
uint8_t msg[64]; int32_t i,len = 0; struct NSPV_txproof P;
if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height )
return(NSPV_txproof_json(&NSPV_txproofresult));
msg[len++] = NSPV_TXPROOF;
len += iguana_rwnum(1,&msg[len],sizeof(height),&height);
len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout);
len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid);
//fprintf(stderr,"req txproof %s at height.%d\n",txid.GetHex().c_str(),height);
if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 )

6
src/komodo_nSPV_wallet.h

@ -29,7 +29,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr)
return(-2);
else if ( tx.GetHash() != ptr->nexttxid )
return(-3);
else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&desttxid,tx,ptr->common.nextht) < 0 )
else if ( NSPV_notarizationextract(&height,&blockhash,&desttxid,tx) < 0 )
return(-4);
else if ( height != ptr->common.nextht )
return(-5);
@ -48,7 +48,7 @@ int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr)
return(-7);
else if ( tx.GetHash() != ptr->prevtxid )
return(-8);
else if ( NSPV_notarizationextract(&height,&blockhash,&txid,&desttxid,tx,ptr->common.prevht) < 0 )
else if ( NSPV_notarizationextract(&height,&blockhash,&desttxid,tx) < 0 )
return(-9);
else if ( height != ptr->common.prevht )
return(-10);
@ -81,7 +81,7 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx)
offset = (height - NSPV_ntzsresult.prevntz.height);
if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height )
{
NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height);
NSPV_hdrsproof(NSPV_ntzsresult.prevtxid,NSPV_ntzsresult.nexttxid);
if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 )
{
std::vector<uint256> txids; std::vector<uint8_t> proof; uint256 proofroot;

4
src/wallet/rpcdump.cpp

@ -981,7 +981,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis);
UniValue NSPV_spentinfo(uint256 txid,int32_t vout);
UniValue NSPV_notarizations(int32_t height);
UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight);
UniValue NSPV_txproof(uint256 txid,int32_t vout);
UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t vout);
uint256 Parseuint256(const char *hexstr);
extern std::string NSPV_address;
@ -1057,7 +1057,7 @@ UniValue nspv_txproof(const UniValue& params, bool fHelp)
throw runtime_error("nspv_txproof txid height\n");
txid = Parseuint256((char *)params[0].get_str().c_str());
height = atoi((char *)params[1].get_str().c_str());
return(NSPV_txproof(txid,height));
return(NSPV_txproof(0,txid,height));
}
UniValue nspv_spend(const UniValue& params, bool fHelp)

Loading…
Cancel
Save