diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index 3959a6a7c..bc19e7bd6 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -502,6 +502,83 @@ cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid) return(0); } +cJSON *get_listunspent(char *refcoin,char *acname) +{ + cJSON *retjson; char *retstr,str[65]; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","","","","")) != 0 ) + { + return(retjson); + } + else if ( retstr != 0 ) + { + fprintf(stderr,"get_listunspent.(%s) %s error.(%s)\n",refcoin,acname,retstr); + free(retstr); + } + return(0); +} + +cJSON *z_listunspent(char *refcoin,char *acname) +{ + cJSON *retjson; char *retstr,str[65]; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_listunspent","","","","")) != 0 ) + { + return(retjson); + } + else if ( retstr != 0 ) + { + fprintf(stderr,"get_zlistunspent.(%s) %s error.(%s)\n",refcoin,acname,retstr); + free(retstr); + } + return(0); +} + +cJSON *z_listoperationids(char *refcoin,char *acname) +{ + cJSON *retjson; char *retstr,str[65]; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_listoperationids","","","","")) != 0 ) + { + return(retjson); + } + else if ( retstr != 0 ) + { + fprintf(stderr,"get_zlistoperationids.(%s) %s error.(%s)\n",refcoin,acname,retstr); + free(retstr); + } + return(0); +} + +cJSON *z_getoperationstatus(char *refcoin,char *acname,char *opid) +{ + cJSON *retjson; char *retstr,str[65],params[512]; + sprintf(params,"[%s]",opid); + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getoperationstatus",params,"","","")) != 0 ) + { + return(retjson); + } + else if ( retstr != 0 ) + { + fprintf(stderr,"get_zgetoperationstatus.(%s) %s error.(%s)\n",refcoin,acname,retstr); + free(retstr); + } + return(0); +} + +cJSON *z_getoperationresult(char *refcoin,char *acname,char *opid) +{ + cJSON *retjson; char *retstr,str[65],params[512]; + sprintf(params,"[%s]",opid); + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getoperationresult",params,"","","")) != 0 ) + { + return(retjson); + } + else if ( retstr != 0 ) + { + fprintf(stderr,"get_zgetoperationstatus.(%s) %s error.(%s)\n",refcoin,acname,retstr); + free(retstr); + } + return(0); +} + int32_t validateaddress(char *refcoin,char *acname,char *depositaddr, char* compare) { cJSON *retjson; char *retstr; int32_t res=0; @@ -535,6 +612,89 @@ int32_t z_validateaddress(char *refcoin,char *acname,char *depositaddr, char *co return (res); } +int64_t z_getbalance(char *refcoin,char *acname,char *coinaddr) +{ + cJSON *retjson; char *retstr; int64_t amount=0; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getbalance",coinaddr,"","","")) != 0 ) + { + fprintf(stderr,"z_getbalance.(%s) %s returned json!\n",refcoin,acname); + free_json(retjson); + } + else if ( retstr != 0 ) + { + amount = atof(retstr) * SATOSHIDEN + 0.0000000049999; + free(retstr); + } + return (amount); +} + +int32_t getnewaddress(char *coinaddr,char *refcoin,char *acname) +{ + cJSON *retjson; char *retstr; int64_t amount=0; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getnewaddress","","","","")) != 0 ) + { + fprintf(stderr,"getnewaddress.(%s) %s returned json!\n",refcoin,acname); + free_json(retjson); + return(-1); + } + else if ( retstr != 0 ) + { + strcpy(coinaddr,retstr); + free(retstr); + return(0); + } +} + +int64_t find_onetime_amount(char *coinstr,char *coinaddr) +{ + cJSON *array,*item; int32_t i,n; char *addr; int64_t amount = 0; + coinaddr[0] = 0; + if ( (array= get_listunspent(coinstr,"")) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; i 0 ) + { + for (i=0; i %s %.8f\n",coinstr,coinaddr,zsaddr,dstr(amount)); + return(0); +} + +int32_t sprout_send(char *coinstr,char *zcaddr,char *coinaddr,int64_t amount) +{ + printf("do sapling send %s %s -> %s %.8f\n",coinstr,coinaddr,zsaddr,dstr(amount)); + return(0); +} + cJSON *getinputarray(int64_t *totalp,cJSON *unspents,int64_t required) { cJSON *vin,*item,*vins = cJSON_CreateArray(); int32_t i,n,v; int64_t satoshis; bits256 txid; @@ -621,6 +793,38 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd return(hasvout); } +int32_t have_pending_opid(char *coinstr) +{ + cJSON *array,*status,*result; int32_t i,n,pending = 0; char *statusstr; + if ( (array= z_listoperationids(coinstr,"")) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; i txfee ) + { + // find taddr with funds and send all to zsaddr + sapling_send(coinstr,coinaddr,zsaddr,amount-txfee); + alldone = 0; + sleep(1); + } + if ( (amount= find_sprout_amount(zcaddr)) > txfee ) + { + // generate taddr, send max of 10000.0001 + if ( amount > stdamount+txfee ) + amount = stdamount + txfee; + if ( getnewaddress(coinaddr,coinstr,"") == 0 ) + { + sprout_send(coinstr,zcaddr,coinaddr,amount); + } else printf("couldnt getnewaddress!\n"); + alldone = 0; + sleep(10); + } + if ( alldone != 0 ) + break; + } + printf("%s %s ALLDONE!\n",coinstr,zsaddr); return(0); } diff --git a/src/main.cpp b/src/main.cpp index bab4f32b4..b609900ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4648,7 +4648,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C // because we receive the wrong transactions for it. // Size limits - fprintf(stderr,"%s checkblock %d -> %d vs blocksize.%d\n",ASSETCHAINS_SYMBOL,height,MAX_BLOCK_SIZE(height),(int32_t)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)); + //fprintf(stderr,"%s checkblock %d -> %d vs blocksize.%d\n",ASSETCHAINS_SYMBOL,height,MAX_BLOCK_SIZE(height),(int32_t)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)); if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_SIZE(height) || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE(height)) return state.DoS(100, error("CheckBlock: size limits failed"), REJECT_INVALID, "bad-blk-length");