Browse Source

Initial CC support skeleton

warmup
jl777 5 years ago
parent
commit
95dcb9cd32
  1. 5
      src/cc/CCinclude.h
  2. 8
      src/cc/CCtx.cpp
  3. 129
      src/komodo_nSPV.h
  4. 156
      src/komodo_nSPV_defs.h
  5. 1
      src/komodo_nSPV_superlite.h
  6. 9
      src/komodo_nSPV_wallet.h
  7. 1
      src/main.cpp

5
src/cc/CCinclude.h

@ -52,6 +52,7 @@ one other technical note is that komodod has the insight-explorer extensions bui
#include "../utlist.h"
#include "../uthash.h"
#include "merkleblock.h"
#include "../komodo_nSPV_defs.h"
#define CC_BURNPUBKEY "02deaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddead"
#define CC_MAXVINS 1024
@ -287,8 +288,8 @@ 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);
int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs);
int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs);
int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr = 0);
int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr = 0);
int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCflag);
bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey,uint32_t nTime);

8
src/cc/CCtx.cpp

@ -518,13 +518,11 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *
else return(belowi);
}
int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs)
int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr)
{
int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector<COutput> vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up;
int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector<COutput> vecOutputs; CTransaction tx; struct CC_utxosinfo *utxos,*up;
if ( KOMODO_NSPV != 0 )
{
//return(NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64_t total,int32_t maxinputs,struct NSPV_utxoresp *ptr,int32_t num));
}
return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,ptr));
#ifdef ENABLE_WALLET
assert(pwalletMain != NULL);
const CKeyStore& keystore = *pwalletMain;

129
src/komodo_nSPV.h

@ -28,33 +28,6 @@
#ifndef KOMODO_NSPV_H
#define KOMODO_NSPV_H
#define NSPV_POLLITERS 15
#define NSPV_POLLMICROS 100000
#define NSPV_MAXVINS 64
#define NSPV_AUTOLOGOUT 777
#define NSPV_BRANCHID 0x76b809bb
// nSPV defines and struct definitions with serialization and purge functions
#define NSPV_INFO 0x00
#define NSPV_INFORESP 0x01
#define NSPV_UTXOS 0x02
#define NSPV_UTXOSRESP 0x03
#define NSPV_NTZS 0x04
#define NSPV_NTZSRESP 0x05
#define NSPV_NTZSPROOF 0x06
#define NSPV_NTZSPROOFRESP 0x07
#define NSPV_TXPROOF 0x08
#define NSPV_TXPROOFRESP 0x09
#define NSPV_SPENTINFO 0x0a
#define NSPV_SPENTINFORESP 0x0b
#define NSPV_BROADCAST 0x0c
#define NSPV_BROADCASTRESP 0x0d
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);
extern uint256 SIG_TXHASH;
uint32_t NSPV_blocktime(int32_t hdrheight);
int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *buf)
{
if ( rwflag != 0 )
@ -63,18 +36,6 @@ int32_t iguana_rwbuf(int32_t rwflag,uint8_t *serialized,uint16_t len,uint8_t *bu
return(len);
}
struct NSPV_equihdr
{
int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
uint256 hashFinalSaplingRoot;
uint32_t nTime;
uint32_t nBits;
uint256 nNonce;
uint8_t nSolution[1344];
};
int32_t NSPV_rwequihdr(int32_t rwflag,uint8_t *serialized,struct NSPV_equihdr *ptr)
{
int32_t len = 0;
@ -117,13 +78,6 @@ int32_t iguana_rwuint8vec(int32_t rwflag,uint8_t *serialized,uint16_t *vecsizep,
return(len);
}
struct NSPV_utxoresp
{
uint256 txid;
int64_t satoshis,extradata;
int32_t vout,height;
};
int32_t NSPV_rwutxoresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxoresp *ptr)
{
int32_t len = 0;
@ -135,15 +89,6 @@ int32_t NSPV_rwutxoresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxoresp
return(len);
}
struct NSPV_utxosresp
{
struct NSPV_utxoresp *utxos;
char coinaddr[64];
int64_t total,interest;
int32_t nodeheight;
uint16_t numutxos; uint8_t CCflag,pad8;
};
int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosresp *ptr) // check mempool
{
int32_t i,len = 0;
@ -173,22 +118,6 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres
return(len);
}
void NSPV_utxosresp_purge(struct NSPV_utxosresp *ptr)
{
if ( ptr != 0 )
{
if ( ptr->utxos != 0 )
free(ptr->utxos);
memset(ptr,0,sizeof(*ptr));
}
}
struct NSPV_ntz
{
uint256 blockhash,txid,othertxid;
int32_t height,txidheight;
};
int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr)
{
int32_t len = 0;
@ -200,12 +129,6 @@ int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr)
return(len);
}
struct NSPV_ntzsresp
{
struct NSPV_ntz prevntz,nextntz;
int32_t reqheight;
};
int32_t NSPV_rwntzsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzsresp *ptr)
{
int32_t len = 0;
@ -226,14 +149,6 @@ void NSPV_ntzsresp_purge(struct NSPV_ntzsresp *ptr)
memset(ptr,0,sizeof(*ptr));
}
struct NSPV_inforesp
{
struct NSPV_ntz notarization;
uint256 blockhash;
int32_t height,hdrheight;
struct NSPV_equihdr H;
};
int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp *ptr)
{
int32_t len = 0;
@ -252,15 +167,6 @@ void NSPV_inforesp_purge(struct NSPV_inforesp *ptr)
memset(ptr,0,sizeof(*ptr));
}
struct NSPV_txproof
{
uint256 txid;
int64_t unspentvalue;
int32_t height,vout,pad;
uint16_t txlen,txprooflen;
uint8_t *tx,*txproof;
};
int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *ptr)
{
int32_t len = 0;
@ -301,13 +207,6 @@ void NSPV_txproof_purge(struct NSPV_txproof *ptr)
}
}
struct NSPV_ntzproofshared
{
struct NSPV_equihdr *hdrs;
int32_t prevht,nextht,pad32;
uint16_t numhdrs,pad16;
};
int32_t NSPV_rwntzproofshared(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzproofshared *ptr)
{
int32_t len = 0;
@ -320,15 +219,6 @@ int32_t NSPV_rwntzproofshared(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz
return(len);
}
struct NSPV_ntzsproofresp
{
struct NSPV_ntzproofshared common;
uint256 prevtxid,nexttxid;
int32_t pad32,prevtxidht,nexttxidht;
uint16_t prevtxlen,nexttxlen;
uint8_t *prevntz,*nextntz;
};
int32_t NSPV_rwntzsproofresp(int32_t rwflag,uint8_t *serialized,struct NSPV_ntzsproofresp *ptr)
{
int32_t len = 0;
@ -377,19 +267,6 @@ void NSPV_ntzsproofresp_purge(struct NSPV_ntzsproofresp *ptr)
}
}
struct NSPV_MMRproof
{
struct NSPV_ntzproofshared common;
// tbd
};
struct NSPV_spentinfo
{
struct NSPV_txproof spent;
uint256 txid;
int32_t vout,spentvini;
};
int32_t NSPV_rwspentinfo(int32_t rwflag,uint8_t *serialized,struct NSPV_spentinfo *ptr) // check mempool
{
int32_t len = 0;
@ -409,12 +286,6 @@ void NSPV_spentinfo_purge(struct NSPV_spentinfo *ptr)
}
}
struct NSPV_broadcastresp
{
uint256 txid;
int32_t retcode;
};
int32_t NSPV_rwbroadcastresp(int32_t rwflag,uint8_t *serialized,struct NSPV_broadcastresp *ptr)
{
int32_t len = 0;

156
src/komodo_nSPV_defs.h

@ -0,0 +1,156 @@
/******************************************************************************
* Copyright © 2014-2019 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
// todo:
// headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs
// interest calculations are currently just using what is returned, it should calculate it from scratch
// CC signing
// make sure to sanity check all vector lengths on receipt
// make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database)
// bug: under load, fullnode was returning all 0 nServices
#ifndef KOMODO_NSPV_DEFSH
#define KOMODO_NSPV_DEFSH
#define NSPV_POLLITERS 15
#define NSPV_POLLMICROS 100000
#define NSPV_MAXVINS 64
#define NSPV_AUTOLOGOUT 777
#define NSPV_BRANCHID 0x76b809bb
// nSPV defines and struct definitions with serialization and purge functions
#define NSPV_INFO 0x00
#define NSPV_INFORESP 0x01
#define NSPV_UTXOS 0x02
#define NSPV_UTXOSRESP 0x03
#define NSPV_NTZS 0x04
#define NSPV_NTZSRESP 0x05
#define NSPV_NTZSPROOF 0x06
#define NSPV_NTZSPROOFRESP 0x07
#define NSPV_TXPROOF 0x08
#define NSPV_TXPROOFRESP 0x09
#define NSPV_SPENTINFO 0x0a
#define NSPV_SPENTINFORESP 0x0b
#define NSPV_BROADCAST 0x0c
#define NSPV_BROADCASTRESP 0x0d
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);
extern uint256 SIG_TXHASH;
uint32_t NSPV_blocktime(int32_t hdrheight);
struct NSPV_equihdr
{
int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
uint256 hashFinalSaplingRoot;
uint32_t nTime;
uint32_t nBits;
uint256 nNonce;
uint8_t nSolution[1344];
};
struct NSPV_utxoresp
{
uint256 txid;
int64_t satoshis,extradata;
int32_t vout,height;
};
struct NSPV_utxosresp
{
struct NSPV_utxoresp *utxos;
char coinaddr[64];
int64_t total,interest;
int32_t nodeheight;
uint16_t numutxos; uint8_t CCflag,pad8;
};
struct NSPV_ntz
{
uint256 blockhash,txid,othertxid;
int32_t height,txidheight;
};
struct NSPV_ntzsresp
{
struct NSPV_ntz prevntz,nextntz;
int32_t reqheight;
};
struct NSPV_inforesp
{
struct NSPV_ntz notarization;
uint256 blockhash;
int32_t height,hdrheight;
struct NSPV_equihdr H;
};
struct NSPV_txproof
{
uint256 txid;
int64_t unspentvalue;
int32_t height,vout,pad;
uint16_t txlen,txprooflen;
uint8_t *tx,*txproof;
};
struct NSPV_ntzproofshared
{
struct NSPV_equihdr *hdrs;
int32_t prevht,nextht,pad32;
uint16_t numhdrs,pad16;
};
struct NSPV_ntzsproofresp
{
struct NSPV_ntzproofshared common;
uint256 prevtxid,nexttxid;
int32_t pad32,prevtxidht,nexttxidht;
uint16_t prevtxlen,nexttxlen;
uint8_t *prevntz,*nextntz;
};
struct NSPV_MMRproof
{
struct NSPV_ntzproofshared common;
// tbd
};
struct NSPV_spentinfo
{
struct NSPV_txproof spent;
uint256 txid;
int32_t vout,spentvini;
};
struct NSPV_broadcastresp
{
uint256 txid;
int32_t retcode;
};
struct CC_utxosinfo
{
struct NSPV_utxosresp U;
struct NSPV_utxoresp used[NSPV_MAXVINS];
};
#endif // KOMODO_NSPV_DEFSH

1
src/komodo_nSPV_superlite.h

@ -686,5 +686,4 @@ UniValue NSPV_broadcast(char *hex)
return(NSPV_broadcast_json(&B,txid));
}
#endif // KOMODO_NSPVSUPERLITE_H

9
src/komodo_nSPV_wallet.h

@ -406,4 +406,13 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a
}
}
int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCdata *ptr)
{
if ( ptr != 0 )
{
memset(ptr->used,0,sizeof(ptr->used));
return(NSPV_addinputs(ptr->used,mtx,total,maxinputs,ptr->U.utxos,ptr->U.numutxos));
} else return(0);
}
#endif // KOMODO_NSPVWALLET_H

1
src/main.cpp

@ -7060,6 +7060,7 @@ void static ProcessGetData(CNode* pfrom)
}
}
#include "komodo_nSPV_defs.h"
#include "komodo_nSPV.h" // shared defines, structs, serdes, purge functions
#include "komodo_nSPV_fullnode.h" // nSPV fullnode handling of the getnSPV request messages
#include "komodo_nSPV_superlite.h" // nSPV superlite client, issuing requests and handling nSPV responses

Loading…
Cancel
Save