Merge pull request #62 from jl777/FSM

Fsm
This commit is contained in:
blackjok3rtt
2018-12-16 22:07:46 +08:00
committed by GitHub
7 changed files with 78 additions and 28 deletions

View File

@@ -39,7 +39,7 @@ echo $pubkey
~/VerusCoin/src/komodod -pubkey=$pubkey -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 &
./komodod -pubkey=$pubkey -ac_name=SEC -ac_cc=333 -ac_supply=1000000000 -addnode=185.148.145.43 &
./komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 &
./komodod -pubkey=$pubkey -ac_name=PIRATE -ac_supply=0 -ac_reward=25600000000 -ac_halving=77777 -ac_private=1 -addnode=136.243.102.225 &
./komodod -pubkey=$pubkey -ac_name=PIRATE -ac_supply=0 -ac_reward=25600000000 -ac_halving=77777 -ac_private=1 -addnode=178.63.77.56 &
./komodod -pubkey=$pubkey -ac_name=MGNX -ac_supply=12465003 -ac_staked=90 -ac_reward=2000000000 -ac_halving=525960 -ac_cc=2 -ac_end=2629800 -addnode=142.93.27.180 &
./komodod -pubkey=$pubkey -ac_name=PGT -ac_supply=10000000 -ac_end=1 -addnode=190.114.254.104 &
./komodod -pubkey=$pubkey -ac_name=KMDICE -ac_supply=10500000 -ac_reward=2500000000 -ac_halving=210000 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=144.76.217.232 &

View File

@@ -110,7 +110,7 @@ int32_t komodo_nextheight();
static const uint256 zeroid;
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock);
int32_t is_hexstr(char *str,int32_t n);
bool myAddtomempool(CTransaction &tx, CValidationState *pstate = NULL);
bool myAddtomempool(CTransaction &tx, CValidationState *pstate = NULL, bool fSkipExpiry = false);
//uint64_t myGettxout(uint256 hash,int32_t n);
bool myIsutxo_spentinmempool(uint256 txid,int32_t vout);
bool mytxid_inmempool(uint256 txid);

11
src/cc/dapps/Makefile Normal file
View File

@@ -0,0 +1,11 @@
# just type make to compile all dapps
all: zmigrate oraclefeed
zmigrate:
$(CC) zmigrate.c -o zmigrate -lm
oraclefeed:
$(CC) oraclefeed.c -o oraclefeed -lm
clean:
rm zmigrate oraclefeed

28
src/cc/dapps/README.md Normal file
View File

@@ -0,0 +1,28 @@
# CryptoCondition dApps
## Compiling
To compile all dapps in this directory:
make
## zmigrate - Sprout to Sapling Migration dApp
This tool converts Sprout zaddress funds into Sapling funds in a new Sapling address.
### Usage
./zmigrate zsaplingaddr
The above command may need to be run multiple times to complete the process.
This CLI implementation will be called by GUI wallets, average users do not
need to worry about using this low-level tool.
## oraclefeed - feed of price data using oracles
### Usage
./oraclefeed $ACNAME $ORACLETXID $MYPUBKEY $FORMAT $BINDTXID [refcoin_cli]
Supported formats are L and Ihh. Price data from CoinDesk API.

View File

@@ -670,6 +670,7 @@ int64_t find_onetime_amount(char *coinstr,char *coinaddr)
coinaddr[0] = 0;
if ( (array= get_listunspent(coinstr,"")) != 0 )
{
//printf("got listunspent.(%s)\n",jprint(array,0));
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
@@ -734,6 +735,7 @@ int32_t z_sendmany(char *opidstr,char *coinstr,char *acname,char *srcaddr,char *
cJSON *retjson; char *retstr,params[1024],addr[128];
sprintf(params,"'[{\"address\":\"%s\",\"amount\":%.8f}]'",destaddr,dstr(amount));
sprintf(addr,"\"%s\"",srcaddr);
printf("z_sendmany from.(%s) -> %s\n",srcaddr,params);
if ( (retjson= get_komodocli(coinstr,&retstr,acname,"z_sendmany",addr,params,"","")) != 0 )
{
printf("unexpected json z_sendmany.(%s)\n",jprint(retjson,0));
@@ -906,7 +908,7 @@ int32_t main(int32_t argc,char **argv)
zsaddr = clonestr(argv[2]);
printf("%s: %s %s\n",REFCOIN_CLI,coinstr,zsaddr);
uint32_t lastopid; char coinaddr[64],zcaddr[128],opidstr[128]; int32_t finished; int64_t amount,stdamount,txfee;
stdamount = 1000 * SATOSHIDEN;
//stdamount = 500 * SATOSHIDEN;
txfee = 10000;
again:
printf("start processing zmigrate\n");
@@ -916,7 +918,7 @@ again:
{
if ( have_pending_opid(coinstr,0) != 0 )
{
sleep(60);
sleep(10);
continue;
}
if ( (amount= find_onetime_amount(coinstr,coinaddr)) > txfee )
@@ -930,14 +932,28 @@ again:
if ( (amount= find_sprout_amount(coinstr,zcaddr)) > txfee )
{
// generate taddr, send max of 10000.0001
if ( amount > stdamount+txfee )
amount = stdamount + txfee;
static int64_t lastamount,lastamount2,lastamount3,lastamount4,refamount = 5000 * SATOSHIDEN;
stdamount = refamount;
if ( amount == lastamount && amount == lastamount2 )
{
stdamount /= 10;
if ( amount == lastamount3 && amount == lastamount4 )
stdamount /= 10;
}
if ( stdamount < refamount )
refamount = stdamount;
lastamount4 = lastamount3;
lastamount3 = lastamount2;
lastamount2 = lastamount;
lastamount = amount;
if ( amount > stdamount+2*txfee )
amount = stdamount + 2*txfee;
if ( getnewaddress(coinaddr,coinstr,"") == 0 )
{
z_sendmany(opidstr,coinstr,"",zcaddr,coinaddr,amount-txfee);
lastopid = (uint32_t)time(NULL);
} else printf("couldnt getnewaddress!\n");
sleep(30);
sleep(3);
continue;
}
if ( time(NULL) > lastopid+600 )

View File

@@ -1021,10 +1021,9 @@ bool ContextualCheckTransaction(
// If Sprout rules apply, reject transactions which are intended for Overwinter and beyond
if (isSprout && tx.fOverwintered) {
return state.DoS(isInitBlockDownload() ? 0 : dosLevel,
error("ContextualCheckTransaction(): ht.%d activates.%d dosLevel.%d overwinter is not active yet",
nHeight, Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight, dosLevel),
REJECT_INVALID, "tx-overwinter-not-active");
int32_t ht = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight;
return state.DoS((ht < 0 || nHeight < ht) ? 0 : dosLevel,error("ContextualCheckTransaction(): ht.%d activates.%d dosLevel.%d overwinter is not active yet",nHeight, Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight, dosLevel),REJECT_INVALID, "tx-overwinter-not-active");
//return state.DoS(isInitBlockDownload() ? 0 : dosLevel,error("ContextualCheckTransaction(): ht.%d activates.%d dosLevel.%d overwinter is not active yet",nHeight, Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight, dosLevel),REJECT_INVALID, "tx-overwinter-not-active");
}
if (saplingActive) {
@@ -1081,8 +1080,8 @@ bool ContextualCheckTransaction(
if (overwinterActive) {
// Reject transactions intended for Sprout
if (!tx.fOverwintered) {
return state.DoS(dosLevel, error("ContextualCheckTransaction: overwinter is active"),
REJECT_INVALID, "tx-overwinter-active");
int32_t ht = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight;
return state.DoS((ht < 0 || nHeight < ht) ? 0 : dosLevel, error("ContextualCheckTransaction: overwinter is active"),REJECT_INVALID, "tx-overwinter-active");
}
// Check that all transactions are unexpired
@@ -1464,7 +1463,7 @@ bool CheckTransactionWithoutProofVerification(uint32_t tiptime,const CTransactio
{
static uint32_t counter;
if ( counter++ < 10 )
fprintf(stderr,"found taddr in private chain: z_z.%d z_t.%d t_z.%d\n",z_z,z_t,t_z);
fprintf(stderr,"found taddr in private chain: z_z.%d z_t.%d t_z.%d vinsize.%d\n",z_z,z_t,t_z,(int32_t)tx.vin.size());
if ( z_t == 0 || z_z != 0 || t_z != 0 || tx.vin.size() != 0 )
return state.DoS(100, error("CheckTransaction(): this is a private chain, only sprout -> taddr allowed until deadline"),REJECT_INVALID, "bad-txns-acprivacy-chain");
}
@@ -1631,7 +1630,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF
}
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, int dosLevel)
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, int dosLevel, bool fSkipExpiry)
{
AssertLockHeld(cs_main);
if (pfMissingInputs)
@@ -1668,7 +1667,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
}
// DoS level set to 10 to be more forgiving.
// Check transaction contextually against the set of consensus rules which apply in the next block to be mined.
if (!ContextualCheckTransaction(tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel))
if (!fSkipExpiry && !ContextualCheckTransaction(tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel))
{
return error("AcceptToMemoryPool: ContextualCheckTransaction failed");
}
@@ -1765,7 +1764,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
if (pfMissingInputs)
*pfMissingInputs = true;
//fprintf(stderr,"missing inputs\n");
//return state.DoS(0, error("AcceptToMemoryPool: tx inputs not found"),REJECT_INVALID, "bad-txns-inputs-missing");
return state.DoS(0, error("AcceptToMemoryPool: tx inputs not found"),REJECT_INVALID, "bad-txns-inputs-missing");
return(false);
}
}
@@ -2006,14 +2005,14 @@ bool GetAddressUnspent(uint160 addressHash, int type,
else return(coins.vout[n].nValue);
}*/
bool myAddtomempool(CTransaction &tx, CValidationState *pstate)
bool myAddtomempool(CTransaction &tx, CValidationState *pstate, bool fSkipExpiry)
{
CValidationState state;
if (!pstate)
pstate = &state;
CTransaction Ltx; bool fMissingInputs,fOverrideFees = false;
if ( mempool.lookup(tx.GetHash(),Ltx) == 0 )
return(AcceptToMemoryPool(mempool, *pstate, tx, false, &fMissingInputs, !fOverrideFees));
return(AcceptToMemoryPool(mempool, *pstate, tx, false, &fMissingInputs, !fOverrideFees, -1, fSkipExpiry));
else return(true);
}
@@ -3936,9 +3935,7 @@ int32_t komodo_activate_sapling(CBlockIndex *pindex)
}
if ( activation != 0 )
{
//#if KOMODO_SAPLING_ACTIVATION != 1544832000
komodo_setactivation(activation);
//#endif
fprintf(stderr,"%s sapling activation at %d\n",ASSETCHAINS_SYMBOL,activation);
ASSETCHAINS_SAPLING = activation;
}
@@ -4743,7 +4740,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) {
const CTransaction &tx = e.GetTx();
const uint256 &hash = tx.GetHash();
if ( tx.vjoinsplit.size() == 0 ) {
if ( tx.vjoinsplit.empty() && tx.vShieldedSpend.empty()) {
transactionsToRemove.push_back(tx);
tmpmempool.addUnchecked(hash,e,true);
}
@@ -4762,10 +4759,10 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
CValidationState state;
CTransaction Tx;
const CTransaction &tx = (CTransaction)block.vtx[i];
if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0)))
if (tx.IsCoinBase() || (!tx.vjoinsplit.empty() && !tx.vShieldedSpend.empty()) || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0)))
continue;
Tx = tx;
if ( myAddtomempool(Tx, &state) == false ) // happens with out of order tx in block on resync
if ( myAddtomempool(Tx, &state, true) == false ) // happens with out of order tx in block on resync
{
//LogPrintf("Rejected by mempool, reason: .%s.\n", state.GetRejectReason().c_str());
// take advantage of other checks, but if we were only rejected because it is a valid staking
@@ -4830,9 +4827,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
{
const CTransaction &tx = e.GetTx();
const uint256 &hash = tx.GetHash();
if ( tx.vjoinsplit.size() == 0 ) {
mempool.addUnchecked(hash,e,true);
}
mempool.addUnchecked(hash,e,true);
}
//fprintf(stderr, "finished adding back. mempoolsize.%ld\n",mempool.size());
// empty the temp mempool for next time.

View File

@@ -274,7 +274,7 @@ void PruneAndFlush();
/** (try to) add transaction to memory pool **/
bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,
bool* pfMissingInputs, bool fRejectAbsurdFee=false, int dosLevel=-1);
bool* pfMissingInputs, bool fRejectAbsurdFee=false, int dosLevel=-1, bool fSkipExpiry=false);
struct CNodeStateStats {