@@ -51,7 +51,7 @@ Komodo is based on Zcash and has been extended by our innovative consensus algor
|
||||
|
||||
```shell
|
||||
#The following packages are needed:
|
||||
sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python python-zmq zlib1g-dev wget libcurl4-gnutls-dev bsdmainutils automake curl
|
||||
sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python python-zmq zlib1g-dev wget libcurl4-gnutls-dev bsdmainutils automake curl libsodium-dev
|
||||
```
|
||||
|
||||
### Build Komodo
|
||||
@@ -102,7 +102,7 @@ cd komodo
|
||||
#### Windows
|
||||
Use a debian cross-compilation setup with mingw for windows and run:
|
||||
```shell
|
||||
sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python python-zmq zlib1g-dev wget libcurl4-gnutls-dev bsdmainutils automake curl cmake mingw-w64
|
||||
sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python python-zmq zlib1g-dev wget libcurl4-gnutls-dev bsdmainutils automake curl cmake mingw-w64 libsodium-dev libevent-dev
|
||||
curl https://sh.rustup.rs -sSf | sh
|
||||
source $HOME/.cargo/env
|
||||
rustup target add x86_64-pc-windows-gnu
|
||||
|
||||
@@ -91,7 +91,7 @@ void WaitForShutdown(boost::thread_group* threadGroup)
|
||||
//fprintf(stderr,"call passport iteration\n");
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
{
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
komodo_passport_iteration();
|
||||
for (i=0; i<10; i++)
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ one other technical note is that komodod has the insight-explorer extensions bui
|
||||
|
||||
#define CC_BURNPUBKEY "02deaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddead"
|
||||
#define CC_MAXVINS 1024
|
||||
#define CC_REQUIREMENTS_MSG (KOMODO_NSPV!=0?"to use CC contracts you need to nspv_login first\n":"to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n")
|
||||
#define CC_REQUIREMENTS_MSG (KOMODO_NSPV_SUPERLITE?"to use CC contracts you need to nspv_login first\n":"to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n")
|
||||
|
||||
#define SMALLVAL 0.000000000000001
|
||||
#define SATOSHIDEN ((uint64_t)100000000L)
|
||||
@@ -292,6 +292,7 @@ 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);
|
||||
void SetCCtxids_NSPV(std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,char *coinaddr,bool ccflag, uint8_t evalcode, uint256 filtertxid);
|
||||
int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr);
|
||||
int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs);
|
||||
int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs);
|
||||
|
||||
@@ -957,7 +957,7 @@ UniValue TokenInfo(uint256 tokenid)
|
||||
result.push_back(Pair("error", "cant find tokenid"));
|
||||
return(result);
|
||||
}
|
||||
if ( KOMODO_NSPV <= 0 && hashBlock.IsNull()) {
|
||||
if ( KOMODO_NSPV_FULLNODE && hashBlock.IsNull()) {
|
||||
result.push_back(Pair("result", "error"));
|
||||
result.push_back(Pair("error", "the transaction is still in mempool"));
|
||||
return(result);
|
||||
|
||||
@@ -162,7 +162,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
|
||||
utxovout = mtx.vin[i].prevout.n;
|
||||
if ( vintx.vout[utxovout].scriptPubKey.IsPayToCryptoCondition() == 0 )
|
||||
{
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
{
|
||||
if ( SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 )
|
||||
fprintf(stderr,"signing error for vini.%d of %llx\n",i,(long long)vinimask);
|
||||
@@ -340,11 +340,12 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
|
||||
|
||||
void NSPV_CCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs,char *coinaddr,bool ccflag);
|
||||
void NSPV_CCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &txids,char *coinaddr,bool ccflag);
|
||||
void NSPV_CCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &txids,char *coinaddr,bool ccflag,uint8_t evalcode,uint256 filtertxid);
|
||||
|
||||
void SetCCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs,char *coinaddr,bool ccflag)
|
||||
{
|
||||
int32_t type=0,i,n; char *ptr; std::string addrstr; uint160 hashBytes; std::vector<std::pair<uint160, int> > addresses;
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
NSPV_CCunspents(unspentOutputs,coinaddr,ccflag);
|
||||
return;
|
||||
@@ -368,7 +369,7 @@ void SetCCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValu
|
||||
void SetCCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,char *coinaddr,bool ccflag)
|
||||
{
|
||||
int32_t type=0,i,n; char *ptr; std::string addrstr; uint160 hashBytes; std::vector<std::pair<uint160, int> > addresses;
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
NSPV_CCtxids(addressIndex,coinaddr,ccflag);
|
||||
return;
|
||||
@@ -389,6 +390,16 @@ void SetCCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex
|
||||
}
|
||||
}
|
||||
|
||||
void SetCCtxids_NSPV(std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,char *coinaddr,bool ccflag, uint8_t evalcode, uint256 filtertxid)
|
||||
{
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
NSPV_CCtxids(addressIndex,coinaddr,ccflag,evalcode,filtertxid);
|
||||
return;
|
||||
}
|
||||
else SetCCtxids(addressIndex,coinaddr,ccflag);
|
||||
}
|
||||
|
||||
int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCflag)
|
||||
{
|
||||
uint256 txid; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
@@ -555,7 +566,7 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *
|
||||
int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs)
|
||||
{
|
||||
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;
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,&NSPV_U));
|
||||
#ifdef ENABLE_WALLET
|
||||
assert(pwalletMain != NULL);
|
||||
@@ -652,7 +663,7 @@ int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinput
|
||||
{
|
||||
int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
return(NSPV_AddNormalinputs(mtx,pubkey2pk(Mypubkey()),total,maxinputs,&NSPV_U));
|
||||
utxos = (struct CC_utxo *)calloc(CC_MAXVINS,sizeof(*utxos));
|
||||
if ( maxinputs > CC_MAXVINS )
|
||||
|
||||
@@ -450,7 +450,7 @@ extern uint32_t NSPV_logintime;
|
||||
bool Myprivkey(uint8_t myprivkey[])
|
||||
{
|
||||
char coinaddr[64],checkaddr[64]; std::string strAddress; char *dest; int32_t i,n; CBitcoinAddress address; CKeyID keyID; CKey vchSecret; uint8_t buf33[33];
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT )
|
||||
{
|
||||
@@ -590,7 +590,7 @@ int32_t NSPV_coinaddr_inmempool(char const *logcategory,char *coinaddr,uint8_t C
|
||||
int32_t myIs_coinaddr_inmempoolvout(char const *logcategory,char *coinaddr)
|
||||
{
|
||||
int32_t i,n; char destaddr[64];
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
return(NSPV_coinaddr_inmempool(logcategory,coinaddr,1));
|
||||
BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx)
|
||||
{
|
||||
@@ -619,7 +619,7 @@ int32_t myGet_mempool_txs(std::vector<CTransaction> &txs,uint8_t evalcode,uint8_
|
||||
{
|
||||
int i=0;
|
||||
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
CTransaction tx; uint256 hashBlock;
|
||||
|
||||
@@ -673,7 +673,7 @@ bool komodo_txnotarizedconfirmed(uint256 txid)
|
||||
CBlockIndex *pindex;
|
||||
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
|
||||
|
||||
if (KOMODO_NSPV!=0)
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
if ( NSPV_myGetTransaction(txid,tx,hashBlock,txheight,currentheight) == 0 )
|
||||
{
|
||||
|
||||
@@ -846,7 +846,7 @@ UniValue ChannelsInfo(uint256 channeltxid)
|
||||
result.push_back(Pair("Amount (satoshi)",i64tostr(param1*param2)));
|
||||
}
|
||||
GetCCaddress(cp,CCaddr,mypk);
|
||||
SetCCtxids(addressIndex,CCaddr,true);
|
||||
SetCCtxids_NSPV(addressIndex,CCaddr,true,EVAL_CHANNELS,opentxid);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
|
||||
{
|
||||
if (myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && it->second==CC_MARKER_VALUE &&
|
||||
|
||||
@@ -629,12 +629,10 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &
|
||||
return eval->Invalid("deposit amount greater then bind total supply");
|
||||
else if (komodo_txnotarizedconfirmed(deposittxid) == false)
|
||||
return eval->Invalid("gatewaysdeposit tx is not yet confirmed(notarised)!");
|
||||
else if (IsCCInput(tx.vin[0].scriptSig) != 0)
|
||||
return eval->Invalid("vin.0 is normal for gatewaysclaim!");
|
||||
else if (tx.vin.size()>2)
|
||||
else if (tx.vin.size()>0)
|
||||
{
|
||||
i=1;
|
||||
while (i<=tx.vin.size()-2)
|
||||
i=0;
|
||||
while (i<tx.vin.size()-1)
|
||||
{
|
||||
if (IsCCInput(tx.vin[i].scriptSig)==0) return eval->Invalid("vin."+std::to_string(i)+" is CC for gatewaysclaim!");
|
||||
i++;
|
||||
@@ -1108,20 +1106,14 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui
|
||||
LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl);
|
||||
return("");
|
||||
}
|
||||
if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 )
|
||||
if ((inputs=AddGatewaysInputs(cp, mtx, gatewayspk, bindtxid, amount, 60)) > 0)
|
||||
{
|
||||
if ((inputs=AddGatewaysInputs(cp, mtx, gatewayspk, bindtxid, amount, 60)) > 0)
|
||||
{
|
||||
if ( inputs > amount ) CCchange = (inputs - amount);
|
||||
mtx.vin.push_back(CTxIn(deposittxid,0,CScript()));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS,amount,destpub));
|
||||
if ( CCchange != 0 ) mtx.vout.push_back(MakeTokensCC1vout(EVAL_GATEWAYS,CCchange,gatewayspk));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysClaimOpRet('C',tokenid,bindtxid,refcoin,deposittxid,destpub,amount)));
|
||||
}
|
||||
if ( inputs > amount ) CCchange = (inputs - amount);
|
||||
mtx.vin.push_back(CTxIn(deposittxid,0,CScript()));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS,amount,destpub));
|
||||
if ( CCchange != 0 ) mtx.vout.push_back(MakeTokensCC1vout(EVAL_GATEWAYS,CCchange,gatewayspk));
|
||||
return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysClaimOpRet('C',tokenid,bindtxid,refcoin,deposittxid,destpub,amount)));
|
||||
}
|
||||
CCerror = strprintf("cant find enough inputs or mismatched total");
|
||||
LOGSTREAM("gatewayscc",CCLOG_INFO, stream << CCerror << std::endl);
|
||||
return("");
|
||||
}
|
||||
|
||||
std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,CPubKey withdrawpub,int64_t amount)
|
||||
|
||||
@@ -641,6 +641,7 @@ bool OraclesDataValidate(struct CCcontract_info *cp,Eval* eval,const CTransactio
|
||||
|
||||
int32_t GetLatestTimestamp(int32_t height)
|
||||
{
|
||||
if ( KOMODO_NSPV_SUPERLITE ) return (NSPV_blocktime(height));
|
||||
return(komodo_heightstamp(height));
|
||||
}
|
||||
|
||||
@@ -793,7 +794,7 @@ int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubK
|
||||
char coinaddr[64]; CPubKey pk; int64_t total=0,num; uint256 txid,hashBlock,subtxid; CTransaction subtx;
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
GetCCaddress(cp,coinaddr,publisher);
|
||||
SetCCtxids(addressIndex,coinaddr,true);
|
||||
SetCCtxids_NSPV(addressIndex,coinaddr,true,EVAL_ORACLES,oracletxid);
|
||||
//fprintf(stderr,"scan lifetime of %s\n",coinaddr);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
|
||||
{
|
||||
|
||||
@@ -1234,7 +1234,7 @@ UniValue PegsAccountHistory(uint256 pegstxid)
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
pegspk = GetUnspendable(cp,0);
|
||||
GetCCaddress1of2(cp,coinaddr,mypk,pegspk);
|
||||
SetCCtxids(txids,coinaddr,true);
|
||||
SetCCtxids_NSPV(txids,coinaddr,true,EVAL_PEGS,pegstxid);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=txids.begin(); it!=txids.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
|
||||
@@ -21,6 +21,14 @@
|
||||
extern int32_t KOMODO_NSPV;
|
||||
#define NSPV_BRANCHID 0x76b809bb
|
||||
|
||||
#ifndef KOMODO_NSPV_FULLNODE
|
||||
#define KOMODO_NSPV_FULLNODE (KOMODO_NSPV <= 0)
|
||||
#endif // !KOMODO_NSPV_FULLNODE
|
||||
|
||||
#ifndef KOMODO_NSPV_SUPERLITE
|
||||
#define KOMODO_NSPV_SUPERLITE (KOMODO_NSPV > 0)
|
||||
#endif // !KOMODO_NSPV_SUPERLITE
|
||||
|
||||
/**
|
||||
* General information about each network upgrade.
|
||||
* Ordered by Consensus::UpgradeIndex.
|
||||
@@ -101,7 +109,7 @@ int CurrentEpoch(int nHeight, const Consensus::Params& params) {
|
||||
|
||||
uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params)
|
||||
{
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
return(NSPV_BRANCHID);
|
||||
return NetworkUpgradeInfo[CurrentEpoch(nHeight, params)].nBranchId;
|
||||
}
|
||||
|
||||
10
src/init.cpp
10
src/init.cpp
@@ -1066,7 +1066,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
RegisterAllCoreRPCCommands(tableRPC);
|
||||
#ifdef ENABLE_WALLET
|
||||
bool fDisableWallet = GetBoolArg("-disablewallet", false);
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
fDisableWallet = true;
|
||||
nLocalServices = 0;
|
||||
@@ -1147,7 +1147,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
// Option to startup with mocktime set (used for regression testing):
|
||||
SetMockTime(GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op
|
||||
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
{
|
||||
if (GetBoolArg("-peerbloomfilters", true))
|
||||
nLocalServices |= NODE_BLOOM;
|
||||
@@ -1306,7 +1306,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
libsnark::inhibit_profiling_info = true;
|
||||
libsnark::inhibit_profiling_counters = true;
|
||||
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
{
|
||||
// Initialize Zcash circuit parameters
|
||||
ZC_LoadParams(chainparams);
|
||||
@@ -1487,7 +1487,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
std::vector<boost::filesystem::path> vImportFiles;
|
||||
threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles));
|
||||
@@ -1911,7 +1911,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
PruneAndFlush();
|
||||
}
|
||||
}
|
||||
if ( KOMODO_NSPV >= 0 )
|
||||
if ( KOMODO_NSPV == 0 )
|
||||
{
|
||||
if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) != 0 )
|
||||
nLocalServices |= NODE_ADDRINDEX;
|
||||
|
||||
@@ -67,9 +67,14 @@ void komodo_currentheight_set(int32_t height)
|
||||
sp->CURRENT_HEIGHT = height;
|
||||
}
|
||||
|
||||
extern struct NSPV_inforesp NSPV_inforesult;
|
||||
int32_t komodo_currentheight()
|
||||
{
|
||||
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
return (NSPV_inforesult.height);
|
||||
}
|
||||
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
|
||||
return(sp->CURRENT_HEIGHT);
|
||||
else return(0);
|
||||
|
||||
@@ -345,4 +345,11 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui
|
||||
|
||||
uint256 Parseuint256(const char *hexstr);
|
||||
|
||||
#ifndef KOMODO_NSPV_FULLNODE
|
||||
#define KOMODO_NSPV_FULLNODE (KOMODO_NSPV <= 0)
|
||||
#endif // !KOMODO_NSPV_FULLNODE
|
||||
#ifndef KOMODO_NSPV_SUPERLITE
|
||||
#define KOMODO_NSPV_SUPERLITE (KOMODO_NSPV > 0)
|
||||
#endif // !KOMODO_NSPV_SUPERLITE
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#ifndef KOMODO_NSPV_DEFSH
|
||||
#define KOMODO_NSPV_DEFSH
|
||||
|
||||
#define NSPV_PROTOCOL_VERSION 0x00000002
|
||||
#define NSPV_PROTOCOL_VERSION 0x00000003
|
||||
#define NSPV_POLLITERS 200
|
||||
#define NSPV_POLLMICROS 50000
|
||||
#define NSPV_MAXVINS 64
|
||||
|
||||
@@ -172,7 +172,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC
|
||||
{
|
||||
// if gettxout is != null to handle mempool
|
||||
{
|
||||
if ( n >= skipcount )
|
||||
if ( n >= skipcount && myIsutxo_spentinmempool(ignoretxid,ignorevin,it->first.txhash,(int32_t)it->first.index) == 0 )
|
||||
{
|
||||
ptr->utxos[ind].txid = it->first.txhash;
|
||||
ptr->utxos[ind].vout = (int32_t)it->first.index;
|
||||
@@ -208,8 +208,13 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC
|
||||
|
||||
int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC,int32_t skipcount,uint32_t filter)
|
||||
{
|
||||
int32_t maxlen,txheight,ind=0,n = 0,len = 0;
|
||||
int32_t maxlen,txheight,ind=0,n = 0,len = 0; CTransaction tx; uint256 hashBlock,filtertxid;
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > txids;
|
||||
if (ptr->txids!=0)
|
||||
{
|
||||
filtertxid=ptr->txids[0].txid;
|
||||
free(ptr->txids);
|
||||
}
|
||||
SetCCtxids(txids,coinaddr,isCC);
|
||||
ptr->nodeheight = chainActive.LastTip()->GetHeight();
|
||||
maxlen = MAX_BLOCK_SIZE(ptr->nodeheight) - 512;
|
||||
@@ -231,6 +236,32 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC
|
||||
{
|
||||
if ( n >= skipcount )
|
||||
{
|
||||
if (filter&0xFF!=0)
|
||||
{
|
||||
myGetTransaction(it->first.txhash,tx,hashBlock);
|
||||
std::vector<std::pair<uint8_t, vscript_t>> oprets; uint256 tokenid,txid;
|
||||
std::vector<uint8_t> vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode;
|
||||
std::vector<CPubKey> pubkeys;
|
||||
|
||||
if (DecodeTokenOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,tokenevalcode,tokenid,pubkeys,oprets)!=0 && GetOpretBlob(oprets, OPRETID_CHANNELSDATA, vOpretExtra) && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0)
|
||||
{
|
||||
vopret=vOpretExtra;
|
||||
}
|
||||
else GetOpReturnData(tx.vout[tx.vout.size()-1].scriptPubKey, vopret);
|
||||
script = (uint8_t *)vopret.data();
|
||||
if ( vopret.size() > 2 && script[0]==filter&0xFF )
|
||||
{
|
||||
switch (filter&0xFF)
|
||||
{
|
||||
case EVAL_CHANNELS:EVAL_PEGS:EVAL_ORACLES:
|
||||
E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> txid;);
|
||||
if (txid!=filtertxid && e==filter&0xFF) continue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ptr->txids[ind].txid = it->first.txhash;
|
||||
ptr->txids[ind].vout = (int32_t)it->first.index;
|
||||
ptr->txids[ind].satoshis = (int64_t)it->second;
|
||||
@@ -250,10 +281,11 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC
|
||||
return(0);
|
||||
}
|
||||
|
||||
int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector<uint256> &txids,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout)
|
||||
int32_t NSPV_mempoolfuncs(bits256 *satoshisp,int32_t *vindexp,std::vector<uint256> &txids,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout)
|
||||
{
|
||||
int32_t num = 0,vini = 0,vouti = 0; uint8_t evalcode=0,func=0; std::vector<uint8_t> vopret; char destaddr[64];
|
||||
*vindexp = -1;
|
||||
memset(satoshisp,0,sizeof(*satoshisp));
|
||||
if ( mempool.size() == 0 )
|
||||
return(0);
|
||||
if ( funcid == NSPV_MEMPOOL_CCEVALCODE )
|
||||
@@ -323,6 +355,8 @@ int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector<uint256> &txids,char *coi
|
||||
{
|
||||
txids.push_back(hash);
|
||||
*vindexp = vouti;
|
||||
if ( num < 4 )
|
||||
satoshisp->ulongs[num] = txout.nValue;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
@@ -336,14 +370,14 @@ int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector<uint256> &txids,char *coi
|
||||
|
||||
int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,uint8_t isCC,uint8_t funcid,uint256 txid,int32_t vout)
|
||||
{
|
||||
std::vector<uint256> txids; uint256 tmp,tmpdest; int32_t i,len = 0;
|
||||
std::vector<uint256> txids; bits256 satoshis; uint256 tmp,tmpdest; int32_t i,len = 0;
|
||||
ptr->nodeheight = chainActive.LastTip()->GetHeight();
|
||||
strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1);
|
||||
ptr->CCflag = isCC;
|
||||
ptr->txid = txid;
|
||||
ptr->vout = vout;
|
||||
ptr->funcid = funcid;
|
||||
if ( NSPV_mempoolfuncs(&ptr->vindex,txids,coinaddr,isCC,funcid,txid,vout) >= 0 )
|
||||
if ( NSPV_mempoolfuncs(&satoshis,&ptr->vindex,txids,coinaddr,isCC,funcid,txid,vout) >= 0 )
|
||||
{
|
||||
if ( (ptr->numtxids= (int32_t)txids.size()) >= 0 )
|
||||
{
|
||||
@@ -356,6 +390,11 @@ int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,uint8_t is
|
||||
iguana_rwbignum(0,(uint8_t *)&tmp,sizeof(*ptr->txids),(uint8_t *)&ptr->txids[i]);
|
||||
}
|
||||
}
|
||||
if ( funcid == NSPV_MEMPOOL_ADDRESS )
|
||||
{
|
||||
memcpy(&tmp,&satoshis,sizeof(tmp));
|
||||
iguana_rwbignum(0,(uint8_t *)&tmp,sizeof(ptr->txid),(uint8_t *)&ptr->txid);
|
||||
}
|
||||
len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->txids)*ptr->numtxids - sizeof(ptr->txids));
|
||||
return(len);
|
||||
}
|
||||
@@ -413,46 +452,48 @@ int32_t NSPV_sendrawtransaction(struct NSPV_broadcastresp *ptr,uint8_t *data,int
|
||||
int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32_t height)
|
||||
{
|
||||
int32_t flag = 0,len = 0; CTransaction _tx; uint256 hashBlock; CBlock block; CBlockIndex *pindex;
|
||||
if ( (ptr->tx= NSPV_getrawtx(_tx,hashBlock,&ptr->txlen,txid)) == 0 )
|
||||
return(-1);
|
||||
ptr->txid = txid;
|
||||
ptr->vout = vout;
|
||||
ptr->hashblock = hashBlock;
|
||||
if ( height == 0 )
|
||||
ptr->height = komodo_blockheight(hashBlock);
|
||||
else
|
||||
ptr->height = -1;
|
||||
if ( (ptr->tx= NSPV_getrawtx(_tx,hashBlock,&ptr->txlen,txid)) != 0 )
|
||||
{
|
||||
ptr->height = height;
|
||||
if ((pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 )
|
||||
ptr->txid = txid;
|
||||
ptr->vout = vout;
|
||||
ptr->hashblock = hashBlock;
|
||||
if ( height == 0 )
|
||||
ptr->height = komodo_blockheight(hashBlock);
|
||||
else
|
||||
{
|
||||
BOOST_FOREACH(const CTransaction&tx, block.vtx)
|
||||
ptr->height = height;
|
||||
if ( (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 )
|
||||
{
|
||||
if ( tx.GetHash() == txid )
|
||||
BOOST_FOREACH(const CTransaction&tx, block.vtx)
|
||||
{
|
||||
flag = 1;
|
||||
break;
|
||||
if ( tx.GetHash() == txid )
|
||||
{
|
||||
flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( flag != 0 )
|
||||
{
|
||||
set<uint256> setTxids;
|
||||
CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION);
|
||||
setTxids.insert(txid);
|
||||
CMerkleBlock mb(block, setTxids);
|
||||
ssMB << mb;
|
||||
std::vector<uint8_t> proof(ssMB.begin(), ssMB.end());
|
||||
ptr->txprooflen = (int32_t)proof.size();
|
||||
//fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str());
|
||||
if ( ptr->txprooflen > 0 )
|
||||
if ( flag != 0 )
|
||||
{
|
||||
ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen);
|
||||
memcpy(ptr->txproof,&proof[0],ptr->txprooflen);
|
||||
set<uint256> setTxids;
|
||||
CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION);
|
||||
setTxids.insert(txid);
|
||||
CMerkleBlock mb(block, setTxids);
|
||||
ssMB << mb;
|
||||
std::vector<uint8_t> proof(ssMB.begin(), ssMB.end());
|
||||
ptr->txprooflen = (int32_t)proof.size();
|
||||
//fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str());
|
||||
if ( ptr->txprooflen > 0 )
|
||||
{
|
||||
ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen);
|
||||
memcpy(ptr->txproof,&proof[0],ptr->txprooflen);
|
||||
}
|
||||
//fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen));
|
||||
}
|
||||
//fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen));
|
||||
}
|
||||
}
|
||||
ptr->unspentvalue = CCgettxout(txid,vout,1,1);
|
||||
}
|
||||
ptr->unspentvalue = CCgettxout(txid,vout,1,1);
|
||||
return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen);
|
||||
}
|
||||
|
||||
@@ -576,7 +617,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> request) // received a req
|
||||
else
|
||||
{
|
||||
isCC = (request[len-9] != 0);
|
||||
iguana_rwnum(0,&request[len-4],sizeof(skipcount),&skipcount);
|
||||
iguana_rwnum(0,&request[len-8],sizeof(skipcount),&skipcount);
|
||||
iguana_rwnum(0,&request[len-4],sizeof(filter),&filter);
|
||||
}
|
||||
if ( isCC != 0 )
|
||||
@@ -616,7 +657,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> request) // received a req
|
||||
else
|
||||
{
|
||||
isCC = (request[len-9] != 0);
|
||||
iguana_rwnum(0,&request[len-4],sizeof(skipcount),&skipcount);
|
||||
iguana_rwnum(0,&request[len-8],sizeof(skipcount),&skipcount);
|
||||
iguana_rwnum(0,&request[len-4],sizeof(filter),&filter);
|
||||
}
|
||||
//if ( isCC != 0 )
|
||||
|
||||
@@ -214,7 +214,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector<uint8_t> response) // received a r
|
||||
CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind)
|
||||
{
|
||||
int32_t n,flag = 0; CNode *pnodes[64]; uint32_t timestamp = (uint32_t)time(NULL);
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
return(0);
|
||||
if ( pnode == 0 )
|
||||
{
|
||||
@@ -243,7 +243,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind)
|
||||
std::vector<uint8_t> request;
|
||||
request.resize(len);
|
||||
memcpy(&request[0],msg,len);
|
||||
if ( (0) && KOMODO_NSPV > 0 )
|
||||
if ( (0) && KOMODO_NSPV_SUPERLITE )
|
||||
fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len);
|
||||
pnode->PushMessage("getnSPV",request);
|
||||
pnode->prevtimes[ind] = timestamp;
|
||||
@@ -279,7 +279,7 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages
|
||||
return;
|
||||
if ( pto->prevtimes[NSPV_INFO>>1] > timestamp )
|
||||
pto->prevtimes[NSPV_INFO>>1] = 0;
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 )
|
||||
{
|
||||
@@ -355,7 +355,7 @@ 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"));
|
||||
result.push_back(Pair("nSPV",KOMODO_NSPV!=0?"superlite":"fullnode"));
|
||||
result.push_back(Pair("nSPV",KOMODO_NSPV==-1?"disabled":(KOMODO_NSPV_SUPERLITE?"superlite":"fullnode")));
|
||||
if ( NSPV_address.size() != 0 )
|
||||
{
|
||||
result.push_back(Pair("address",NSPV_address));
|
||||
@@ -537,7 +537,7 @@ UniValue NSPV_login(char *wifstr)
|
||||
result.push_back(Pair("address",NSPV_address));
|
||||
result.push_back(Pair("pubkey",HexStr(pubkey)));
|
||||
strcpy(NSPV_pubkeystr,HexStr(pubkey).c_str());
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
decode_hex(NOTARY_PUBKEY33,33,NSPV_pubkeystr);
|
||||
result.push_back(Pair("wifprefix",(int64_t)data[0]));
|
||||
result.push_back(Pair("compressed",(int64_t)(data[len-5] == 1)));
|
||||
@@ -621,7 +621,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount,int32
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter)
|
||||
UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter, uint256 filtertxid)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint8_t msg[512]; int32_t i,iter,slen,len = 0;
|
||||
if ( NSPV_txidsresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag && skipcount == NSPV_txidsresult.skipcount )
|
||||
@@ -642,6 +642,11 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,int32
|
||||
msg[len++] = (CCflag != 0);
|
||||
len += iguana_rwnum(1,&msg[len],sizeof(skipcount),&skipcount);
|
||||
len += iguana_rwnum(1,&msg[len],sizeof(filter),&filter);
|
||||
if (filtertxid!=zeroid)
|
||||
{
|
||||
NSPV_txidsresult.txids = (struct NSPV_txidresp *)malloc(sizeof(NSPV_txidsresult.txids));
|
||||
NSPV_txidsresult.txids[0].txid=filtertxid;
|
||||
}
|
||||
//fprintf(stderr,"skipcount.%d\n",skipcount);
|
||||
for (iter=0; iter<3; iter++)
|
||||
if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 )
|
||||
|
||||
@@ -452,12 +452,12 @@ int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total
|
||||
mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID;
|
||||
mtx.nVersion = SAPLING_TX_VERSION;
|
||||
Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG);
|
||||
if ( strcmp(ptr->U.coinaddr,coinaddr) != 0 )
|
||||
{
|
||||
// if ( strcmp(ptr->U.coinaddr,coinaddr) != 0 )
|
||||
// {
|
||||
NSPV_addressutxos(coinaddr,CCflag,0,0);
|
||||
NSPV_utxosresp_purge(&ptr->U);
|
||||
NSPV_utxosresp_copy(&ptr->U,&NSPV_utxosresult);
|
||||
}
|
||||
// }
|
||||
fprintf(stderr,"%s numutxos.%d\n",ptr->U.coinaddr,ptr->U.numutxos);
|
||||
memset(ptr->used,0,sizeof(ptr->used));
|
||||
return(NSPV_addinputs(ptr->used,mtx,total,maxinputs,ptr->U.utxos,ptr->U.numutxos));
|
||||
@@ -522,7 +522,14 @@ void NSPV_CCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentVa
|
||||
void NSPV_CCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &txids,char *coinaddr,bool ccflag)
|
||||
{
|
||||
int32_t filter = 0;
|
||||
NSPV_addresstxids(coinaddr,ccflag,0,filter);
|
||||
NSPV_addresstxids(coinaddr,ccflag,0,filter,zeroid);
|
||||
NSPV_txids2CCtxids(&NSPV_txidsresult,txids);
|
||||
}
|
||||
|
||||
void NSPV_CCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &txids,char *coinaddr,bool ccflag, uint8_t evalcode,uint256 filtertxid)
|
||||
{
|
||||
int32_t filter = evalcode;
|
||||
NSPV_addresstxids(coinaddr,ccflag,0,filter,filtertxid);
|
||||
NSPV_txids2CCtxids(&NSPV_txidsresult,txids);
|
||||
}
|
||||
|
||||
|
||||
36
src/main.cpp
36
src/main.cpp
@@ -2227,7 +2227,7 @@ bool myAddtomempool(CTransaction &tx, CValidationState *pstate, bool fSkipExpiry
|
||||
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock)
|
||||
{
|
||||
memset(&hashBlock,0,sizeof(hashBlock));
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
int64_t rewardsum = 0; int32_t i,retval,txheight,currentheight,height=0,vout = 0;
|
||||
for (i=0; i<NSPV_U.U.numutxos; i++)
|
||||
@@ -2281,7 +2281,7 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo
|
||||
bool NSPV_myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, int32_t &txheight, int32_t ¤theight)
|
||||
{
|
||||
memset(&hashBlock,0,sizeof(hashBlock));
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
int64_t rewardsum = 0; int32_t i,retval,height=0,vout = 0;
|
||||
for (i=0; i<NSPV_U.U.numutxos; i++)
|
||||
@@ -3427,7 +3427,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
||||
{
|
||||
CDiskBlockPos blockPos;
|
||||
const CChainParams& chainparams = Params();
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
return(true);
|
||||
if ( KOMODO_STOPAT != 0 && pindex->GetHeight() > KOMODO_STOPAT )
|
||||
return(false);
|
||||
@@ -4011,7 +4011,7 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
|
||||
|
||||
void FlushStateToDisk() {
|
||||
CValidationState state;
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
FlushStateToDisk(state, FLUSH_STATE_ALWAYS);
|
||||
}
|
||||
|
||||
@@ -4162,7 +4162,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
|
||||
if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight(),true) != 0)))
|
||||
{
|
||||
#ifdef ENABLE_WALLET
|
||||
if ( !GetBoolArg("-disablewallet", false) && KOMODO_NSPV <= 0 )
|
||||
if ( !GetBoolArg("-disablewallet", false) && KOMODO_NSPV_FULLNODE )
|
||||
pwalletMain->EraseFromWallet(tx.GetHash());
|
||||
#endif
|
||||
}
|
||||
@@ -4267,7 +4267,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
|
||||
// Get the current commitment tree
|
||||
SproutMerkleTree oldSproutTree;
|
||||
SaplingMerkleTree oldSaplingTree;
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
{
|
||||
assert(pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), oldSproutTree));
|
||||
assert(pcoinsTip->GetSaplingAnchorAt(pcoinsTip->GetBestAnchor(SAPLING), oldSaplingTree));
|
||||
@@ -4296,13 +4296,13 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
|
||||
mapBlockSource.erase(pindexNew->GetBlockHash());
|
||||
nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2;
|
||||
LogPrint("bench", " - Connect total: %.2fms [%.2fs]\n", (nTime3 - nTime2) * 0.001, nTimeConnectTotal * 0.000001);
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
assert(view.Flush());
|
||||
}
|
||||
int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3;
|
||||
LogPrint("bench", " - Flush: %.2fms [%.2fs]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001);
|
||||
// Write the chain state to disk, if necessary.
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
{
|
||||
if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED))
|
||||
return false;
|
||||
@@ -4318,7 +4318,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
|
||||
|
||||
// Update chainActive & related variables.
|
||||
UpdateTip(pindexNew);
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
{
|
||||
// Tell wallet about transactions that went from mempool
|
||||
// to conflicted:
|
||||
@@ -4346,7 +4346,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
|
||||
komodo_broadcast(pblock,8);
|
||||
else if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
komodo_broadcast(pblock,4);*/
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
{
|
||||
if ( ASSETCHAINS_CBOPRET != 0 )
|
||||
komodo_pricesupdate(pindexNew->GetHeight(),pblock);
|
||||
@@ -6568,7 +6568,7 @@ bool InitBlockIndex() {
|
||||
if (!ActivateBestChain(true, state, &block))
|
||||
return error("LoadBlockIndex(): genesis block cannot be activated");
|
||||
// Force a chainstate write so that when we VerifyDB in a moment, it doesn't check stale data
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
return FlushStateToDisk(state, FLUSH_STATE_ALWAYS);
|
||||
else return(true);
|
||||
} catch (const std::runtime_error& e) {
|
||||
@@ -7128,7 +7128,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id);
|
||||
//if ( KOMODO_NSPV > 0 )
|
||||
//if ( KOMODO_NSPV_SUPERLITE )
|
||||
//if ( strCommand != "version" && strCommand != "verack" )
|
||||
// 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)
|
||||
@@ -7303,7 +7303,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
{
|
||||
pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION));
|
||||
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
if ( (pfrom->nServices & NODE_NSPV) == 0 )
|
||||
{
|
||||
@@ -7503,7 +7503,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
}
|
||||
else if (strCommand == "getnSPV")
|
||||
{
|
||||
if ( KOMODO_NSPV == 0 && KOMODO_INSYNC != 0 )
|
||||
if ( KOMODO_NSPV == 0 )//&& KOMODO_INSYNC != 0 )
|
||||
{
|
||||
std::vector<uint8_t> payload;
|
||||
vRecv >> payload;
|
||||
@@ -7513,7 +7513,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
}
|
||||
else if (strCommand == "nSPV")
|
||||
{
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
std::vector<uint8_t> payload;
|
||||
vRecv >> payload;
|
||||
@@ -7521,7 +7521,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
else if ( KOMODO_NSPV > 0 )
|
||||
else if ( KOMODO_NSPV_SUPERLITE )
|
||||
return(true);
|
||||
else if (strCommand == "inv")
|
||||
{
|
||||
@@ -8311,7 +8311,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
}
|
||||
state.fShouldBan = false;
|
||||
}
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
komodo_nSPV(pto);
|
||||
return(true);
|
||||
@@ -8522,7 +8522,7 @@ extern "C" const char* getDataDir()
|
||||
CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight)
|
||||
{
|
||||
CMutableTransaction mtx;
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
mtx.fOverwintered = true;
|
||||
mtx.nExpiryHeight = 0;
|
||||
|
||||
@@ -1920,9 +1920,9 @@ void static BitcoinMiner()
|
||||
if ( !TestBlockValidity(state,B, chainActive.LastTip(), true, false))
|
||||
{
|
||||
h = UintToArith256(B.GetHash());
|
||||
for (z=31; z>=0; z--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&h)[z]);
|
||||
fprintf(stderr," Invalid block mined, try again\n");
|
||||
//for (z=31; z>=0; z--)
|
||||
// fprintf(stderr,"%02x",((uint8_t *)&h)[z]);
|
||||
//fprintf(stderr," Invalid block mined, try again\n");
|
||||
gotinvalid = 1;
|
||||
return(false);
|
||||
}
|
||||
|
||||
@@ -445,6 +445,13 @@ void CNode::CloseSocketDisconnect()
|
||||
}
|
||||
|
||||
extern int32_t KOMODO_NSPV;
|
||||
#ifndef KOMODO_NSPV_FULLNODE
|
||||
#define KOMODO_NSPV_FULLNODE (KOMODO_NSPV <= 0)
|
||||
#endif // !KOMODO_NSPV_FULLNODE
|
||||
|
||||
#ifndef KOMODO_NSPV_SUPERLITE
|
||||
#define KOMODO_NSPV_SUPERLITE (KOMODO_NSPV > 0)
|
||||
#endif // !KOMODO_NSPV_SUPERLITE
|
||||
|
||||
void CNode::PushVersion()
|
||||
{
|
||||
@@ -1843,7 +1850,7 @@ bool StopNode()
|
||||
for (int i=0; i<MAX_OUTBOUND_CONNECTIONS; i++)
|
||||
semOutbound->post();
|
||||
|
||||
if (KOMODO_NSPV <= 0 && fAddressesInitialized)
|
||||
if (KOMODO_NSPV_FULLNODE && fAddressesInitialized)
|
||||
{
|
||||
DumpAddresses();
|
||||
fAddressesInitialized = false;
|
||||
|
||||
438
src/pow.cpp
438
src/pow.cpp
@@ -42,6 +42,195 @@ uint32_t komodo_chainactive_timestamp();
|
||||
unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params);
|
||||
unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const Consensus::Params& params);
|
||||
|
||||
/* from zawy repo
|
||||
Preliminary code for super-fast increases in difficulty.
|
||||
Requires the ability to change the difficulty during the current block,
|
||||
based on the timestamp the miner selects. See my github issue #36 and KMD.
|
||||
Needs intr-block exponential decay function because
|
||||
this can make difficulty jump very high.
|
||||
Miners need to caclulate new difficulty with each second, or
|
||||
maybe 3 seconds. FTL, MTP, and revert to local times must be small.
|
||||
MTP=1 if using Digishield. Out-of-sequence timestamps must be forbidden.
|
||||
1) bnTarget = Digishield() or other baseline DA
|
||||
2) bnTarget = RT_CST_RST()
|
||||
3) bnTarget = max(bnTarget,expdecay())
|
||||
RT_CST_RST() multiplies Recent Target(s), Current Solvetimes, &
|
||||
Recent SolveTime if RST had an unlikely 1/200 block chance of
|
||||
being too fast on accident. This estimates and adjusts for recent
|
||||
hashrate aggressively (lots of random error) but corrects the error by
|
||||
CST adjusting the difficulty during the block.
|
||||
It checks to see if there was an "active trigger" still in play which
|
||||
occurs when recent block emission rate has been too fast. Triggers
|
||||
are supposed to be active if emission rate has not slowed up enough
|
||||
to get back on track. It checks the longest range first because it's
|
||||
the least aggressive.
|
||||
T = target blocktime
|
||||
ts = timestamp vector, 62 elements, 62 is oldest (elements needed are 50+W)
|
||||
ct = cumulative targets, 62 elements, 62 is oldest
|
||||
W = window size of recent solvetimes and targets to use that estimates hashrate
|
||||
numerator & deonominator needed for 1/200 possion estimator
|
||||
past = how far back in past to look for beginning of a trigger
|
||||
*/
|
||||
|
||||
/* create ts and cw vectors
|
||||
// Get bnTarget = Digishield();
|
||||
|
||||
arith_uint256 past = 50;
|
||||
|
||||
arith_uint256 W = 12;
|
||||
arith_uint256 numerator = 12;
|
||||
arith_uint256 denominator = 7;
|
||||
|
||||
// bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past);
|
||||
|
||||
W = 6; top = 7; denominator = 3;
|
||||
|
||||
// bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past);
|
||||
|
||||
W = 3; top = 1; denominator = 2;
|
||||
|
||||
bnTarget = RT_CST_RST (bnTarget, ts, cw, numerator, denominator, W, T, past);
|
||||
*/
|
||||
|
||||
#define T ASSETCHAINS_BLOCKTIME
|
||||
#define K ((int64_t)1000000)
|
||||
|
||||
#ifdef original_algo
|
||||
arith_uint256 oldRT_CST_RST(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past)
|
||||
{
|
||||
//if (ts.size() < 2*W || ct.size() < 2*W ) { exit; } // error. a vector was too small
|
||||
//if (ts.size() < past+W || ct.size() < past+W ) { past = min(ct.size(), ts.size()) - W; } // past was too small, adjust
|
||||
int64_t altK; int32_t i,j,k,ii=0; // K is a scaling factor for integer divisions
|
||||
if ( height < 64 )
|
||||
return(bnTarget);
|
||||
//if ( ((ts[0]-ts[W]) * W * 100)/(W-1) < (T * numerator * 100)/denominator )
|
||||
if ( (ts[0] - ts[W]) < (T * numerator)/denominator )
|
||||
{
|
||||
//bnTarget = ((ct[0]-ct[1])/K) * max(K,(K*(nTime-ts[0])*(ts[0]-ts[W])*denominator/numerator)/T/T);
|
||||
bnTarget = ct[0] / arith_uint256(K);
|
||||
//altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator * W) / (numerator * (W-1) * (T * T));
|
||||
altK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator) / (numerator * (T * T));
|
||||
fprintf(stderr,"ht.%d initial altK.%lld %d * %d * %d / %d\n",height,(long long)altK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator);
|
||||
if ( altK > K )
|
||||
altK = K;
|
||||
bnTarget *= arith_uint256(altK);
|
||||
if ( altK < K )
|
||||
return(bnTarget);
|
||||
}
|
||||
/* Check past 24 blocks for any sum of 3 STs < T/2 triggers. This is messy
|
||||
because the blockchain does not allow us to store a variable to know
|
||||
if we are currently in a triggered state that is making a sequence of
|
||||
adjustments to prevTargets, so we have to look for them.
|
||||
Nested loops do this: if block emission has not slowed to be back on track at
|
||||
any time since most recent trigger and we are at current block, aggressively
|
||||
adust prevTarget. */
|
||||
|
||||
for (j=past-1; j>=2; j--)
|
||||
{
|
||||
if ( ts[j]-ts[j+W] < T*numerator/denominator )
|
||||
{
|
||||
ii = 0;
|
||||
for (i=j-2; i>=0; i--)
|
||||
{
|
||||
ii++;
|
||||
// Check if emission caught up. If yes, "trigger stopped at i".
|
||||
// Break loop to try more recent j's to see if trigger activates again.
|
||||
if ( (ts[i] - ts[j+W]) > (ii+W)*T )
|
||||
break;
|
||||
|
||||
// We're here, so there was a TS[j]-TS[j-3] < T/2 trigger in the past and emission rate has not yet slowed up to be back on track so the "trigger is still active", aggressively adjusting target here at block "i"
|
||||
if ( i == 0 )
|
||||
{
|
||||
/* We made it all the way to current block. Emission rate since
|
||||
last trigger never slowed enough to get back on track, so adjust again.
|
||||
If avg last 3 STs = T, this increases target to prevTarget as ST increases to T.
|
||||
This biases it towards ST=~1.75*T to get emission back on track.
|
||||
If avg last 3 STs = T/2, target increases to prevTarget at 2*T.
|
||||
Rarely, last 3 STs can be 1/2 speed => target = prevTarget at T/2, & 1/2 at T.*/
|
||||
|
||||
//bnTarget = ((ct[0]-ct[W])/W/K) * (K*(nTime-ts[0])*(ts[0]-ts[W]))/W/T/T;
|
||||
bnTarget = ct[0];
|
||||
for (k=1; k<W; k++)
|
||||
bnTarget += ct[k];
|
||||
bnTarget /= arith_uint256(W * K);
|
||||
altK = (K * (nTime-ts[0]) * (ts[0]-ts[W])) / (W * T * T);
|
||||
fprintf(stderr,"ht.%d made it to i == 0, j.%d ii.%d altK %lld (%d * %d) %u - %u W.%d\n",height,j,ii,(long long)altK,(nTime-ts[0]),(ts[0]-ts[W]),ts[0],ts[W],W);
|
||||
bnTarget *= arith_uint256(altK);
|
||||
j = 0; // It needed adjusting, we adjusted it, we're finished, so break out of j loop.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return(bnTarget);
|
||||
}
|
||||
#endif
|
||||
|
||||
arith_uint256 RT_CST_RST_outer(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past)
|
||||
{
|
||||
int64_t outerK; int32_t cmpval; arith_uint256 mintarget = bnTarget / arith_uint256(2);
|
||||
cmpval = (T * numerator)/denominator;
|
||||
if ( cmpval < 2 )
|
||||
cmpval = 2;
|
||||
if ( (ts[0] - ts[W]) < cmpval )
|
||||
{
|
||||
outerK = (K * (nTime-ts[0]) * (ts[0]-ts[W]) * denominator) / (numerator * (T * T));
|
||||
if ( outerK < K )
|
||||
{
|
||||
bnTarget = ct[0] / arith_uint256(K);
|
||||
bnTarget *= arith_uint256(outerK);
|
||||
}
|
||||
if ( bnTarget > mintarget )
|
||||
bnTarget = mintarget;
|
||||
{
|
||||
int32_t z;
|
||||
for (z=31; z>=0; z--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]);
|
||||
}
|
||||
fprintf(stderr," ht.%d initial W.%d outerK.%lld %d * %d * %d / %d\n",height,W,(long long)outerK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator);
|
||||
} //else fprintf(stderr,"ht.%d no outer trigger %d >= %d\n",height,(ts[0] - ts[W]),(T * numerator)/denominator);
|
||||
return(bnTarget);
|
||||
}
|
||||
|
||||
arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t width)
|
||||
{
|
||||
int32_t i; int64_t innerK;
|
||||
bnTarget = ct[0];
|
||||
for (i=1; i<width; i++)
|
||||
bnTarget += ct[i];
|
||||
bnTarget /= arith_uint256(width * K);
|
||||
innerK = (K * (nTime-ts[0]) * (ts[0]-ts[width])) / (width * T * T);
|
||||
bnTarget *= arith_uint256(innerK);
|
||||
if ( 0 )
|
||||
{
|
||||
int32_t z;
|
||||
for (z=31; z>=0; z--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]);
|
||||
fprintf(stderr," ht.%d innerK %lld (%d * %d) %u - %u width.%d\n",height,(long long)innerK,(nTime-ts[0]),(ts[0]-ts[width]),ts[0],ts[width],width);
|
||||
}
|
||||
return(bnTarget);
|
||||
}
|
||||
|
||||
arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t W,int32_t outeri)
|
||||
{
|
||||
int32_t expected,elapsed,width = outeri+W; arith_uint256 mintarget,origtarget;
|
||||
expected = (width+1) * T;
|
||||
origtarget = bnTarget;
|
||||
if ( (elapsed= (ts[0] - ts[width])) < expected )
|
||||
{
|
||||
mintarget = (bnTarget / arith_uint256(101)) * arith_uint256(100);
|
||||
bnTarget = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,W);
|
||||
if ( bnTarget == origtarget ) // force zawyflag to 1
|
||||
bnTarget = mintarget;
|
||||
{
|
||||
int32_t z;
|
||||
for (z=31; z>=0; z--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]);
|
||||
}
|
||||
fprintf(stderr," height.%d O.%-2d, W.%-2d width.%-2d %4d vs %-4d, deficit %4d tip.%d\n",height,outeri,W,width,(ts[0] - ts[width]),expected,expected - (ts[0] - ts[width]),nTime-ts[0]);
|
||||
}
|
||||
return(bnTarget);
|
||||
}
|
||||
|
||||
arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnSum,int32_t num,int32_t numerator,int32_t divisor)
|
||||
{
|
||||
bnSum /= arith_uint256(ASSETCHAINS_BLOCKTIME * num * num * divisor);
|
||||
@@ -51,21 +240,58 @@ arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnSum,int32_t num,i
|
||||
return(bnSum);
|
||||
}
|
||||
|
||||
arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult)
|
||||
int64_t zawy_exponential_val360000(int32_t num)
|
||||
{
|
||||
int32_t i,n,modval; int64_t A = 1, B = 3600 * 100;
|
||||
if ( (n= (mult/ASSETCHAINS_BLOCKTIME)) > 0 )
|
||||
if ( (n= (num/ASSETCHAINS_BLOCKTIME)) > 0 )
|
||||
{
|
||||
for (i=1; i<=n; i++)
|
||||
A *= 3;
|
||||
}
|
||||
if ( (modval= (mult % ASSETCHAINS_BLOCKTIME)) != 0 )
|
||||
if ( (modval= (num % ASSETCHAINS_BLOCKTIME)) != 0 )
|
||||
{
|
||||
B += (3600 * 110 * modval) / ASSETCHAINS_BLOCKTIME;
|
||||
B += (3600 * 60 * modval * modval) / (ASSETCHAINS_BLOCKTIME * ASSETCHAINS_BLOCKTIME);
|
||||
}
|
||||
return(A * B);
|
||||
}
|
||||
|
||||
arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult)
|
||||
{
|
||||
bnTarget /= arith_uint256(100 * 3600);
|
||||
bnTarget *= arith_uint256(A * B);
|
||||
bnTarget *= arith_uint256(zawy_exponential_val360000(mult));
|
||||
return(bnTarget);
|
||||
}
|
||||
|
||||
arith_uint256 zawy_ctB(arith_uint256 bnTarget,uint32_t solvetime)
|
||||
{
|
||||
int64_t num;
|
||||
num = ((int64_t)1000 * solvetime * solvetime * 1000) / (T * T * 784);
|
||||
if ( num > 1 )
|
||||
{
|
||||
bnTarget /= arith_uint256(1000);
|
||||
bnTarget *= arith_uint256(num);
|
||||
}
|
||||
return(bnTarget);
|
||||
}
|
||||
|
||||
arith_uint256 zawy_TSA_EMA(int32_t height,int32_t tipdiff,arith_uint256 prevTarget,int32_t solvetime)
|
||||
{
|
||||
arith_uint256 A,B,C,bnTarget;
|
||||
if ( tipdiff < 4 )
|
||||
tipdiff = 4;
|
||||
tipdiff &= ~1;
|
||||
bnTarget = prevTarget / arith_uint256(K*T);
|
||||
A = bnTarget * arith_uint256(T);
|
||||
B = (bnTarget / arith_uint256(360000)) * arith_uint256(tipdiff * zawy_exponential_val360000(tipdiff/2));
|
||||
C = (bnTarget / arith_uint256(360000)) * arith_uint256(T * zawy_exponential_val360000(tipdiff/2));
|
||||
bnTarget = ((A + B - C) / arith_uint256(tipdiff)) * arith_uint256(K*T);
|
||||
{
|
||||
int32_t z;
|
||||
for (z=31; z>=0; z--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]);
|
||||
}
|
||||
fprintf(stderr," ht.%d TSA bnTarget tipdiff.%d\n",height,tipdiff);
|
||||
return(bnTarget);
|
||||
}
|
||||
|
||||
@@ -100,40 +326,50 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
||||
|
||||
// Find the first block in the averaging interval
|
||||
const CBlockIndex* pindexFirst = pindexLast;
|
||||
arith_uint256 bnTmp,bnTarget,bnPrev {0},bnSum4 {0},bnSum7 {0},bnSum12 {0},bnTot {0};
|
||||
uint32_t nbits,blocktime,block4diff=0,block7diff=0,block12diff=0; int32_t diff,mult = 0;
|
||||
if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 )
|
||||
arith_uint256 ct[64],ctinv[64],bnTmp,bnPrev,bnTarget,bnTarget2,bnTarget3,bnTarget6,bnTarget12,bnTot {0};
|
||||
uint32_t nbits,blocktime,ts[sizeof(ct)/sizeof(*ct)]; int32_t zflags[sizeof(ct)/sizeof(*ct)],i,diff,height=0,mult = 0,tipdiff = 0;
|
||||
memset(ts,0,sizeof(ts));
|
||||
memset(ct,0,sizeof(ct));
|
||||
memset(ctinv,0,sizeof(ctinv));
|
||||
memset(zflags,0,sizeof(zflags));
|
||||
if ( pindexLast != 0 )
|
||||
height = (int32_t)pindexLast->GetHeight() + 1;
|
||||
if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 && height >= (int32_t)(sizeof(ct)/sizeof(*ct)) )
|
||||
{
|
||||
mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME;
|
||||
tipdiff = (pblock->nTime - pindexFirst->nTime);
|
||||
mult = tipdiff - 7 * ASSETCHAINS_BLOCKTIME;
|
||||
bnPrev.SetCompact(pindexFirst->nBits);
|
||||
//fprintf(stderr,"ht.%d mult.%d = (%u - %u - 7x)\n",pindexLast->GetHeight(),(int32_t)mult,pblock->nTime, pindexFirst->nTime);
|
||||
for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++)
|
||||
{
|
||||
zflags[i] = (pindexFirst->nBits & 3);
|
||||
ct[i].SetCompact(pindexFirst->nBits);
|
||||
ts[i] = pindexFirst->nTime;
|
||||
pindexFirst = pindexFirst->pprev;
|
||||
}
|
||||
for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct))-1; i++)
|
||||
{
|
||||
if ( zflags[i] == 1 || zflags[i] == 2 ) // I, O and if TSA made it harder
|
||||
ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]);
|
||||
}
|
||||
if ( ASSETCHAINS_ADAPTIVEPOW == 2 ) // TSA
|
||||
{
|
||||
bnTarget = zawy_TSA_EMA(height,tipdiff,ct[0],ts[0] - ts[1]);
|
||||
nbits = bnTarget.GetCompact();
|
||||
nbits = (nbits & 0xfffffffc) | 0;
|
||||
return(nbits);
|
||||
}
|
||||
}
|
||||
for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++)
|
||||
pindexFirst = pindexLast;
|
||||
for (i = 0; pindexFirst && i < params.nPowAveragingWindow; i++)
|
||||
{
|
||||
bnTmp.SetCompact(pindexFirst->nBits);
|
||||
bnTot += bnTmp;
|
||||
if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pblock != 0 )
|
||||
{
|
||||
blocktime = pindexFirst->nTime;
|
||||
diff = (pblock->nTime - blocktime);
|
||||
//fprintf(stderr,"%d ",diff);
|
||||
if ( i < 12 )
|
||||
if ( i < 6 )
|
||||
{
|
||||
if ( i == 3 )
|
||||
{
|
||||
block4diff = diff;
|
||||
bnSum4 = bnTot;
|
||||
}
|
||||
else if ( i == 6 )
|
||||
{
|
||||
block7diff = diff;
|
||||
bnSum7 = bnTot;
|
||||
}
|
||||
else if ( i == 11 )
|
||||
{
|
||||
block12diff = diff;
|
||||
bnSum12 = bnTot;
|
||||
}
|
||||
diff -= (8+i)*ASSETCHAINS_BLOCKTIME;
|
||||
if ( diff > mult )
|
||||
{
|
||||
@@ -141,63 +377,127 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
||||
mult = diff;
|
||||
}
|
||||
}
|
||||
if ( zflags[i] != 0 && zflags[0] == 0 ) // an RST block, but the most recent has no RST
|
||||
bnTmp = (bnTmp / arith_uint256(8)) * arith_uint256(7);
|
||||
}
|
||||
bnTot += bnTmp;
|
||||
pindexFirst = pindexFirst->pprev;
|
||||
}
|
||||
//fprintf(stderr,"diffs %d\n",(int32_t) pindexLast->GetHeight());
|
||||
//fprintf(stderr,"diffs %d\n",height);
|
||||
// Check we have enough blocks
|
||||
if (pindexFirst == NULL)
|
||||
return nProofOfWorkLimit;
|
||||
|
||||
bool fNegative,fOverflow; int32_t flag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow};
|
||||
bool fNegative,fOverflow; int32_t zawyflag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow};
|
||||
nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
|
||||
if ( ASSETCHAINS_ADAPTIVEPOW > 0 && block12diff != 0 && block7diff != 0 && block4diff != 0 )
|
||||
if ( ASSETCHAINS_ADAPTIVEPOW > 0 )
|
||||
{
|
||||
origtarget = bnTarget = arith_uint256().SetCompact(nbits);
|
||||
easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||
bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1);
|
||||
bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1);
|
||||
bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2,1);
|
||||
if ( bnSum4 < bnSum7 )
|
||||
bnTmp = bnSum4;
|
||||
else bnTmp = bnSum7;
|
||||
if ( bnSum12 < bnTmp )
|
||||
bnTmp = bnSum12;
|
||||
if ( bnTmp < bnTarget )
|
||||
bnTarget = arith_uint256().SetCompact(nbits);
|
||||
if ( height > (int32_t)(sizeof(ct)/sizeof(*ct)) && pblock != 0 && tipdiff > 0 )
|
||||
{
|
||||
fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11);
|
||||
bnTarget = (bnTmp + bnPrev) / arith_uint256(2);
|
||||
flag = 1;
|
||||
}
|
||||
else if ( flag == 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t???
|
||||
{
|
||||
flag = 1;
|
||||
bnTarget = zawy_exponential(bnTarget,mult);
|
||||
if ( bnTarget < origtarget || bnTarget > easy )
|
||||
easy.SetCompact(KOMODO_MINDIFF_NBITS & (~3),&fNegative,&fOverflow);
|
||||
if ( pblock != 0 )
|
||||
{
|
||||
bnTarget = easy;
|
||||
fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight());
|
||||
return(KOMODO_MINDIFF_NBITS);
|
||||
} else fprintf(stderr,"cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight());
|
||||
}
|
||||
if ( flag == 0 )
|
||||
{
|
||||
bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 3,10);
|
||||
bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 5,10);
|
||||
bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 6,10);
|
||||
if ( bnSum4 > bnSum7 )
|
||||
bnTmp = bnSum4;
|
||||
else bnTmp = bnSum7;
|
||||
if ( bnSum12 > bnTmp )
|
||||
bnTmp = bnSum12;
|
||||
if ( bnTmp > bnTarget )
|
||||
origtarget = bnTarget;
|
||||
if ( zflags[0] == 0 || zflags[0] == 3 )
|
||||
{
|
||||
// 15 51 102 162 230 303 380 460 543 627 714 803 892 983 1075 These are the 0.5% per blk numerator constants for W=2 to 16 if denominator is 100. - zawy
|
||||
if ( ASSETCHAINS_BLOCKTIME >= 60 && ASSETCHAINS_BLOCKTIME < 100 )
|
||||
bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,60,1,10);
|
||||
else if ( ASSETCHAINS_BLOCKTIME >= 100 )
|
||||
bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,100,1,10);
|
||||
if ( bnTarget < origtarget )
|
||||
zawyflag = 2;
|
||||
else
|
||||
{
|
||||
bnTarget = RT_CST_RST_outer(height,pblock->nTime,origtarget,ts,ct,15,100,2,20);
|
||||
if ( bnTarget < origtarget )
|
||||
zawyflag = 2;
|
||||
else
|
||||
{
|
||||
bnTarget = RT_CST_RST_outer(height,pblock->nTime,origtarget,ts,ct,1,2,3,30);
|
||||
if ( bnTarget < origtarget )
|
||||
zawyflag = 2;
|
||||
else
|
||||
{
|
||||
bnTarget = RT_CST_RST_outer(height,pblock->nTime,origtarget,ts,ct,7,3,6,40);
|
||||
if ( bnTarget < origtarget )
|
||||
zawyflag = 2;
|
||||
else
|
||||
{
|
||||
bnTarget = RT_CST_RST_outer(height,pblock->nTime,origtarget,ts,ct,12,7,12,50);
|
||||
if ( bnTarget < origtarget )
|
||||
zawyflag = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=0; i<50; i++)
|
||||
if ( zflags[i] == 2 )
|
||||
break;
|
||||
if ( i < 10 )
|
||||
{
|
||||
bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,1,i);
|
||||
if ( bnTarget > origtarget )
|
||||
bnTarget = origtarget;
|
||||
}
|
||||
if ( i < 20 )
|
||||
{
|
||||
bnTarget2 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,2,i);
|
||||
if ( bnTarget2 < bnTarget )
|
||||
bnTarget = bnTarget2;
|
||||
}
|
||||
if ( i < 30 )
|
||||
{
|
||||
bnTarget3 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,3,i);
|
||||
if ( bnTarget3 < bnTarget )
|
||||
bnTarget = bnTarget3;
|
||||
}
|
||||
if ( i < 40 )
|
||||
{
|
||||
bnTarget6 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,6,i);
|
||||
if ( bnTarget6 < bnTarget )
|
||||
bnTarget = bnTarget6;
|
||||
}
|
||||
if ( i < 50 )
|
||||
{
|
||||
bnTarget12 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,12,i);
|
||||
if ( bnTarget12 < bnTarget)
|
||||
bnTarget = bnTarget12;
|
||||
}
|
||||
if ( bnTarget != origtarget )
|
||||
zawyflag = 1;
|
||||
}
|
||||
}
|
||||
if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t???
|
||||
{
|
||||
fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13);
|
||||
bnTarget = (bnTmp + bnPrev) / arith_uint256(2);
|
||||
flag = 1;
|
||||
origtarget = bnTarget;
|
||||
bnTarget = zawy_exponential(bnTarget,mult);
|
||||
if ( bnTarget < origtarget || bnTarget > easy )
|
||||
{
|
||||
bnTarget = easy;
|
||||
fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,height);
|
||||
return(KOMODO_MINDIFF_NBITS & (~3));
|
||||
}
|
||||
{
|
||||
int32_t z;
|
||||
for (z=31; z>=0; z--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]);
|
||||
}
|
||||
fprintf(stderr," exp() to the rescue cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height);
|
||||
}
|
||||
if ( 0 && zflags[0] == 0 && zawyflag == 0 && mult <= 1 )
|
||||
{
|
||||
bnTarget = zawy_TSA_EMA(height,tipdiff,(bnTarget+ct[0]+ct[1])/arith_uint256(3),ts[0] - ts[1]);
|
||||
if ( bnTarget < origtarget )
|
||||
zawyflag = 3;
|
||||
}
|
||||
}
|
||||
nbits = bnTarget.GetCompact();
|
||||
nbits = (nbits & 0xfffffffc) | zawyflag;
|
||||
}
|
||||
return(nbits);
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ bool NSPV_inmempool(uint256 txid);
|
||||
bool myIsutxo_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,int32_t vout)
|
||||
{
|
||||
int32_t vini = 0;
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
return(NSPV_spentinmempool(spenttxid,spentvini,txid,vout));
|
||||
BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx)
|
||||
{
|
||||
@@ -420,7 +420,7 @@ bool myIsutxo_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,
|
||||
|
||||
bool mytxid_inmempool(uint256 txid)
|
||||
{
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -403,7 +403,52 @@ UniValue setgenerate(const UniValue& params, bool fHelp)
|
||||
}
|
||||
#endif
|
||||
|
||||
CBlockIndex *komodo_chainactive(int32_t height);
|
||||
arith_uint256 zawy_ctB(arith_uint256 bnTarget,uint32_t solvetime);
|
||||
|
||||
UniValue genminingCSV(const UniValue& params, bool fHelp)
|
||||
{
|
||||
int32_t i,z,height; uint32_t solvetime,prevtime=0; FILE *fp; char str[65],str2[65],fname[256]; uint256 hash; arith_uint256 bnTarget; CBlockIndex *pindex; bool fNegative,fOverflow; UniValue result(UniValue::VOBJ);
|
||||
if (fHelp || params.size() != 0 )
|
||||
throw runtime_error("genminingCSV\n");
|
||||
LOCK(cs_main);
|
||||
sprintf(fname,"%s_mining.csv",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL);
|
||||
if ( (fp= fopen(fname,"wb")) != 0 )
|
||||
{
|
||||
fprintf(fp,"height,nTime,nBits,bnTarget,bnTargetB,diff,solvetime\n");
|
||||
height = komodo_nextheight();
|
||||
for (i=0; i<height; i++)
|
||||
{
|
||||
if ( (pindex= komodo_chainactive(i)) != 0 )
|
||||
{
|
||||
bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow);
|
||||
solvetime = (prevtime==0) ? 0 : (int32_t)(pindex->nTime - prevtime);
|
||||
for (z=0; z<16; z++)
|
||||
sprintf(&str[z<<1],"%02x",((uint8_t *)&bnTarget)[31-z]);
|
||||
str[32] = 0;
|
||||
//hash = pindex->GetBlockHash();
|
||||
memset(&hash,0,sizeof(hash));
|
||||
if ( i >= 64 && (pindex->nBits & 3) != 0 )
|
||||
hash = ArithToUint256(zawy_ctB(bnTarget,solvetime));
|
||||
for (z=0; z<16; z++)
|
||||
sprintf(&str2[z<<1],"%02x",((uint8_t *)&hash)[31-z]);
|
||||
str2[32] = 0; fprintf(fp,"%d,%u,%08x,%s,%s,%.1f,%d\n",i,pindex->nTime,pindex->nBits,str,str2,GetDifficulty(pindex),solvetime);
|
||||
prevtime = pindex->nTime;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("created", fname));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("error", "couldnt create mining.csv"));
|
||||
result.push_back(Pair("filename", fname));
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue getmininginfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
|
||||
@@ -243,7 +243,7 @@ UniValue getinfo(const UniValue& params, bool fHelp)
|
||||
obj.push_back(Pair("prevMoMheight", prevMoMheight));
|
||||
obj.push_back(Pair("notarizedhash", notarized_hash.ToString()));
|
||||
obj.push_back(Pair("notarizedtxid", notarized_desttxid.ToString()));
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
{
|
||||
txid_height = notarizedtxid_height(ASSETCHAINS_SYMBOL[0] != 0 ? (char *)"KMD" : (char *)"BTC",(char *)notarized_desttxid.ToString().c_str(),&kmdnotarized_height);
|
||||
if ( txid_height > 0 )
|
||||
|
||||
@@ -374,7 +374,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
|
||||
const CTxOut& txout = tx.vout[i];
|
||||
UniValue out(UniValue::VOBJ);
|
||||
out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
|
||||
if ( KOMODO_NSPV <= 0 && ASSETCHAINS_SYMBOL[0] == 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE && ASSETCHAINS_SYMBOL[0] == 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 )
|
||||
{
|
||||
int64_t interest; int32_t txheight; uint32_t locktime;
|
||||
interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->GetHeight());
|
||||
@@ -1366,7 +1366,7 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp)
|
||||
bool fOverrideFees = false;
|
||||
if (params.size() > 1)
|
||||
fOverrideFees = params[1].get_bool();
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
{
|
||||
CCoinsViewCache &view = *pcoinsTip;
|
||||
const CCoins* existingCoins = view.AccessCoins(hashTx);
|
||||
|
||||
@@ -384,6 +384,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "mining", "prioritisetransaction", &prioritisetransaction, true },
|
||||
{ "mining", "submitblock", &submitblock, true },
|
||||
{ "mining", "getblocksubsidy", &getblocksubsidy, true },
|
||||
{ "mining", "genminingCSV", &genminingCSV, true },
|
||||
|
||||
#ifdef ENABLE_MINING
|
||||
/* Coin generation */
|
||||
|
||||
@@ -463,6 +463,7 @@ extern UniValue importgatewaycompletesigning(const UniValue& params, bool fHelp)
|
||||
extern UniValue importgatewaymarkdone(const UniValue& params, bool fHelp);
|
||||
extern UniValue importgatewaypendingwithdraws(const UniValue& params, bool fHelp);
|
||||
extern UniValue importgatewayprocessed(const UniValue& params, bool fHelp);
|
||||
extern UniValue genminingCSV(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue nspv_getinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue nspv_login(const UniValue& params, bool fHelp);
|
||||
|
||||
@@ -37,6 +37,13 @@ typedef vector<unsigned char> valtype;
|
||||
extern uint8_t ASSETCHAINS_TXPOW;
|
||||
extern char NSPV_wifstr[],NSPV_pubkeystr[];
|
||||
extern int32_t KOMODO_NSPV;
|
||||
#ifndef KOMODO_NSPV_FULLNODE
|
||||
#define KOMODO_NSPV_FULLNODE (KOMODO_NSPV <= 0)
|
||||
#endif // !KOMODO_NSPV_FULLNODE
|
||||
#ifndef KOMODO_NSPV_SUPERLITE
|
||||
#define KOMODO_NSPV_SUPERLITE (KOMODO_NSPV > 0)
|
||||
#endif // !KOMODO_NSPV_SUPERLITE
|
||||
|
||||
uint256 SIG_TXHASH;
|
||||
|
||||
TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {}
|
||||
@@ -53,7 +60,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
|
||||
}
|
||||
}
|
||||
SIG_TXHASH = hash;
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
key = DecodeSecret(NSPV_wifstr);
|
||||
else if (pprivKey)
|
||||
key = *pprivKey;
|
||||
@@ -74,7 +81,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
|
||||
return false;
|
||||
}
|
||||
vchSig = CCSigVec(cc);
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
memset((uint8_t *)key.begin(),0,32);
|
||||
return true;
|
||||
}
|
||||
@@ -100,7 +107,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
|
||||
}
|
||||
|
||||
vchSig.push_back((unsigned char)nHashType);
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
memset((uint8_t *)key.begin(),0,32);
|
||||
return true;
|
||||
}
|
||||
@@ -381,7 +388,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
{
|
||||
CPubKey vch;
|
||||
creator.KeyStore().GetPubKey(keyID, vch);
|
||||
|
||||
@@ -973,10 +973,17 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp)
|
||||
}
|
||||
|
||||
extern int32_t KOMODO_NSPV;
|
||||
#ifndef KOMODO_NSPV_FULLNODE
|
||||
#define KOMODO_NSPV_FULLNODE (KOMODO_NSPV <= 0)
|
||||
#endif // !KOMODO_NSPV_FULLNODE
|
||||
#ifndef KOMODO_NSPV_SUPERLITE
|
||||
#define KOMODO_NSPV_SUPERLITE (KOMODO_NSPV > 0)
|
||||
#endif // !KOMODO_NSPV_SUPERLITE
|
||||
uint256 zeroid;
|
||||
UniValue NSPV_getinfo_req(int32_t reqht);
|
||||
UniValue NSPV_login(char *wifstr);
|
||||
UniValue NSPV_logout();
|
||||
UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter);
|
||||
UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter, uint256 filtertxid);
|
||||
UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter);
|
||||
UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 txid,int32_t vout);
|
||||
UniValue NSPV_broadcast(char *hex);
|
||||
@@ -993,7 +1000,7 @@ 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 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
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());
|
||||
@@ -1004,7 +1011,7 @@ UniValue nspv_logout(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if ( fHelp || params.size() != 0 )
|
||||
throw runtime_error("nspv_logout\n");
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
throw runtime_error("-nSPV=1 must be set to use nspv\n");
|
||||
return(NSPV_logout());
|
||||
}
|
||||
@@ -1013,7 +1020,7 @@ UniValue nspv_login(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if ( fHelp || params.size() != 1 )
|
||||
throw runtime_error("nspv_login wif\n");
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
throw runtime_error("-nSPV=1 must be set to use nspv\n");
|
||||
return(NSPV_login((char *)params[0].get_str().c_str()));
|
||||
}
|
||||
@@ -1023,7 +1030,7 @@ 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 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
throw runtime_error("-nSPV=1 must be set to use nspv\n");
|
||||
if ( params.size() == 0 )
|
||||
{
|
||||
@@ -1048,7 +1055,7 @@ 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 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
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();
|
||||
@@ -1068,12 +1075,12 @@ 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 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
throw runtime_error("-nSPV=1 must be set to use nspv\n");
|
||||
if ( params.size() == 0 )
|
||||
{
|
||||
if ( NSPV_address.size() != 0 )
|
||||
return(NSPV_addresstxids((char *)NSPV_address.c_str(),0,0,0));
|
||||
return(NSPV_addresstxids((char *)NSPV_address.c_str(),0,0,0,zeroid));
|
||||
else throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n");
|
||||
}
|
||||
if ( params.size() >= 1 )
|
||||
@@ -1083,7 +1090,7 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp)
|
||||
if ( params.size() == 3 )
|
||||
skipcount = atoi((char *)params[2].get_str().c_str());
|
||||
//fprintf(stderr,"call txids cc.%d skip.%d\n",CCflag,skipcount);
|
||||
return(NSPV_addresstxids((char *)params[0].get_str().c_str(),CCflag,skipcount,0));
|
||||
return(NSPV_addresstxids((char *)params[0].get_str().c_str(),CCflag,skipcount,0,zeroid));
|
||||
}
|
||||
else throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n");
|
||||
}
|
||||
@@ -1093,7 +1100,7 @@ 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 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
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());
|
||||
@@ -1105,7 +1112,7 @@ 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 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
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));
|
||||
@@ -1116,7 +1123,7 @@ 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 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
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());
|
||||
@@ -1128,7 +1135,7 @@ 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 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
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());
|
||||
@@ -1140,7 +1147,7 @@ UniValue nspv_spend(const UniValue& params, bool fHelp)
|
||||
uint64_t satoshis;
|
||||
if ( fHelp || params.size() != 2 )
|
||||
throw runtime_error("nspv_spend address amount\n");
|
||||
if ( KOMODO_NSPV <= 0 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
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");
|
||||
@@ -1155,7 +1162,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 )
|
||||
if ( KOMODO_NSPV_FULLNODE )
|
||||
throw runtime_error("-nSPV=1 must be set to use nspv\n");
|
||||
return(NSPV_broadcast((char *)params[0].get_str().c_str()));
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ void OS_randombytes(unsigned char *x,long xlen);
|
||||
|
||||
UniValue getnewaddress(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if ( KOMODO_NSPV <= 0 && !EnsureWalletIsAvailable(fHelp) )
|
||||
if ( KOMODO_NSPV_FULLNODE && !EnsureWalletIsAvailable(fHelp) )
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() > 1)
|
||||
@@ -178,7 +178,7 @@ UniValue getnewaddress(const UniValue& params, bool fHelp)
|
||||
+ HelpExampleRpc("getnewaddress", "")
|
||||
);
|
||||
|
||||
if ( KOMODO_NSPV > 0 )
|
||||
if ( KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint8_t priv32[32];
|
||||
#ifndef __WIN32
|
||||
@@ -2974,7 +2974,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
||||
uint64_t komodo_interestsum()
|
||||
{
|
||||
#ifdef ENABLE_WALLET
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 && KOMODO_NSPV <= 0 )
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 && KOMODO_NSPV_FULLNODE )
|
||||
{
|
||||
uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime;
|
||||
vector<COutput> vecOutputs;
|
||||
@@ -7002,7 +7002,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp)
|
||||
if ( fHelp || params.size() > 1 )
|
||||
throw runtime_error("faucetfund amount\n");
|
||||
funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999;
|
||||
if ( (0) && KOMODO_NSPV > 0 )
|
||||
if ( (0) && KOMODO_NSPV_SUPERLITE )
|
||||
{
|
||||
char coinaddr[64]; struct CCcontract_info *cp,C; CTxOut v;
|
||||
cp = CCinit(&C,EVAL_FAUCET);
|
||||
@@ -8300,32 +8300,57 @@ void RegisterWalletRPCCommands(CRPCTable &tableRPC)
|
||||
|
||||
UniValue opreturn_burn(const UniValue& params, bool fHelp)
|
||||
{
|
||||
std::vector<uint8_t> vHexStr; CScript opret; int32_t txfee = 10000;
|
||||
if (fHelp || (params.size() != 2))
|
||||
throw runtime_error("amount to burn, hexstring to send\n");
|
||||
struct CCcontract_info *cp, C; UniValue ret(UniValue::VOBJ);
|
||||
if (ensure_CCrequirements(EVAL_ORACLES) < 0)
|
||||
throw runtime_error(CC_REQUIREMENTS_MSG);
|
||||
cp = CCinit(&C, EVAL_ORACLES);
|
||||
|
||||
std::vector<uint8_t> vHexStr; CScript opret; int32_t txfee = 10000;CPubKey myPubkey;
|
||||
if (fHelp || (params.size() < 2) || (params.size() > 4) )
|
||||
{
|
||||
throw runtime_error(
|
||||
"opreturn_burn burn_amount hexstring ( txfee )\n"
|
||||
"\nBurn the specified amount of coins via OP_RETURN. Returns unsigned transaction raw hex that must then be signed via signrawtransaction and broadcast via sendrawtransaction rpc\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"burn_amount\" (numeric, required) Amount of coins to burn.\n"
|
||||
"2. \"hexstring\" (string, required) Hex string to include in OP_RETURN data.\n"
|
||||
"3. \"txfee\" (numeric, optional, default=0.0001) Transaction fee.\n"
|
||||
"\nResult:\n"
|
||||
" {\n"
|
||||
" \"hex\" : \"hexstring\", (string) raw hex of transaction \n"
|
||||
" }\n"
|
||||
"\nExamples:\n"
|
||||
"\nBurn 10 coins with OP_RETURN data \"deadbeef\"\n"
|
||||
+ HelpExampleCli("opreturn_burn", "\"10\" \"deadbeef\"")
|
||||
+ HelpExampleRpc("opreturn_burn", "\"10\", \"deadbeef\"") +
|
||||
"\nBurn 10 coins with OP_RETURN data \"deadbeef\" with 0.00005 txfee\n"
|
||||
+ HelpExampleCli("opreturn_burn", "\"10\" \"deadbeef\" \"0.00005\"")
|
||||
+ HelpExampleRpc("opreturn_burn", "\"10\", \"deadbeef\", 0.00005")
|
||||
);
|
||||
}
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
|
||||
CAmount nAmount = AmountFromValue(params[0]);
|
||||
if (nAmount <= 10000)
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "must burn at least 10000 sat");
|
||||
vHexStr = ParseHex(params[1].get_str());
|
||||
if ( vHexStr.size() == 0 )
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "hexstring is not valid.");
|
||||
|
||||
CPubKey myPubkey = pubkey2pk(Mypubkey());
|
||||
if ( params.size() > 2 )
|
||||
txfee = AmountFromValue(params[2]);
|
||||
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "wallet is locked or unavailable.");
|
||||
EnsureWalletIsUnlocked();
|
||||
CReserveKey reservekey(pwalletMain);
|
||||
if (!reservekey.GetReservedKey(myPubkey))
|
||||
{
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "keypool error.");
|
||||
}
|
||||
|
||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
||||
|
||||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, nAmount, 60);
|
||||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, nAmount+txfee, 60);
|
||||
if (normalInputs < nAmount)
|
||||
throw runtime_error("not enough normals\n");
|
||||
throw runtime_error("insufficient funds\n");
|
||||
|
||||
opret << OP_RETURN << E_MARSHAL(ss << vHexStr);
|
||||
|
||||
mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG));
|
||||
mtx.vout.push_back(CTxOut(nAmount,opret));
|
||||
ret.push_back(Pair("hex",FinalizeCCTx(0, cp, mtx, myPubkey, txfee, CScript())));
|
||||
ret.push_back(Pair("hex", EncodeHexTx(mtx)));
|
||||
return(ret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user