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

@@ -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 )