Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
388303ee63
  1. 2
      crypto777/iguana_secp.c
  2. 15
      iguana/SuperNET.c
  3. 2
      iguana/SuperNET.h
  4. 22
      iguana/SuperNET_keys.c
  5. 69
      iguana/exchanges/bitcoin.c
  6. 2
      iguana/iguana777.h
  7. 7
      iguana/iguana_json.c
  8. 2
      iguana/iguana_unspents.c
  9. 126
      iguana/iguana_wallet.c
  10. 1
      iguana/tests/activehandle
  11. 1
      iguana/tests/bitcoinrpc
  12. 1
      iguana/tests/encryptwallet
  13. 1
      iguana/tests/getaccountaddress
  14. 1
      iguana/tests/getnewaddress
  15. 1
      iguana/tests/login
  16. 1
      iguana/tests/walletpassphrase

2
crypto777/iguana_secp.c

@ -67,7 +67,7 @@ char *bitcoin_base58encode(char *coinaddr,uint8_t *data_,int32_t datalen)
for (i=0; i<datalen; i++)
swapbuf[datalen - i - 1] = data[i];
swapbuf[datalen] = 0;
bn_mpi2bn(&bn,swapbuf,datalen);
bn_mpi2bn(&bn,swapbuf,datalen+1);
while ( BN_cmp(&bn,&bn0) > 0 )
{
if ( BN_div(&dv,&rem,&bn,&bn58,ctx) == 0 )

15
iguana/SuperNET.c

@ -1314,6 +1314,7 @@ ZERO_ARGS(SuperNET,logout)
memset(myinfo->handle,0,sizeof(myinfo->handle));
memset(myinfo->myaddr.NXTADDR,0,sizeof(myinfo->myaddr.NXTADDR));
myinfo->myaddr.nxt64bits = 0;
myinfo->expiration = 0;
return(clonestr("{\"result\":\"logged out\"}"));
}
@ -1326,6 +1327,11 @@ ZERO_ARGS(SuperNET,activehandle)
jaddstr(retjson,"result","success");
jaddstr(retjson,"handle",myinfo->handle);
jaddbits256(retjson,"persistent",myinfo->myaddr.persistent);
if ( myinfo->expiration != 0 )
{
jaddstr(retjson,"status","unlocked");
jaddnum(retjson,"duration",myinfo->expiration - time(NULL));
} else jaddstr(retjson,"status","locked");
SuperNET_MYINFOadd(myinfo);
return(jprint(retjson,1));
}
@ -1375,11 +1381,12 @@ struct supernet_info *SuperNET_accountfind(cJSON *json)
FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase)
{
char *str,*decryptstr = 0; cJSON *argjson;
char *str,*decryptstr = 0; cJSON *argjson; uint32_t expire = myinfo->expiration;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( bits256_nonz(myinfo->persistent_priv) != 0 && (str= SuperNET_logout(IGUANA_CALLARGS)) != 0 )
free(str);
myinfo->expiration = expire;
if ( handle != 0 )
{
safecopy(myinfo->handle,handle,sizeof(myinfo->handle));
@ -1390,8 +1397,10 @@ FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase)
{
if ( (argjson= cJSON_Parse(decryptstr)) != 0 )
{
printf("decrypted.(%s)\n",decryptstr);
free(decryptstr);
printf("decrypted.(%s) exp.%u\n",decryptstr,myinfo->expiration);
if ( myinfo->decryptstr != 0 )
free(myinfo->decryptstr);
myinfo->decryptstr = decryptstr;
if ( (passphrase= jstr(argjson,"passphrase")) != 0 )
{
SuperNET_setkeys(myinfo,passphrase,(int32_t)strlen(passphrase),1);

2
iguana/SuperNET.h

@ -87,7 +87,7 @@ struct supernet_info
struct supernet_agent agents[SUPERNET_MAXAGENTS]; queue_t acceptQ;
int32_t numagents,numexchanges;
struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES];
char handle[1024];
char handle[1024],*decryptstr;
};
/*struct supernet_endpoint

22
iguana/SuperNET_keys.c

@ -78,7 +78,10 @@ char *SuperNET_parsemainargs(struct supernet_info *myinfo,bits256 *wallethashp,b
memcpy(wallethash.bytes,secretbuf,sizeof(wallethash));
//printf("wallethash.(%s)\n",bits256_str(str,wallethash));
if ( (wallet2fname= jstr(json,"permanentfile")) != 0 )
{
wallet2priv = SuperNET_wallet2priv(wallet2fname,wallethash);
myinfo->expiration = (uint32_t)(time(NULL) + 600);
}
}
exchanges = jarray(&n,json,"exchanges");
if ( jobj(json,"coins") != 0 )
@ -132,7 +135,7 @@ int32_t SuperNET_savejsonfile(char *fname,bits256 privkey,bits256 destpubkey,cJS
//sprintf(fname,"confs/iguana.%llu",(long long)wallet2shared.txid);
if ( (ciphered= SuperNET_cipher(0,0,json,0,privkey,destpubkey,confstr)) != 0 )
{
printf("save (%s) <- (%s)\n",fname,confstr);
printf("ciphered.save (%s) <- (%s)\n",fname,confstr);
if ( (fp= fopen(fname,"wb")) != 0 )
{
fwrite(ciphered,1,strlen(ciphered)+1,fp);
@ -144,7 +147,7 @@ int32_t SuperNET_savejsonfile(char *fname,bits256 privkey,bits256 destpubkey,cJS
else
{
//sprintf(fname,"confs/iguana.conf");
//printf("save (%s) <- (%s)\n",fname,confstr);
printf("save (%s) <- (%s)\n",fname,confstr);
if ( (fp= fopen(fname,"wb")) != 0 )
{
fwrite(confstr,1,strlen(confstr)+1,fp);
@ -203,6 +206,7 @@ cJSON *SuperNET_decryptedjson(char *passphrase,int32_t passsize,bits256 walletha
{
if ( (filejson= cJSON_Parse(confstr)) != 0 )
{
printf("confstr.(%s)\n",confstr);
if ( (deciphered= SuperNET_decipher(0,0,0,0,wallet2shared,curve25519(wallethash,curve25519_basepoint9()),jstr(filejson,"result"))) != 0 )
{
if ( (json= cJSON_Parse(deciphered)) == 0 )
@ -243,10 +247,11 @@ int32_t _SuperNET_encryptjson(char *destfname,char *passphrase,int32_t passsize,
wallethash = SuperNET_linehash(passphrase);
SuperNET_linehash(fname2fa); // maps special chars
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);
wallet2pub = curve25519(wallet2shared,curve25519_basepoint9());
sprintf(destfname,"confs/%s",bits256_str(str,wallet2pub));
printf("SAVE ARGJSON.(%s)\n",jprint(argjson,0));
//printf("shared.%llx -> pub.%s\n",(long long)wallet2shared.txid,bits256_str(str,wallet2pub));
SuperNET_savejsonfile(destfname,wallethash,wallet2pub,argjson);
return(0);
@ -401,12 +406,15 @@ TWO_STRINGS(SuperNET,decryptjson,password,permanentfile)
wallethash = bits256_conv(pass);
if ( strlen(fname2) == sizeof(wallet2priv)*2 && is_hexstr(fname2,(int32_t)sizeof(bits256)*2) > 0 )
wallet2priv = bits256_conv(fname2);
//printf("decrypt.(%s %s)\n",pass,fname2);
printf("decrypt.(%s %s)\n",pass,fname2);
if ( (retjson= SuperNET_decryptedjson(pass,sizeof(pass),wallethash,fname2,sizeof(fname2),wallet2priv)) != 0 )
{
obj = jduplicate(jobj(retjson,"payload"));
jdelete(retjson,"payload");
jadd(retjson,"result",obj);
if ( 0 )
{
obj = jduplicate(jobj(retjson,"payload"));
jdelete(retjson,"payload");
jadd(retjson,"result",obj);
}
return(jprint(retjson,1));
}
else return(clonestr("{\"error\":\"couldnt decrypt json file\"}"));

69
iguana/exchanges/bitcoin.c

@ -97,19 +97,47 @@ int32_t bitcoin_validaddress(struct iguana_info *coin,char *coinaddr)
return(0);
}
int32_t bitcoin_priv2wif(char *wifstr,bits256 privkey,uint8_t addrtype)
/*int32_t btc_priv2wif(char *wifstr,uint8_t privkey[32],uint8_t addrtype)
{
uint8_t data[128]; bits256 hash; int32_t i;
memcpy(data,privkey.bytes,sizeof(privkey));
data[32] = 1;
uint8_t tmp[128]; char hexstr[67]; cstring *btc_addr;
memcpy(tmp,privkey,32);
tmp[32] = 1;
init_hexbytes_noT(hexstr,tmp,32);
if ( (btc_addr= base58_encode_check(addrtype,true,tmp,33)) != 0 )
{
strcpy(wifstr,btc_addr->str);
cstr_free(btc_addr,true);
}
//printf("-> (%s) -> wif.(%s) addrtype.%02x\n",hexstr,wifstr,addrtype);
return(0);
}
cstring *base58_encode_check(uint8_t addrtype,bool have_addrtype,const void *data,size_t data_len)
{
uint8_t i,buf[64]; bits256 hash; cstring *s_enc;//,*s = cstr_new_sz(data_len + 1 + 4);
buf[0] = addrtype;
memcpy(buf+1,data,data_len);
hash = bits256_doublesha256(0,buf,(int32_t)data_len+1);
//bu_Hash4(md32,buf,(int32_t)data_len+1);
for (i=0; i<4; i++)
{
buf[data_len+i+1] = hash.bytes[31-i];
//printf("(%02x %02x) ",hash.bytes[31-i],md32[i]);
}
//printf("hash4 cmp\n");
s_enc = base58_encode(buf,data_len+5);
return s_enc;
}
*/
int32_t base58encode_checkbuf(uint8_t addrtype,uint8_t *data,int32_t data_len)
{
uint8_t i; bits256 hash;
data[0] = addrtype;
hash = bits256_doublesha256(0,data,33);
hash = bits256_doublesha256(0,data,(int32_t)data_len+1);
for (i=0; i<4; i++)
data[33+i] = hash.bytes[31-i];
if ( bitcoin_base58encode(wifstr,data,33+4) == 0 )
return(-1);
char str[65]; printf("(%s) -> wif.(%s) addrtype.%02x\n",bits256_str(str,privkey),wifstr,addrtype);
return((int32_t)strlen(wifstr));
data[data_len+i+1] = hash.bytes[31-i];
return(data_len + 5);
}
int32_t bitcoin_wif2priv(uint8_t *addrtypep,bits256 *privkeyp,char *wifstr)
@ -130,6 +158,27 @@ int32_t bitcoin_wif2priv(uint8_t *addrtypep,bits256 *privkeyp,char *wifstr)
return(-1);
}
int32_t bitcoin_priv2wif(char *wifstr,bits256 privkey,uint8_t addrtype)
{
uint8_t data[128]; int32_t len;
memcpy(data+1,privkey.bytes,sizeof(privkey));
data[33] = 1;
len = base58encode_checkbuf(addrtype,data,33);
if ( bitcoin_base58encode(wifstr,data,len) == 0 )
return(-1);
if ( 1 )
{
uint8_t checktype; bits256 checkpriv; char str[65],str2[65];
if ( bitcoin_wif2priv(&checktype,&checkpriv,wifstr) == sizeof(bits256) )
{
if ( checktype != addrtype || bits256_cmp(checkpriv,privkey) != 0 )
printf("(%s) -> wif.(%s) addrtype.%02x -> %02x (%s)\n",bits256_str(str,privkey),wifstr,addrtype,checktype,bits256_str(str2,checkpriv));
}
}
return((int32_t)strlen(wifstr));
}
int32_t iguana_parsevoutobj(struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_msgvout *vout,cJSON *voutobj)
{
int32_t len = 0; cJSON *skey; char *hexstr;

2
iguana/iguana777.h

@ -474,7 +474,7 @@ struct iguana_bundlereq
struct iguana_bitmap { int32_t width,height,amplitude; char name[52]; uint8_t data[IGUANA_WIDTH*IGUANA_HEIGHT*3]; };
struct iguana_waddress { UT_hash_handle hh; uint8_t rmd160[20],type,pubkey[33],wiftype; uint32_t symbolbits; bits256 privkey; char coinaddr[36],wifstr[54]; };
struct iguana_waddress { UT_hash_handle hh; uint8_t rmd160[20],type,pubkey[33],wiftype; bits256 privkey; char symbol[8],coinaddr[36],wifstr[54]; };
struct iguana_waccount { UT_hash_handle hh; char account[128]; struct iguana_waddress *waddr,*current; };
struct iguana_wallet { UT_hash_handle hh; struct iguana_waccount *wacct; };

7
iguana/iguana_json.c

@ -835,6 +835,7 @@ TWO_STRINGS(hmac,whirlpool,message,passphrase) { return(hmac_dispatch(hmac_whirl
STRING_ARG(SuperNET,bitcoinrpc,setcoin)
{
char buf[1024];
if ( setcoin != 0 && setcoin[0] != 0 )
{
strcpy(myinfo->rpcsymbol,setcoin);
@ -842,7 +843,11 @@ STRING_ARG(SuperNET,bitcoinrpc,setcoin)
printf("bitcoinrpc.%s\n",myinfo->rpcsymbol);
if ( iguana_launchcoin(myinfo->rpcsymbol,json) < 0 )
return(clonestr("{\"error\":\"error creating coin\"}"));
else return(clonestr("{\"result\":\"set bitcoin RPC coin\"}"));
else
{
sprintf(buf,"{\"result\":\"success\",\"setcoin\":\"%s\"}",setcoin);
return(clonestr(buf));
}
} else return(clonestr("{\"error\":\"bitcoinrpc needs setcoin value\"}"));
}

2
iguana/iguana_unspents.c

@ -2406,7 +2406,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
{
//printf("RT edge case couldnt link\n");
}
else printf("RT edge case\n");
else printf("RT edge case.%d\n",block->height);
}
if ( coin->spendvectorsaved <= 1 )
return(0);

126
iguana/iguana_wallet.c

@ -30,27 +30,30 @@ struct iguana_waddress *iguana_waddresscreate(struct iguana_info *coin,struct ig
{
waddr = mycalloc('w',1,sizeof(*waddr) + len);
strcpy(waddr->coinaddr,coinaddr);
strcpy(waddr->symbol,coin->symbol);
HASH_ADD_KEYPTR(hh,wacct,waddr->coinaddr,len,wacct);
}
return(waddr);
}
struct iguana_waddress *iguana_waddressadd(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount *wacct,struct iguana_waddress *refwaddr)
struct iguana_waddress *iguana_waddressadd(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount *wacct,struct iguana_waddress *addwaddr)
{
struct iguana_waddress *waddr; int32_t len = (int32_t)strlen(refwaddr->coinaddr)+1;
HASH_FIND(hh,wacct,refwaddr->coinaddr,len,waddr);
struct iguana_waddress *waddr; int32_t len = (int32_t)strlen(addwaddr->coinaddr)+1;
HASH_FIND(hh,wacct,addwaddr->coinaddr,len,waddr);
if ( waddr == 0 )
HASH_ADD_KEYPTR(hh,wacct,waddr->coinaddr,len,wacct);
if ( waddr != refwaddr )
{
waddr->privkey = refwaddr->privkey;
memcpy(waddr->pubkey,refwaddr->pubkey,sizeof(waddr->pubkey));
memcpy(waddr->rmd160,refwaddr->rmd160,sizeof(waddr->rmd160));
strcpy(waddr->coinaddr,refwaddr->coinaddr);
strcpy(waddr->wifstr,refwaddr->wifstr);
waddr->wiftype = refwaddr->wiftype;
waddr->type = refwaddr->type;
}
HASH_ADD_KEYPTR(hh,wacct->waddr,addwaddr->coinaddr,len,addwaddr);
if ( waddr != 0 && waddr != addwaddr )
{
waddr->privkey = addwaddr->privkey;
memcpy(waddr->pubkey,addwaddr->pubkey,sizeof(waddr->pubkey));
memcpy(waddr->rmd160,addwaddr->rmd160,sizeof(waddr->rmd160));
strcpy(waddr->coinaddr,addwaddr->coinaddr);
strcpy(waddr->wifstr,addwaddr->wifstr);
waddr->wiftype = addwaddr->wiftype;
waddr->type = addwaddr->type;
} else waddr = addwaddr;
if ( waddr != 0 )
strcpy(waddr->symbol,coin->symbol);
return(waddr);
}
@ -79,9 +82,10 @@ struct iguana_waddress *iguana_waddresssearch(struct iguana_info *coin,struct ig
struct iguana_waccount *iguana_waccountfind(struct iguana_info *coin,char *account)
{
struct iguana_waccount *waddr;
HASH_FIND(hh,coin->wallet,account,strlen(account)+1,waddr);
return(waddr);
struct iguana_waccount *wacct;
HASH_FIND(hh,coin->wallet,account,strlen(account)+1,wacct);
//printf("waccountfind.(%s) -> wacct.%p\n",account,wacct);
return(wacct);
}
struct iguana_waccount *iguana_waccountcreate(struct iguana_info *coin,char *account)
@ -92,7 +96,8 @@ struct iguana_waccount *iguana_waccountcreate(struct iguana_info *coin,char *acc
{
wacct = mycalloc('w',1,sizeof(*wacct) + len);
strcpy(wacct->account,account);
HASH_ADD_KEYPTR(hh,coin->wallet,account,len,wacct);
HASH_ADD_KEYPTR(hh,coin->wallet,wacct->account,len,wacct);
//printf("waccountcreate.(%s) -> wacct.%p\n",account,wacct);
}
return(wacct);
}
@ -184,6 +189,7 @@ void iguana_walletlock(struct supernet_info *myinfo)
memset(&myinfo->persistent_priv,0,sizeof(myinfo->persistent_priv));
memset(myinfo->secret,0,sizeof(myinfo->secret));
memset(myinfo->permanentfile,0,sizeof(myinfo->permanentfile));
myinfo->expiration = 0;
//printf("wallet locked\n");
}
@ -240,6 +246,7 @@ cJSON *iguana_waddressjson(cJSON *item,struct iguana_waddress *waddr)
//jaddstr(item,"wif",waddr->wifstr);
init_hexbytes_noT(str,waddr->rmd160,20);
jaddstr(item,"rmd160",str);
jaddstr(item,"coin",waddr->symbol);
return(item);
}
@ -328,7 +335,7 @@ int32_t iguana_loginsave(struct supernet_info *myinfo,struct iguana_info *coin,c
if ( (passphrase= jstr(loginjson,"passphrase")) != 0 )
{
_SuperNET_encryptjson(destfname,passphrase,0,myinfo->permanentfile,0,loginjson);
iguana_walletlock(myinfo);
//iguana_walletlock(myinfo);
printf("loginsave.(%s) <= (%s)\n",destfname,newstr);
}
free_json(loginjson);
@ -353,13 +360,14 @@ int32_t iguana_payloadupdate(struct supernet_info *myinfo,struct iguana_info *co
jaddbits256(payload,waddr->coinaddr,waddr->privkey);
jadd(retjson,"payload",payload);
newstr = jprint(retjson,1);
printf("newstr.(%s)\n",newstr);
retval = iguana_loginsave(myinfo,coin,newstr);
free(newstr);
}
} else printf("iguana_payloadupdate: error parsing.(%s)\n",retstr);
return(retval);
}
cJSON *iguana_walletadd(struct supernet_info *myinfo,struct iguana_info *coin,char *retstr,char *account,struct iguana_waddress *refwaddr,int32_t setcurrent)
cJSON *iguana_walletadd(struct supernet_info *myinfo,struct iguana_waddress **waddrp,struct iguana_info *coin,char *retstr,char *account,struct iguana_waddress *refwaddr,int32_t setcurrent)
{
cJSON *retjson=0; struct iguana_waccount *wacct; struct iguana_waddress *waddr;
if ( (wacct= iguana_waccountfind(coin,account)) == 0 )
@ -387,22 +395,24 @@ cJSON *iguana_walletadd(struct supernet_info *myinfo,struct iguana_info *coin,ch
jaddstr(retjson,"result","success");
}
}
if ( waddrp != 0 )
(*waddrp) = waddr;
return(retjson);
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
char *getnewaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *account,char *retstr)
char *getnewaddress(struct supernet_info *myinfo,struct iguana_waddress **waddrp,struct iguana_info *coin,char *account,char *retstr)
{
struct iguana_waddress addr; cJSON *retjson;
if ( myinfo->secret[0] == 0 )
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
if ( retstr != 0 )
{
memset(&addr,0,sizeof(addr));
if ( iguana_waddresscalc(coin->chain->pubtype,coin->chain->wiftype,&addr,rand256(1)) != 0 )
retjson = iguana_walletadd(myinfo,coin,retstr,account,&addr,1);
retjson = iguana_walletadd(myinfo,waddrp,coin,retstr,account,&addr,1);
else return(clonestr("{\"error\":\"couldnt calculate waddr\"}"));
} else return(clonestr("{\"error\":\"no wallet data\"}"));
return(jprint(retjson,1));
@ -478,15 +488,18 @@ STRING_ARG(bitcoinrpc,getaccount,address)
STRING_ARG(bitcoinrpc,getnewaddress,account)
{
char *retstr,*newretstr;
char *retstr,*newretstr; struct iguana_waddress *waddr;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->secret[0] != 0 )
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
if ( (retstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,0)) != 0 )
{
newretstr = getnewaddress(myinfo,coin,account,retstr);
free(retstr);
retstr = myinfo->decryptstr, myinfo->decryptstr = 0;
newretstr = getnewaddress(myinfo,&waddr,coin,account,retstr);
if ( retstr != 0 )
free(retstr);
return(newretstr);
}
else return(clonestr("{\"error\":\"no wallet payload\"}"));
@ -494,10 +507,10 @@ STRING_ARG(bitcoinrpc,getnewaddress,account)
STRING_ARG(bitcoinrpc,getaccountaddress,account)
{
char *retstr; struct iguana_waccount *wacct; struct iguana_waddress *waddr=0; cJSON *retjson;
char *retstr,*newstr; struct iguana_waccount *wacct; struct iguana_waddress *waddr=0; cJSON *retjson;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->secret[0] != 0 )
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
if ( account != 0 && account[0] != 0 )
{
@ -508,10 +521,19 @@ STRING_ARG(bitcoinrpc,getaccountaddress,account)
if ( (waddr= wacct->current) == 0 )
{
if ( (retstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,0)) != 0 )
return(getnewaddress(myinfo,coin,account,retstr));
else return(clonestr("{\"error\":\"no wallet payload\"}"));
{
free(retstr);
retstr = myinfo->decryptstr, myinfo->decryptstr = 0;
printf("loginstr.(%s)\n",retstr);
newstr = getnewaddress(myinfo,&waddr,coin,account,retstr);
if ( retstr != 0 )
free(retstr);
retstr = newstr;
} else return(clonestr("{\"error\":\"no wallet payload\"}"));
}
retjson = iguana_waddressjson(0,waddr);
if ( waddr != 0 )
retjson = iguana_waddressjson(0,waddr);
else return(clonestr("{\"error\":\"couldnt create address\"}"));
jaddstr(retjson,"account",account);
jaddstr(retjson,"result","success");
return(jprint(retjson,1));
@ -535,8 +557,8 @@ TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout)
return(clonestr("{\"error\":\"no remote\"}"));
if ( timeout <= 0 )
return(clonestr("{\"error\":\"timeout must be positive\"}"));
retstr = SuperNET_login(IGUANA_CALLARGS,myinfo->handle,password,permanentfile,0);
myinfo->expiration = (uint32_t)time(NULL) + timeout;
retstr = SuperNET_login(IGUANA_CALLARGS,myinfo->handle,password,permanentfile,0);
return(retstr);
}
@ -548,7 +570,7 @@ THREE_STRINGS(bitcoinrpc,encryptwallet,passphrase,password,permanentfile)
if ( password == 0 || password[0] == 0 )
password = passphrase;
retstr = SuperNET_login(IGUANA_CALLARGS,myinfo->handle,password,permanentfile,passphrase);
iguana_walletlock(myinfo);
//iguana_walletlock(myinfo);
return(retstr);
}
@ -559,16 +581,18 @@ FOUR_STRINGS(bitcoinrpc,walletpassphrasechange,oldpassword,newpassword,oldperman
return(clonestr("{\"error\":\"no remote\"}"));
if ( (tmpstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,oldpassword,oldpermanentfile,0)) != 0 )
{
if ( (tmpjson= cJSON_Parse(retstr)) != 0 )
free(tmpstr);
tmpstr = myinfo->decryptstr, myinfo->decryptstr = 0;
if ( (tmpjson= cJSON_Parse(tmpstr)) != 0 )
{
if ( (loginstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,newpassword,newpermanentfile,0)) != 0 )
{
if ( (loginjson= cJSON_Parse(loginstr)) != 0 )
if ( myinfo->decryptstr != 0 && (loginjson= cJSON_Parse(myinfo->decryptstr)) != 0 )
{
if ( (passphrase= jstr(loginjson,"passphrase")) != 0 )
{
_SuperNET_encryptjson(destfname,passphrase,0,newpermanentfile,0,loginjson);
iguana_walletlock(myinfo);
//iguana_walletlock(myinfo);
retstr = SuperNET_login(IGUANA_CALLARGS,myinfo->handle,newpassword,newpermanentfile,0);
}
free_json(loginjson);
@ -577,7 +601,8 @@ FOUR_STRINGS(bitcoinrpc,walletpassphrasechange,oldpassword,newpassword,oldperman
}
free_json(tmpjson);
}
free(tmpstr);
if ( tmpstr != 0 )
free(tmpstr);
}
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"error changing walletpassphrase\"}");
@ -600,13 +625,16 @@ TWOSTRINGS_AND_INT(bitcoinrpc,importprivkey,wif,account,rescan)
if ( account != 0 && account[0] != 0 )
waddr = iguana_waccountswitch(coin,account,addr.coinaddr);
}
if ( myinfo->secret[0] == 0 )
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
if ( (retstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,0)) != 0 )
{
iguana_waddresscalc(coin->chain->pubtype,coin->chain->wiftype,waddr,privkey);
retjson = iguana_walletadd(myinfo,coin,retstr,account,waddr,0);
free(retstr);
retstr = myinfo->decryptstr, myinfo->decryptstr = 0;
iguana_waddresscalc(coin->chain->pubtype,coin->chain->wiftype,waddr,privkey);
retjson = iguana_walletadd(myinfo,0,coin,retstr,account,waddr,0);
if ( retstr != 0 )
free(retstr);
return(jprint(retjson,1));
}
}
@ -650,7 +678,7 @@ STRING_ARG(bitcoinrpc,dumpwallet,filename)
{
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->secret[0] != 0 )
if ( myinfo->expiration != 0 )
return(SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,0));
else return(clonestr("{\"error\":\"wallet is locked, cant backup\"}"));
}
@ -677,17 +705,20 @@ STRING_ARG(bitcoinrpc,backupwallet,filename)
char *loginstr,*payloadstr,*retstr = 0; cJSON *retjson;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->secret[0] != 0 )
if ( myinfo->expiration != 0 )
{
if ( (loginstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,0)) != 0 )
{
free(loginstr);
loginstr = myinfo->decryptstr, myinfo->decryptstr = 0;
if ( (retjson= cJSON_Parse(loginstr)) != 0 )
{
if ( (payloadstr= jstr(retjson,"payload")) != 0 )
retstr = iguana_payloadsave(filename,payloadstr);
free_json(retjson);
}
free(loginstr);
if ( loginstr != 0 )
free(loginstr);
if ( retstr == 0 )
return(clonestr("{\"result\":\"wallet backup saved\"}"));
else return(retstr);
@ -721,7 +752,7 @@ STRING_ARG(bitcoinrpc,importwallet,filename)
cJSON *retjson = 0,*importjson,*loginjson = 0; long filesize; char *importstr,*loginstr;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->secret[0] != 0 )
if ( myinfo->expiration != 0 )
{
if ( (importstr= OS_filestr(&filesize,filename)) != 0 )
{
@ -729,8 +760,11 @@ STRING_ARG(bitcoinrpc,importwallet,filename)
{
if ( (loginstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,0)) != 0 )
{
loginjson = cJSON_Parse(loginstr);
free(loginstr);
loginstr = myinfo->decryptstr, myinfo->decryptstr = 0;
loginjson = cJSON_Parse(loginstr);
if ( loginstr != 0 )
free(loginstr);
}
retjson = iguana_payloadmerge(loginjson,importjson);
if ( importjson != 0 && importjson != retjson )

1
iguana/tests/activehandle

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"SuperNET\",\"method\":\"activehandle\"}"

1
iguana/tests/bitcoinrpc

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"SuperNET\",\"method\":\"bitcoinrpc\",\"setcoin\":\"$1\"}"

1
iguana/tests/encryptwallet

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"encryptwallet\",\"passphrase\":\"$1\"}"

1
iguana/tests/getaccountaddress

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"getaccountaddress\",\"account\":\"test\"}"

1
iguana/tests/getnewaddress

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"getnewaddress\",\"account\":\"test\"}"

1
iguana/tests/login

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"SuperNET\",\"method\":\"login\",\"passphrase\":\"$1\"}"

1
iguana/tests/walletpassphrase

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"walletpassphrase\",\"passphrase\":\"$1\",\"timeout\":$2}"
Loading…
Cancel
Save