Rearrange
This commit is contained in:
@@ -113,7 +113,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind)
|
||||
if ( pnode == 0 )
|
||||
{
|
||||
memset(pnodes,0,sizeof(pnodes));
|
||||
//LOCK(cs_vNodes);
|
||||
LOCK(cs_vNodes);
|
||||
n = 0;
|
||||
BOOST_FOREACH(CNode *ptr,vNodes)
|
||||
{
|
||||
@@ -426,6 +426,8 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0;
|
||||
//fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str());
|
||||
if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag )
|
||||
return(NSPV_utxosresp_json(&NSPV_utxosresult));
|
||||
NSPV_utxosresp_purge(&NSPV_utxosresult);
|
||||
if ( bitcoin_base58decode(msg,coinaddr) != 25 )
|
||||
{
|
||||
@@ -456,8 +458,8 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag)
|
||||
UniValue NSPV_notarizations(int32_t height)
|
||||
{
|
||||
uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsresp N;
|
||||
//if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height )
|
||||
// return(NSPV_ntzs_json(&NSPV_ntzsresult));
|
||||
if ( NSPV_ntzsresult.prevntz.height <= height && NSPV_ntzsresult.nextntz.height >= height )
|
||||
return(NSPV_ntzs_json(&NSPV_ntzsresult));
|
||||
NSPV_ntzsresp_purge(&NSPV_ntzsresult);
|
||||
msg[len++] = NSPV_NTZS;
|
||||
len += iguana_rwnum(1,&msg[len],sizeof(height),&height);
|
||||
@@ -478,6 +480,8 @@ UniValue NSPV_notarizations(int32_t height)
|
||||
UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid)
|
||||
{
|
||||
uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsproofresp H;
|
||||
if ( NSPV_ntzsproofresult.prevtxid == prevtxid && NSPV_ntzsproofresult.nexttxid == nexttxid )
|
||||
return(NSPV_ntzsproof_json(&NSPV_ntzsproofresult));
|
||||
NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresult);
|
||||
msg[len++] = NSPV_NTZSPROOF;
|
||||
len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid);
|
||||
@@ -509,8 +513,8 @@ UniValue NSPV_hdrsproof(int32_t prevht,int32_t nextht)
|
||||
UniValue NSPV_txproof(int32_t vout,uint256 txid,int32_t height)
|
||||
{
|
||||
uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_txproof P;
|
||||
//if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height )
|
||||
// return(NSPV_txproof_json(&NSPV_txproofresult));
|
||||
if ( NSPV_txproofresult.txid == txid )
|
||||
return(NSPV_txproof_json(&NSPV_txproofresult));
|
||||
NSPV_txproof_purge(&NSPV_txproofresult);
|
||||
msg[len++] = NSPV_TXPROOF;
|
||||
len += iguana_rwnum(1,&msg[len],sizeof(height),&height);
|
||||
@@ -589,111 +593,5 @@ UniValue NSPV_broadcast(char *hex)
|
||||
return(NSPV_broadcast_json(&B,txid));
|
||||
}
|
||||
|
||||
int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr)
|
||||
{
|
||||
int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid;
|
||||
if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs )
|
||||
{
|
||||
fprintf(stderr,"next.%d prev.%d -> %d vs %d\n",ptr->common.nextht,ptr->common.prevht,ptr->common.nextht-ptr->common.prevht+1,ptr->common.numhdrs);
|
||||
return(-2);
|
||||
}
|
||||
else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 )
|
||||
return(-3);
|
||||
else if ( tx.GetHash() != ptr->nexttxid )
|
||||
return(-4);
|
||||
else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 )
|
||||
return(-5);
|
||||
else if ( height != ptr->common.nextht )
|
||||
return(-6);
|
||||
else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash )
|
||||
return(-7);
|
||||
for (i=ptr->common.numhdrs-1; i>0; i--)
|
||||
{
|
||||
blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]);
|
||||
if ( blockhash != ptr->common.hdrs[i].hashPrevBlock )
|
||||
return(-i-13);
|
||||
}
|
||||
if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 )
|
||||
return(-8);
|
||||
else if ( tx.GetHash() != ptr->prevtxid )
|
||||
return(-9);
|
||||
else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 )
|
||||
return(-10);
|
||||
else if ( height != ptr->common.prevht )
|
||||
return(-11);
|
||||
else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash )
|
||||
return(-12);
|
||||
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 i,offset,retval = 0; int64_t rewards = 0; uint32_t nLockTime; std::vector<uint8_t> proof;
|
||||
for (i=0; i<3; i++)
|
||||
{
|
||||
NSPV_txproof(vout,txid,height);
|
||||
if ( NSPV_txproofresult.txlen != 0 )
|
||||
break;
|
||||
sleep(1);
|
||||
}
|
||||
if ( NSPV_txproofresult.txid != txid )
|
||||
{
|
||||
fprintf(stderr,"txproof error %s != %s\n",NSPV_txproofresult.txid.GetHex().c_str(),txid.GetHex().c_str());
|
||||
return(-1);
|
||||
}
|
||||
else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 )
|
||||
retval = -2000;
|
||||
else if ( skipvalidation == 0 && NSPV_txproofresult.unspentvalue <= 0 )
|
||||
retval = -2001;
|
||||
else if ( ASSETCHAINS_SYMBOL[0] == 0 && extradata >= 0 && tiptime != 0 )
|
||||
{
|
||||
rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime);
|
||||
if ( rewards != extradata )
|
||||
{
|
||||
fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards));
|
||||
}
|
||||
rewardsum += rewards;
|
||||
}
|
||||
|
||||
if ( skipvalidation == 0 )
|
||||
{
|
||||
if ( NSPV_txproofresult.txprooflen > 0 )
|
||||
{
|
||||
proof.resize(NSPV_txproofresult.txprooflen);
|
||||
memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen);
|
||||
}
|
||||
fprintf(stderr,"call NSPV_notarizations\n");
|
||||
NSPV_notarizations(height); // gets the prev and next notarizations
|
||||
if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) )
|
||||
{
|
||||
fprintf(stderr,"issue manual bracket\n");
|
||||
NSPV_notarizations(height-1);
|
||||
NSPV_notarizations(height+1);
|
||||
NSPV_notarizations(height); // gets the prev and next notarizations
|
||||
}
|
||||
if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height )
|
||||
{
|
||||
fprintf(stderr,">>>>> gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height);
|
||||
offset = (height - NSPV_ntzsresult.prevntz.height);
|
||||
if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height )
|
||||
{
|
||||
fprintf(stderr,"call NSPV_txidhdrsproof %s %s\n",NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.txid.GetHex().c_str());
|
||||
NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid);
|
||||
usleep(10000);
|
||||
if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 )
|
||||
{
|
||||
std::vector<uint256> txids; uint256 proofroot;
|
||||
proofroot = BitcoinGetProofMerkleRoot(proof,txids);
|
||||
if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot )
|
||||
{
|
||||
fprintf(stderr,"prooflen.%d proofroot.%s vs %s\n",NSPV_txproofresult.txprooflen,proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str());
|
||||
retval = -2003;
|
||||
}
|
||||
}
|
||||
} else retval = -2002;
|
||||
} else retval = -2004;
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
|
||||
#endif // KOMODO_NSPVSUPERLITE_H
|
||||
|
||||
@@ -20,6 +20,113 @@
|
||||
// nSPV wallet uses superlite functions (and some komodod built in functions) to implement nSPV_spend
|
||||
extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
|
||||
|
||||
int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresp *ptr)
|
||||
{
|
||||
int32_t i,height,txidht; CTransaction tx; uint256 blockhash,txid,desttxid;
|
||||
if ( (ptr->common.nextht-ptr->common.prevht+1) != ptr->common.numhdrs )
|
||||
{
|
||||
fprintf(stderr,"next.%d prev.%d -> %d vs %d\n",ptr->common.nextht,ptr->common.prevht,ptr->common.nextht-ptr->common.prevht+1,ptr->common.numhdrs);
|
||||
return(-2);
|
||||
}
|
||||
else if ( NSPV_txextract(tx,ptr->nextntz,ptr->nexttxlen) < 0 )
|
||||
return(-3);
|
||||
else if ( tx.GetHash() != ptr->nexttxid )
|
||||
return(-4);
|
||||
else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 )
|
||||
return(-5);
|
||||
else if ( height != ptr->common.nextht )
|
||||
return(-6);
|
||||
else if ( NSPV_hdrhash(&ptr->common.hdrs[ptr->common.numhdrs-1]) != blockhash )
|
||||
return(-7);
|
||||
for (i=ptr->common.numhdrs-1; i>0; i--)
|
||||
{
|
||||
blockhash = NSPV_hdrhash(&ptr->common.hdrs[i-1]);
|
||||
if ( blockhash != ptr->common.hdrs[i].hashPrevBlock )
|
||||
return(-i-13);
|
||||
}
|
||||
if ( NSPV_txextract(tx,ptr->prevntz,ptr->prevtxlen) < 0 )
|
||||
return(-8);
|
||||
else if ( tx.GetHash() != ptr->prevtxid )
|
||||
return(-9);
|
||||
else if ( NSPV_notarizationextract(1,&height,&blockhash,&desttxid,tx) < 0 )
|
||||
return(-10);
|
||||
else if ( height != ptr->common.prevht )
|
||||
return(-11);
|
||||
else if ( NSPV_hdrhash(&ptr->common.hdrs[0]) != blockhash )
|
||||
return(-12);
|
||||
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 i,offset,retval = 0; int64_t rewards = 0; uint32_t nLockTime; std::vector<uint8_t> proof;
|
||||
for (i=0; i<3; i++)
|
||||
{
|
||||
NSPV_txproof(vout,txid,height);
|
||||
if ( NSPV_txproofresult.txlen != 0 )
|
||||
break;
|
||||
sleep(1);
|
||||
}
|
||||
if ( NSPV_txproofresult.txid != txid )
|
||||
{
|
||||
fprintf(stderr,"txproof error %s != %s\n",NSPV_txproofresult.txid.GetHex().c_str(),txid.GetHex().c_str());
|
||||
return(-1);
|
||||
}
|
||||
else if ( NSPV_txextract(tx,NSPV_txproofresult.tx,NSPV_txproofresult.txlen) < 0 || NSPV_txproofresult.txlen <= 0 )
|
||||
retval = -2000;
|
||||
else if ( skipvalidation == 0 && NSPV_txproofresult.unspentvalue <= 0 )
|
||||
retval = -2001;
|
||||
else if ( ASSETCHAINS_SYMBOL[0] == 0 && extradata >= 0 && tiptime != 0 )
|
||||
{
|
||||
rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime);
|
||||
if ( rewards != extradata )
|
||||
{
|
||||
fprintf(stderr,"extradata %.8f vs rewards %.8f\n",dstr(extradata),dstr(rewards));
|
||||
}
|
||||
rewardsum += rewards;
|
||||
}
|
||||
|
||||
if ( skipvalidation == 0 )
|
||||
{
|
||||
if ( NSPV_txproofresult.txprooflen > 0 )
|
||||
{
|
||||
proof.resize(NSPV_txproofresult.txprooflen);
|
||||
memcpy(&proof[0],NSPV_txproofresult.txproof,NSPV_txproofresult.txprooflen);
|
||||
}
|
||||
fprintf(stderr,"call NSPV_notarizations\n");
|
||||
NSPV_notarizations(height); // gets the prev and next notarizations
|
||||
if ( NSPV_inforesult.notarization.height >= height && (NSPV_ntzsresult.prevntz.height == 0 || NSPV_ntzsresult.prevntz.height >= NSPV_ntzsresult.nextntz.height) )
|
||||
{
|
||||
fprintf(stderr,"issue manual bracket\n");
|
||||
NSPV_notarizations(height-1);
|
||||
NSPV_notarizations(height+1);
|
||||
NSPV_notarizations(height); // gets the prev and next notarizations
|
||||
}
|
||||
if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height )
|
||||
{
|
||||
fprintf(stderr,">>>>> gettx ht.%d prev.%d next.%d\n",height,NSPV_ntzsresult.prevntz.height, NSPV_ntzsresult.nextntz.height);
|
||||
offset = (height - NSPV_ntzsresult.prevntz.height);
|
||||
if ( offset >= 0 && height <= NSPV_ntzsresult.nextntz.height )
|
||||
{
|
||||
fprintf(stderr,"call NSPV_txidhdrsproof %s %s\n",NSPV_ntzsresult.prevntz.txid.GetHex().c_str(),NSPV_ntzsresult.nextntz.txid.GetHex().c_str());
|
||||
NSPV_txidhdrsproof(NSPV_ntzsresult.prevntz.txid,NSPV_ntzsresult.nextntz.txid);
|
||||
usleep(10000);
|
||||
if ( (retval= NSPV_validatehdrs(&NSPV_ntzsproofresult)) == 0 )
|
||||
{
|
||||
std::vector<uint256> txids; uint256 proofroot;
|
||||
proofroot = BitcoinGetProofMerkleRoot(proof,txids);
|
||||
if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot )
|
||||
{
|
||||
fprintf(stderr,"prooflen.%d proofroot.%s vs %s\n",NSPV_txproofresult.txprooflen,proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str());
|
||||
retval = -2003;
|
||||
}
|
||||
}
|
||||
} else retval = -2002;
|
||||
} else retval = -2004;
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
|
||||
int32_t NSPV_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct NSPV_utxoresp utxos[],int32_t numunspents,int64_t value)
|
||||
{
|
||||
int32_t i,abovei,belowi; int64_t above,below,gap,atx_value;
|
||||
|
||||
Reference in New Issue
Block a user