Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
ca0fc8d7fc
  1. 6
      basilisk/basilisk_bitcoin.c
  2. 6
      iguana/SuperNET_keys.c
  3. 28
      iguana/iguana_wallet.c

6
basilisk/basilisk_bitcoin.c

@ -955,7 +955,7 @@ struct basilisk_spend *basilisk_addspend(struct supernet_info *myinfo,char *symb
void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *item,int32_t spentheight,int32_t relayid,int32_t RTheight) void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *item,int32_t spentheight,int32_t relayid,int32_t RTheight)
{ {
//{"txid":"4814dc8a357f93f16271eb43806a69416ec41ab1956b128d170402b0a1b37c7f","vout":2,"address":"RSyKVKNxrSDc1Vwvh4guYb9ZDEpvMFz2rm","scriptPubKey":"76a914c210f6711e98fe9971757ede2b2dcb0507f3f25e88ac","amount":9.99920000,"timestamp":1466684518,"height":1160306,"confirmations":22528,"checkind":1157,"spent":{"hdrsi":2320,"pkind":168,"unspentind":1157,"prevunspentind":0,"satoshis":"999920000","txidind":619,"vout":2,"type":2,"fileid":0,"scriptpos":0,"scriptlen":25},"spentheight":1161800,"dest":{"error":"couldnt find spent info"}} //{"txid":"4814dc8a357f93f16271eb43806a69416ec41ab1956b128d170402b0a1b37c7f","vout":2,"address":"RSyKVKNxrSDc1Vwvh4guYb9ZDEpvMFz2rm","scriptPubKey":"76a914c210f6711e98fe9971757ede2b2dcb0507f3f25e88ac","amount":9.99920000,"timestamp":1466684518,"height":1160306,"confirmations":22528,"checkind":1157,"spent":{"hdrsi":2320,"pkind":168,"unspentind":1157,"prevunspentind":0,"satoshis":"999920000","txidind":619,"vout":2,"type":2,"fileid":0,"scriptpos":0,"scriptlen":25},"spentheight":1161800,"dest":{"error":"couldnt find spent info"}}
int32_t i,n,j,m,already_spent=0; struct basilisk_unspent bu,bu2; char *address,*script,*destaddr; struct iguana_waccount *wacct; struct iguana_waddress *waddr; cJSON *dest,*vouts,*vitem; double ratio; int32_t i,n,j,m,already_spent=0; struct basilisk_unspent bu,bu2; char *address,*script=0,*destaddr; struct iguana_waccount *wacct; struct iguana_waddress *waddr=0; cJSON *dest,*vouts,*vitem; double ratio;
if ( (address= jstr(item,"address")) != 0 && (script= jstr(item,"scriptPubKey")) != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 ) if ( (address= jstr(item,"address")) != 0 && (script= jstr(item,"scriptPubKey")) != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 )
{ {
if ( relayid >= 64 ) if ( relayid >= 64 )
@ -976,6 +976,7 @@ void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *co
bu.unspentind = juint(item,"checkind"); bu.unspentind = juint(item,"checkind");
bu.timestamp = juint(item,"timestamp"); bu.timestamp = juint(item,"timestamp");
decode_hex(bu.script,bu.spendlen,script); decode_hex(bu.script,bu.spendlen,script);
printf("unspentupdate.(%s)\n",jprint(item,0));
n = waddr->numunspents; n = waddr->numunspents;
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
@ -1003,6 +1004,7 @@ void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *co
already_spent = spentheight; already_spent = spentheight;
if ( (bu.spentheight= already_spent) != 0 ) if ( (bu.spentheight= already_spent) != 0 )
bu.status = 1; bu.status = 1;
printf("i.%d n.%d\n",i,n);
if ( i == n ) if ( i == n )
{ {
if ( i >= waddr->maxunspents ) if ( i >= waddr->maxunspents )
@ -1046,7 +1048,7 @@ void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *co
} }
} }
} }
} } else printf("waddr.%p script.%p address.%p %s\n",waddr,script,address,address!=0?address:"");
} }
void basilisk_relay_unspentsprocess(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *relayjson) void basilisk_relay_unspentsprocess(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *relayjson)

6
iguana/SuperNET_keys.c

@ -265,7 +265,7 @@ int32_t _SuperNET_encryptjson(struct supernet_info *myinfo,char *destfname,char
wallethash = SuperNET_linehash(passphrase); wallethash = SuperNET_linehash(passphrase);
SuperNET_linehash(fname2fa); // maps special chars SuperNET_linehash(fname2fa); // maps special chars
wallet2priv = SuperNET_wallet2priv(fname2fa,wallethash); wallet2priv = SuperNET_wallet2priv(fname2fa,wallethash);
//char str2[65]; printf("ENCRYPT.[%s %s] (%s) 2.%s\n",passphrase,fname2fa,bits256_str(str,wallethash),bits256_str(str2,wallet2priv)); char str2[65]; printf("ENCRYPT.[%s %s] (%s) 2.%s\n",passphrase,fname2fa,bits256_str(str,wallethash),bits256_str(str2,wallet2priv));
wallet2shared = SuperNET_wallet2shared(wallethash,wallet2priv); wallet2shared = SuperNET_wallet2shared(wallethash,wallet2priv);
wallet2pub = curve25519(wallet2shared,curve25519_basepoint9()); wallet2pub = curve25519(wallet2shared,curve25519_basepoint9());
sprintf(destfname,"%s/%s",GLOBAL_CONFSDIR,bits256_str(str,wallet2pub)); sprintf(destfname,"%s/%s",GLOBAL_CONFSDIR,bits256_str(str,wallet2pub));
@ -403,7 +403,7 @@ TWO_STRINGS(SuperNET,decryptjson,password,permanentfile)
wallet2priv = bits256_conv(fname2); wallet2priv = bits256_conv(fname2);
if ( (retjson= SuperNET_decryptedjson(destfname,pass,sizeof(pass),wallethash,fname2,sizeof(fname2),wallet2priv)) != 0 ) if ( (retjson= SuperNET_decryptedjson(destfname,pass,sizeof(pass),wallethash,fname2,sizeof(fname2),wallet2priv)) != 0 )
{ {
//printf("decrypt pass.(%s) fname2.(%s) -> destfname.(%s)\n",pass,fname2,destfname); printf("decrypt pass.(%s) fname2.(%s) -> destfname.(%s)\n",pass,fname2,destfname);
//obj = jduplicate(jobj(retjson,"payload")); //obj = jduplicate(jobj(retjson,"payload"));
//jdelete(retjson,"payload"); //jdelete(retjson,"payload");
//jadd(retjson,"result",obj); //jadd(retjson,"result",obj);
@ -417,7 +417,7 @@ THREE_STRINGS(SuperNET,encryptjson,password,permanentfile,payload)
safecopy(pass,password,sizeof(pass)); safecopy(pass,password,sizeof(pass));
safecopy(fname2,permanentfile,sizeof(fname2)); safecopy(fname2,permanentfile,sizeof(fname2));
argjson = jduplicate(json); argjson = jduplicate(json);
//printf("argjson.(%s)\n",jprint(argjson,0)); printf("argjson.(%s)\n",jprint(argjson,0));
jdelete(argjson,"agent"); jdelete(argjson,"agent");
jdelete(argjson,"method"); jdelete(argjson,"method");
jdelete(argjson,"password"); jdelete(argjson,"password");

28
iguana/iguana_wallet.c

@ -33,6 +33,7 @@ struct iguana_waddress *iguana_waddressfind(struct supernet_info *myinfo,struct
{ {
struct iguana_waddress *waddr; uint8_t addrtype,rmd160[20]; struct iguana_waddress *waddr; uint8_t addrtype,rmd160[20];
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
//calc_rmd160_sha256(rmd160,pubkey33,33);
HASH_FIND(hh,wacct->waddr,rmd160,sizeof(rmd160),waddr); HASH_FIND(hh,wacct->waddr,rmd160,sizeof(rmd160),waddr);
//if ( waddr != 0 && coin != 0 && strcmp(coin->symbol,waddr->symbol) != 0 ) //if ( waddr != 0 && coin != 0 && strcmp(coin->symbol,waddr->symbol) != 0 )
// return(0); // return(0);
@ -166,7 +167,9 @@ 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); int32_t i; for (i=0; i<20; i++)
printf("%02x",waddr->rmd160[i]);
printf(" add (%s) scriptlen.%d -> (%s) wif.(%s)\n",waddr->coinaddr,waddr->scriptlen,wacct->account,waddr->wifstr);
} }
else else
{ {
@ -216,11 +219,11 @@ struct iguana_waddress *iguana_waddresssearch(struct supernet_info *myinfo,struc
struct iguana_waddress *iguana_waddresscalc(struct supernet_info *myinfo,uint8_t pubtype,uint8_t wiftype,struct iguana_waddress *waddr,bits256 privkey) struct iguana_waddress *iguana_waddresscalc(struct supernet_info *myinfo,uint8_t pubtype,uint8_t wiftype,struct iguana_waddress *waddr,bits256 privkey)
{ {
waddr->privkey = privkey; waddr->privkey = privkey;
bitcoin_pubkey33(myinfo->ctx,waddr->pubkey,waddr->privkey);
calc_rmd160_sha256(waddr->rmd160,waddr->pubkey,33);
bitcoin_address(waddr->coinaddr,pubtype,waddr->rmd160,sizeof(waddr->rmd160)); bitcoin_address(waddr->coinaddr,pubtype,waddr->rmd160,sizeof(waddr->rmd160));
if ( bits256_nonz(privkey) != 0 ) if ( bits256_nonz(privkey) != 0 )
{ {
bitcoin_pubkey33(myinfo->ctx,waddr->pubkey,waddr->privkey);
calc_rmd160_sha256(waddr->rmd160,waddr->pubkey,33);
myinfo->dirty = (uint32_t)time(NULL); myinfo->dirty = (uint32_t)time(NULL);
if ( bitcoin_priv2wif(waddr->wifstr,waddr->privkey,wiftype) > 0 ) if ( bitcoin_priv2wif(waddr->wifstr,waddr->privkey,wiftype) > 0 )
{ {
@ -795,7 +798,7 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi
} }
printf("persistent address not found in wallet, autoadd.(%s)\n",coinaddr); printf("persistent address not found in wallet, autoadd.(%s)\n",coinaddr);
} }
else if ( flag >= 0 ) else if ( persistent_flag != 0 )
printf("found persistent address in wallet\n"); printf("found persistent address in wallet\n");
} }
portable_mutex_unlock(&myinfo->bu_mutex); portable_mutex_unlock(&myinfo->bu_mutex);
@ -803,6 +806,11 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi
*goodp = good; *goodp = good;
if ( badp != 0 ) if ( badp != 0 )
*badp = bad; *badp = bad;
if ( iguana_waddresssearch(myinfo,&wacct,myinfo->myaddr.BTCD) != 0 )
{
printf("found persistent address.(%s)\n",myinfo->myaddr.BTCD);
}
return(array); return(array);
} }
@ -855,6 +863,7 @@ void iguana_walletinitcheck(struct supernet_info *myinfo,struct iguana_info *coi
privkey = bits256_conv(child->valuestring); privkey = bits256_conv(child->valuestring);
if ( iguana_waddresscalc(myinfo,coin->chain->pubtype,coin->chain->wiftype,&waddr,privkey) != 0 ) if ( iguana_waddresscalc(myinfo,coin->chain->pubtype,coin->chain->wiftype,&waddr,privkey) != 0 )
iguana_waddressadd(myinfo,coin,wacct,&waddr,0); iguana_waddressadd(myinfo,coin,wacct,&waddr,0);
else printf("walletinitcheck: error waddresscalc\n");
} }
} }
} }
@ -1188,6 +1197,7 @@ THREE_STRINGS(bitcoinrpc,encryptwallet,passphrase,password,permanentfile)
char *retstr; char *retstr;
if ( remoteaddr != 0 ) if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}")); return(clonestr("{\"error\":\"no remote\"}"));
iguana_walletlock(myinfo,coin);
if ( password == 0 || password[0] == 0 ) if ( password == 0 || password[0] == 0 )
password = passphrase; password = passphrase;
if ( passphrase == 0 || passphrase[0] == 0 ) if ( passphrase == 0 || passphrase[0] == 0 )
@ -1197,7 +1207,15 @@ THREE_STRINGS(bitcoinrpc,encryptwallet,passphrase,password,permanentfile)
if ( permanentfile != 0 ) if ( permanentfile != 0 )
strcpy(myinfo->permanentfile,permanentfile); strcpy(myinfo->permanentfile,permanentfile);
retstr = SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,myinfo->password); retstr = SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,myinfo->password);
//iguana_walletlock(myinfo); myinfo->expiration = (uint32_t)time(NULL) + 3600*24;
struct iguana_waddress waddr; struct iguana_waccount *wacct;
if ( (wacct= iguana_waccountcreate(myinfo,"default")) != 0 )
{
if ( iguana_waddresscalc(myinfo,coin->chain->pubtype,coin->chain->wiftype,&waddr,myinfo->persistent_priv) != 0 )
iguana_waddressadd(myinfo,coin,wacct,&waddr,0);
else printf("couldnt waddresscalc persistent\n");
} else printf("coildnt create default account\n");
iguana_walletinitcheck(myinfo,coin);
myinfo->dirty = (uint32_t)time(NULL); myinfo->dirty = (uint32_t)time(NULL);
return(retstr); return(retstr);
} }

Loading…
Cancel
Save