Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
56095fe7f1
  1. 1
      iguana/iguana_rpc.c
  2. 60
      iguana/iguana_wallet.c
  3. 1
      includes/iguana_funcs.h

1
iguana/iguana_rpc.c

@ -402,6 +402,7 @@ static char *importwallet(RPCARGS)
static char *walletpassphrase(RPCARGS) static char *walletpassphrase(RPCARGS)
{ {
sglue3(0,CALLGLUE,"bitcoinrpc","walletpassphrase","password",params[0],"permanentfile",params[2],"timeout",params[1]);
return(sglue3(0,CALLGLUE,"bitcoinrpc","walletpassphrase","password",params[0],"permanentfile",params[2],"timeout",params[1])); return(sglue3(0,CALLGLUE,"bitcoinrpc","walletpassphrase","password",params[0],"permanentfile",params[2],"timeout",params[1]));
} }

60
iguana/iguana_wallet.c

@ -159,7 +159,7 @@ struct iguana_waddress *iguana_waddressadd(struct supernet_info *myinfo,struct i
HASH_ADD_KEYPTR(hh,wacct->waddr,waddr->rmd160,sizeof(waddr->rmd160),waddr); HASH_ADD_KEYPTR(hh,wacct->waddr,waddr->rmd160,sizeof(waddr->rmd160),waddr);
myinfo->dirty = (uint32_t)time(NULL); myinfo->dirty = (uint32_t)time(NULL);
printf("add (%s) scriptlen.%d -> (%s) wif.(%s)\n",waddr->coinaddr,waddr->scriptlen,wacct->account,waddr->wifstr); printf("add (%s) scriptlen.%d -> (%s) wif.(%s)\n",waddr->coinaddr,waddr->scriptlen,wacct->account,waddr->wifstr);
} } else printf("(%s) already in account.(%s)\n",waddr->coinaddr,wacct->account);
if ( waddr != 0 && waddr->symbol[0] == 0 ) if ( waddr != 0 && waddr->symbol[0] == 0 )
strcpy(waddr->symbol,coin->symbol); strcpy(waddr->symbol,coin->symbol);
return(waddr); return(waddr);
@ -194,7 +194,7 @@ struct iguana_waddress *iguana_waddresssearch(struct supernet_info *myinfo,struc
} }
(*wacctp) = wacct; (*wacctp) = wacct;
return(waddr); return(waddr);
} } else printf("not in (%s)\n",wacct->account);
} }
(*wacctp) = 0; (*wacctp) = 0;
return(0); return(0);
@ -222,7 +222,7 @@ struct iguana_waddress *iguana_waddresscalc(struct supernet_info *myinfo,uint8_t
struct iguana_waddress *iguana_waccountswitch(struct supernet_info *myinfo,struct iguana_info *coin,char *account,char *coinaddr,char *redeemScript) struct iguana_waddress *iguana_waccountswitch(struct supernet_info *myinfo,struct iguana_info *coin,char *account,char *coinaddr,char *redeemScript)
{ {
struct iguana_waccount *wacct = 0; struct iguana_waddress addr,*waddr = 0; int32_t flag = 0; struct iguana_waccount *wacct = 0; struct iguana_waddress addr,*waddr = 0; int32_t flag = 0;
if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 ) if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 && wacct != 0 )
{ {
if ( strcmp(wacct->account,account) != 0 ) if ( strcmp(wacct->account,account) != 0 )
{ {
@ -234,9 +234,10 @@ struct iguana_waddress *iguana_waccountswitch(struct supernet_info *myinfo,struc
if ( (wacct= iguana_waccountcreate(myinfo,coin,account)) != 0 ) if ( (wacct= iguana_waccountcreate(myinfo,coin,account)) != 0 )
{ {
waddr = iguana_waddresscreate(myinfo,coin,wacct,coinaddr,redeemScript); waddr = iguana_waddresscreate(myinfo,coin,wacct,coinaddr,redeemScript);
if ( flag != 0 && redeemScript == 0 ) if ( waddr != 0 && redeemScript == 0 )
iguana_waddresscalc(myinfo,coin->chain->pubtype,coin->chain->wiftype,waddr,addr.privkey); iguana_waddresscalc(myinfo,coin->chain->pubtype,coin->chain->wiftype,waddr,addr.privkey);
} }
myinfo->dirty = (uint32_t)time(NULL);
return(waddr); return(waddr);
} }
@ -303,9 +304,9 @@ cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_i
return(array); return(array);
} }
struct iguana_waddress *iguana_ismine(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t addrtype,uint8_t pubkey[65],uint8_t rmd160[20]) struct iguana_waddress *iguana_ismine(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,uint8_t addrtype,uint8_t pubkey[65],uint8_t rmd160[20])
{ {
char coinaddr[65]; struct iguana_waccount *wacct; struct iguana_waddress *waddr = 0; struct iguana_waccount *wacct; struct iguana_waddress *waddr = 0;
if ( bitcoin_address(coinaddr,addrtype,rmd160,20) > 0 ) if ( bitcoin_address(coinaddr,addrtype,rmd160,20) > 0 )
waddr = iguana_waddresssearch(myinfo,&wacct,coinaddr); waddr = iguana_waddresssearch(myinfo,&wacct,coinaddr);
return(waddr); return(waddr);
@ -695,9 +696,12 @@ uint8_t iguana_waddrvalidate(struct supernet_info *myinfo,struct iguana_info *co
cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coin,int32_t flag,cJSON *array,int32_t *goodp,int32_t *badp,int32_t *errors) cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coin,int32_t flag,cJSON *array,int32_t *goodp,int32_t *badp,int32_t *errors)
{ {
struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr=0,*tmp2; uint8_t errorflags; int32_t i,good=0,bad=0,_errors[8]; cJSON *item; char coinaddr[64]; struct iguana_waccount *wacct,*tmp,*checkwacct; struct iguana_waddress *checkwaddr,*waddr=0,*tmp2; uint8_t persistent_rmd160[20],errorflags; int32_t i,persistent_flag=0,good=0,bad=0,_errors[8]; cJSON *item; char coinaddr[64],*retstr;
if ( errors == 0 ) if ( errors == 0 )
errors = _errors; errors = _errors;
if ( myinfo->decryptstr != 0 )
calc_rmd160_sha256(persistent_rmd160,myinfo->persistent_pubkey33,33);
else memset(persistent_rmd160,0,sizeof(persistent_rmd160));
portable_mutex_lock(&myinfo->bu_mutex); portable_mutex_lock(&myinfo->bu_mutex);
HASH_ITER(hh,myinfo->wallet,wacct,tmp) HASH_ITER(hh,myinfo->wallet,wacct,tmp)
{ {
@ -733,6 +737,12 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi
jaddi(array,item); jaddi(array,item);
} }
} else good++; } else good++;
if ( myinfo->decryptstr != 0 && persistent_flag == 0 && memcmp(waddr->rmd160,persistent_rmd160,20) == 0 )
{
persistent_flag = 1;
bitcoin_address(coinaddr,coin->chain->pubtype,waddr->rmd160,20);
printf("FOUND PERSISTENT.%s in %s\n",coinaddr,wacct->account);
}
} }
} }
if ( flag < -1 ) if ( flag < -1 )
@ -741,6 +751,29 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi
myfree(wacct,sizeof(*wacct)); myfree(wacct,sizeof(*wacct));
} }
} }
if ( myinfo->decryptstr != 0 )
{
if ( flag >= 0 && persistent_flag == 0 )
{
bitcoin_address(coinaddr,coin->chain->pubtype,persistent_rmd160,20);
if ( (retstr= setaccount(myinfo,coin,0,"default",coinaddr,0)) != 0 )
{
free(retstr);
if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 )
{
memcpy(waddr->rmd160,persistent_rmd160,20);
memcpy(waddr->pubkey,myinfo->persistent_pubkey33,33);
waddr->privkey = myinfo->persistent_priv;
strcpy(waddr->coinaddr,coinaddr);
if ( (checkwaddr= iguana_waddresssearch(myinfo,&checkwacct,waddr->coinaddr)) != waddr || checkwacct != wacct )
;
}
}
printf("persistent address not found in wallet, autoadd.(%s)\n",coinaddr);
}
else if ( flag >= 0 )
printf("found persistent address in wallet\n");
}
portable_mutex_unlock(&myinfo->bu_mutex); portable_mutex_unlock(&myinfo->bu_mutex);
if ( goodp != 0 ) if ( goodp != 0 )
*goodp = good; *goodp = good;
@ -809,10 +842,11 @@ void iguana_walletinitcheck(struct supernet_info *myinfo,struct iguana_info *coi
} }
} }
free_json(payload); free_json(payload);
myinfo->decryptstr = 0;
scrubfree(myinfo->decryptstr); scrubfree(myinfo->decryptstr);
myinfo->decryptstr = 0;
myinfo->dirty = 0; myinfo->dirty = 0;
} }
printf("call walletiterate from initcheck.%p\n",myinfo->decryptstr);
iguana_walletiterate(myinfo,coin,1,0,0,0,0); iguana_walletiterate(myinfo,coin,1,0,0,0,0);
} }
@ -931,7 +965,7 @@ char *getnewaddress(struct supernet_info *myinfo,struct iguana_waddress **waddrp
STRING_ARG(bitcoinrpc,validateaddress,address) STRING_ARG(bitcoinrpc,validateaddress,address)
{ {
cJSON *retjson; uint8_t addrtype,rmd160[20],pubkey[65]; struct iguana_info *other,*tmp; char str[256]; cJSON *retjson; uint8_t addrtype,rmd160[20],pubkey[65]; char coinaddr[64],str[256];
if ( remoteaddr != 0 ) if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}")); return(clonestr("{\"error\":\"no remote\"}"));
if ( iguana_addressvalidate(coin,&addrtype,address) < 0 ) if ( iguana_addressvalidate(coin,&addrtype,address) < 0 )
@ -946,21 +980,22 @@ STRING_ARG(bitcoinrpc,validateaddress,address)
strcat(str,"88ac"); strcat(str,"88ac");
jaddstr(retjson,"scriptPubKey",str); jaddstr(retjson,"scriptPubKey",str);
jadd(retjson,"isscript",(addrtype == coin->chain->p2shtype) ? jtrue() : jfalse()); jadd(retjson,"isscript",(addrtype == coin->chain->p2shtype) ? jtrue() : jfalse());
if ( iguana_ismine(myinfo,coin,addrtype,pubkey,rmd160) > 0 ) if ( iguana_ismine(myinfo,coin,coinaddr,addrtype,pubkey,rmd160) > 0 )
{ {
init_hexbytes_noT(str,pubkey,bitcoin_pubkeylen(pubkey)); init_hexbytes_noT(str,pubkey,bitcoin_pubkeylen(pubkey));
jaddstr(retjson,"pubkey",str); jaddstr(retjson,"pubkey",str);
cJSON_AddTrueToObject(retjson,"ismine"); cJSON_AddTrueToObject(retjson,"ismine");
} else cJSON_AddFalseToObject(retjson,"ismine"); } else cJSON_AddFalseToObject(retjson,"ismine");
jaddstr(retjson,coin->symbol,coinaddr);
//portable_mutex_lock(&myinfo->allcoins_mutex); //portable_mutex_lock(&myinfo->allcoins_mutex);
HASH_ITER(hh,myinfo->allcoins,other,tmp) /*HASH_ITER(hh,myinfo->allcoins,other,tmp)
{ {
if ( strcmp(other->symbol,coin->symbol) != 0 ) if ( strcmp(other->symbol,coin->symbol) != 0 )
{ {
iguana_addressconv(coin,str,other,addrtype == coin->chain->p2shtype,rmd160); iguana_addressconv(coin,str,other,addrtype == coin->chain->p2shtype,rmd160);
jaddstr(retjson,other->symbol,str); jaddstr(retjson,other->symbol,str);
} }
} }*/
//portable_mutex_unlock(&myinfo->allcoins_mutex); //portable_mutex_unlock(&myinfo->allcoins_mutex);
return(jprint(retjson,1)); return(jprint(retjson,1));
} }
@ -1090,6 +1125,7 @@ TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout)
return(clonestr("{\"error\":\"no remote\"}")); return(clonestr("{\"error\":\"no remote\"}"));
if ( timeout <= 0 ) if ( timeout <= 0 )
return(clonestr("{\"error\":\"timeout must be positive\"}")); return(clonestr("{\"error\":\"timeout must be positive\"}"));
iguana_walletlock(myinfo,coin);
printf("timeout.%d\n",timeout); printf("timeout.%d\n",timeout);
myinfo->expiration = (uint32_t)time(NULL) + timeout; myinfo->expiration = (uint32_t)time(NULL) + timeout;
retstr = SuperNET_login(IGUANA_CALLARGS,myinfo->handle,password,permanentfile,0); retstr = SuperNET_login(IGUANA_CALLARGS,myinfo->handle,password,permanentfile,0);

1
includes/iguana_funcs.h

@ -545,6 +545,7 @@ int64_t iguana_lockval(int32_t finalized,int64_t locktime);
int64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_pkhash **Ptrp,int64_t *supplyp,int32_t *numacctsp,int32_t *nonzp,int32_t *errsp,int32_t lastheight); int64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_pkhash **Ptrp,int64_t *supplyp,int32_t *numacctsp,int32_t *nonzp,int32_t *errsp,int32_t lastheight);
int32_t iguana_staker_sort(struct iguana_info *coin,bits256 *hash2p,uint8_t *refrmd160,struct iguana_pkhash *refP,int64_t *weights,int32_t numweights,bits256 *sortbuf); int32_t iguana_staker_sort(struct iguana_info *coin,bits256 *hash2p,uint8_t *refrmd160,struct iguana_pkhash *refP,int64_t *weights,int32_t numweights,bits256 *sortbuf);
bits256 mpz_div64(bits256 hash,uint64_t divval); bits256 mpz_div64(bits256 hash,uint64_t divval);
void iguana_walletinitcheck(struct supernet_info *myinfo,struct iguana_info *coin);
// ------------------------------------------------------[ Preparation ]---- // ------------------------------------------------------[ Preparation ]----
// Initialise a gfshare context for producing shares // Initialise a gfshare context for producing shares

Loading…
Cancel
Save