From 8cb7b1ed31a7537f4d6a954836ab1a1c075208be Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Jan 2016 00:41:55 -0300 Subject: [PATCH] test --- .gitignore | 2 ++ crypto777/OS_portable.h | 5 +-- crypto777/OS_time.c | 32 ++++++++++++++++-- crypto777/iguana_utils.c | 9 +++++ deprecated/obsolete.h | 9 ++++- iguana/SuperNET.c | 40 +++++++++++++++++++++-- iguana/SuperNET.h | 4 +-- iguana/SuperNET_category.c | 4 +-- iguana/icon128.png | Bin 0 -> 10729 bytes iguana/iguana777.c | 2 +- iguana/iguana777.h | 18 ++++++---- iguana/iguana_chains.c | 39 ++++++++++++++++++---- iguana/iguana_init.c | 1 + iguana/iguana_json.c | 16 +++++---- iguana/iguana_pubkeys.c | 60 +++++++++++++++++++--------------- iguana/iguana_recv.c | 10 ++++-- iguana/iguana_rpc.c | 2 +- iguana/iguana_tx.c | 6 ++-- iguana/iguana_wallet.c | 10 +++--- iguana/main.c | 16 +++++++-- iguana/manifest.json | 2 +- iguana/pangea_api.c | 5 ++- iguana/pangea_json.c | 13 +++----- iguana/ramchain_api.c | 44 +++++++++++++++++++++++++ includes/iguana_apideclares.h | 9 +++-- 25 files changed, 270 insertions(+), 88 deletions(-) create mode 100644 iguana/icon128.png diff --git a/.gitignore b/.gitignore index 0e21f054a..b4382289d 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ iguana/pnacl/Release/iguana_unstripped.bc iguana/pnacl/Release/iguana_unstripped.bc---linked.pre_opt.pexe *.stamp + +*.d diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index c4af61254..9944c63a8 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -140,8 +140,9 @@ int32_t taidate_mjd(struct taidate cd); uint64_t tai2utime(struct tai t); struct tai taitime2tai(struct taitime ct); char *tai_str(char *str,struct tai t); -char *utc_str(char *str,struct tai t); +char *utc_str(char *str,uint32_t utc); double tai_diff(struct tai reftai,struct tai cmptai); +uint32_t OS_conv_utime(char *utime); //int32_t msync(void *addr,size_t len,int32_t flags); @@ -333,7 +334,7 @@ bits256 bits256_add(bits256 a,bits256 b); int32_t bits256_cmp(bits256 a,bits256 b); bits256 bits256_lshift(bits256 x); bits256 bits256_from_compact(uint32_t c); - +bits256 bits256_conv(char *hexstr); int32_t btc_priv2pub(uint8_t pubkey[33],uint8_t privkey[32]); extern char *Iguana_validcommands[]; diff --git a/crypto777/OS_time.c b/crypto777/OS_time.c index c685a38cd..8962fcbb1 100755 --- a/crypto777/OS_time.c +++ b/crypto777/OS_time.c @@ -17,6 +17,7 @@ #include "OS_portable.h" +#define DISABLE_LEAPS #define TAI_PACK 8 #define TAI_UTC_DIFF ((uint64_t)4611686018427387914ULL) @@ -152,7 +153,7 @@ struct taitime tai2time(struct tai t,int32_t *pwday,int32_t *pyday) // t.x = (t.millis / 1000.) + First_TAI.x; leap = leapsecs_sub(&t); u = t.x; - u += (58486 + 60); // was off by a minute + u += 58486; // was off by a minute (or 3?) s = u % 86400ULL; ct.second = (s % 60) + leap; s /= 60; ct.minute = s % 60; s /= 60; @@ -351,7 +352,9 @@ struct tai tai_now() if ( First_TAI.x == 0 ) { First_TAI = t, First_utc = (uint32_t)now; +#ifndef DISABLE_LEAPS UTC_ADJUST = -36; +#endif printf("TAINOW.%llu %03.3f UTC.%u vs %u [diff %d]\n",(long long)t.x,t.millis,First_utc,tai2utc(t),UTC_ADJUST); } return(t); @@ -359,6 +362,7 @@ struct tai tai_now() struct tai leapsecs_add(struct tai t,int32_t hit) { +#ifndef DISABLE_LEAPS int32_t i; uint64_t u; u = t.x; if ( t.x > leaptais[(sizeof(leaptais)/sizeof(*leaptais)) - 1].x ) @@ -374,6 +378,7 @@ struct tai leapsecs_add(struct tai t,int32_t hit) } } t.x = u; +#endif return(t); } @@ -421,6 +426,7 @@ struct tai taidate_scan(char *s,int32_t numleaps) int32_t leapsecs_sub(struct tai *lt) { +#ifndef DISABLE_LEAPS char out[101],x[TAI_PACK]; double packerr; int32_t weekday,yearday,i,j,s; uint64_t u; struct tai t,t2; struct taitime ct2; if ( leaptais[0].x == 0 ) @@ -468,6 +474,7 @@ int32_t leapsecs_sub(struct tai *lt) } lt->x = u - s; } +#endif return(0); } @@ -479,10 +486,20 @@ char *tai_str(char *str,struct tai t) return(str); } -char *utc_str(char *str,struct tai t) +/*char *utc_str(char *str,struct tai t) { t.x += UTC_ADJUST; return(tai_str(str,t)); +}*/ + +char *utc_str(char *str,uint32_t utc) +{ + struct taitime ct; struct tai t; + t = utc2tai(utc); + t.x += UTC_ADJUST; + ct = tai2time(t,0,0); + sprintf(str,"%d-%02d-%02dT%02d:%02d:%02dZ",ct.date.year,ct.date.month,ct.date.day,ct.hour,ct.minute,ct.second); + return(str); } double OS_milliseconds() @@ -512,7 +529,8 @@ uint64_t OS_conv_datenum(int32_t datenum,int32_t hour,int32_t minute,int32_t sec { ct = taitime_set(taidate_set(year,month,day),hour,minute,second); t = taitime2tai(ct); - return(tai2utime(t)+788250398LL - 4294967296LL); + //char str[65]; printf("conv.(y%d m%d d%d %d:%d:%d) %s\n",year,month,day,hour,minute,second,tai_str(str,t)); + return(tai2utc(t));//tai2utime(t)+788250398LL - 4294967296LL); } return(0); } @@ -571,6 +589,7 @@ int32_t conv_date(int32_t *secondsp,char *date) *secondsp = (3600*hour + 60*min + sec); else printf("ERROR: seconds.%d %d %d %d, len.%d\n",*secondsp,hour,min,sec,len); } + //printf("(%s) -> Y.%d M.%d D.%d %d:%d:%d\n",date,year,month,day,hour,min,sec); sprintf(origdate,"%d-%02d-%02d",year,month,day); //2015-07-25T22:34:31Z if ( strcmp(tmpdate,origdate) != 0 ) { @@ -580,6 +599,13 @@ int32_t conv_date(int32_t *secondsp,char *date) return((year * 10000) + (month * 100) + day); } +uint32_t OS_conv_utime(char *utime) +{ + int32_t datenum,seconds; + datenum = conv_date(&seconds,utime); + return((uint32_t)OS_conv_datenum(datenum,seconds/3600,(seconds%3600)/60,seconds%60)); +} + int32_t expand_datenum(char *date,int32_t datenum) { int32_t year,month,day; date[0] = 0; diff --git a/crypto777/iguana_utils.c b/crypto777/iguana_utils.c index 790754556..6fc646b7c 100755 --- a/crypto777/iguana_utils.c +++ b/crypto777/iguana_utils.c @@ -33,6 +33,15 @@ char *bits256_str(char hexstr[65],bits256 x) return(hexstr); } +bits256 bits256_conv(char *hexstr) +{ + bits256 x; + memset(&x,0,sizeof(x)); + if ( strlen(hexstr) == sizeof(x)*2) + decode_hex(x.bytes,sizeof(x.bytes),hexstr); + return(x); +} + char *bits256_lstr(char hexstr[65],bits256 x) { bits256 revx; int32_t i; diff --git a/deprecated/obsolete.h b/deprecated/obsolete.h index a823a9d53..42e0fa9c0 100644 --- a/deprecated/obsolete.h +++ b/deprecated/obsolete.h @@ -12837,5 +12837,12 @@ len = 0; if ( flag == 0 ) break; } - + uint8_t hex[1024]; char hashstr[65]; bits256 hash,hash2; long l = strlen("c0fbdbb600b7000000010000000000000000000000000000000000000000000000000000000000000000000058283b1b3ea5ad73f9aabc571dedd442d06e4ad8b3867a4f495acacd93a1698a54405408ffff1e0fb2780001010100004000085401540000000000000000000000000000000000000000000000000000000000000000ffffffff0424ffff1d000401541c7568202c2034655320703032343131203a323030303a20304d47ff54ffff01ff0000000000000000000000000000fb00b6c0afdb0000060000009900a46df6901a15d0d99d5dc9efda9b44582b1d3c83a60d119d64e7c7d7000a3300a678b550a606416b7a09510b2f3f89ee88971b7164c6f93fce76bb6d620b5f0c0880ff540fff001ede04010300010000805e54080001000000000000000000000000000000000000000000000000000000000000ff00ffff03ff0151ff02ffff01ff00005d8a45780163761914a96651e5e6e52dfa8d18cb0c673000dcae95f23923ac88000000000000"); + l>>=1; + decode_hex(hex,(int32_t)l,"c0fbdbb600b7000000010000000000000000000000000000000000000000000000000000000000000000000058283b1b3ea5ad73f9aabc571dedd442d06e4ad8b3867a4f495acacd93a1698a54405408ffff1e0fb2780001010100004000085401540000000000000000000000000000000000000000000000000000000000000000ffffffff0424ffff1d000401541c7568202c2034655320703032343131203a323030303a20304d47ff54ffff01ff0000000000000000000000000000fb00b6c0afdb0000060000009900a46df6901a15d0d99d5dc9efda9b44582b1d3c83a60d119d64e7c7d7000a3300a678b550a606416b7a09510b2f3f89ee88971b7164c6f93fce76bb6d620b5f0c0880ff540fff001ede04010300010000805e54080001000000000000000000000000000000000000000000000000000000000000ff00ffff03ff0151ff02ffff01ff00005d8a45780163761914a96651e5e6e52dfa8d18cb0c673000dcae95f23923ac88000000000000"); + vcalc_sha256(0,hash.bytes,hex+24,(int32_t)l-24); + vcalc_sha256(hashstr,hash2.bytes,hash.bytes,sizeof(hash)); + printf("ghash.(%s)\n",hashstr); + + getchar(); #endif diff --git a/iguana/SuperNET.c b/iguana/SuperNET.c index 994563896..725d483c0 100644 --- a/iguana/SuperNET.c +++ b/iguana/SuperNET.c @@ -1003,17 +1003,24 @@ THREE_STRINGS(SuperNET,rosetta,passphrase,pin,showprivkey) if ( btc_coinaddr(addr,0,str) == 0 ) { jaddstr(retjson,"BTC",addr); - btc_priv2wip(wifbuf,privkey.bytes,0x80); + btc_priv2wif(wifbuf,privkey.bytes,0x80); if ( flag != 0 ) jaddstr(retjson,"BTCwif",wifbuf); } if ( btc_coinaddr(addr,60,str) == 0 ) { jaddstr(retjson,"BTCD",addr); - btc_priv2wip(wifbuf,privkey.bytes,0xbc); + btc_priv2wif(wifbuf,privkey.bytes,0xbc); if ( flag != 0 ) jaddstr(retjson,"BTCDwif",wifbuf); } + if ( btc_coinaddr(addr,5,str) == 0 ) + { + jaddstr(retjson,"VPN",addr); + btc_priv2wif(wifbuf,privkey.bytes,0xbc); + if ( flag != 0 ) + jaddstr(retjson,"VPNwif",wifbuf); + } if ( flag != 0 ) jaddbits256(retjson,"privkey",privkey); check = SuperNET_pindecipher(IGUANA_CALLARGS,pin,privcipher); @@ -1177,4 +1184,33 @@ THREE_STRINGS(SuperNET,survey,category,subcategory,message) categoryhash = calc_categoryhashes(&subhash,category,subcategory); return(SuperNET_categorymulticast(myinfo,1,categoryhash,subhash,message,juint(json,"maxdelay"),juint(json,"broadcast"),juint(json,"plaintext"))); } + +STRING_ARG(SuperNET,wif2priv,wif) +{ + bits256 privkey; char str[65]; uint8_t privkeytype; cJSON *retjson = cJSON_CreateObject(); + if ( btc_wif2priv(&privkeytype,privkey.bytes,wif) == sizeof(privkey) ) + { + jaddstr(retjson,"result","success"); + jaddstr(retjson,"privkey",bits256_str(str,privkey)); + jaddnum(retjson,"type",privkeytype); + } else jaddstr(retjson,"error","couldnt convert wif"); + return(jprint(retjson,1)); +} + +STRING_ARG(SuperNET,utime2utc,utime) +{ + uint32_t utc = 0; cJSON *retjson = cJSON_CreateObject(); + utc = OS_conv_utime(utime); + char str[65]; printf("utime.%s -> %u -> %s\n",utime,utc,utc_str(str,utc)); + jaddnum(retjson,"result",utc); + return(jprint(retjson,1)); +} + +INT_ARG(SuperNET,utc2utime,utc) +{ + char str[65]; cJSON *retjson = cJSON_CreateObject(); + jaddstr(retjson,"result",utc_str(str,utc)); + return(jprint(retjson,1)); +} + #include "../includes/iguana_apiundefs.h" diff --git a/iguana/SuperNET.h b/iguana/SuperNET.h index d9bf8b2ad..a9cd5c43e 100644 --- a/iguana/SuperNET.h +++ b/iguana/SuperNET.h @@ -99,8 +99,8 @@ struct category_info UT_hash_handle hh; queue_t Q; int32_t (*process_func)(struct supernet_info *myinfo,void *data,int32_t datalen,char *remoteaddr); int32_t (*blockhash_func)(void *blockhashp,void *data,int32_t datalen); // returns len of blockhash - uint64_t (*hit_func)(struct supernet_info *myinfo,void *categoryinfo,void *subinfo,bits256 addr); - int32_t (*ishwm_func)(struct supernet_info *myinfo,void *categoryinfo,void *subinfo,bits256 blockhash,int32_t heighthint,uint64_t hwmwt,uint64_t prevwt,uint64_t hit); + uint64_t (*hit_func)(struct supernet_info *myinfo,void *categoryinfo,void *subinfo,void *addr,int32_t addrlen); + int32_t (*ishwm_func)(struct supernet_info *myinfo,void *categoryinfo,void *subinfo,void *blockhashp,int32_t hashlen,int32_t heighthint,uint64_t hwmwt,uint64_t prevwt,uint64_t hit); bits256 hash; void *info; struct category_info *sub; }; extern struct category_info *Categories; diff --git a/iguana/SuperNET_category.c b/iguana/SuperNET_category.c index ff409af9f..0ada22550 100644 --- a/iguana/SuperNET_category.c +++ b/iguana/SuperNET_category.c @@ -96,7 +96,7 @@ struct category_info *category_blockhashfunc(bits256 categoryhash,bits256 subhas return(0); } -struct category_info *category_hitfunc(bits256 categoryhash,bits256 subhash,uint64_t (*hit_func)(struct supernet_info *myinfo,void *categoryinfo,void *subinfo,bits256 addr)) +struct category_info *category_hitfunc(bits256 categoryhash,bits256 subhash,uint64_t (*hit_func)(struct supernet_info *myinfo,void *categoryinfo,void *subinfo,void *addr,int32_t addrlen)) { struct category_info *cat; if ( (cat= category_find(categoryhash,subhash)) != 0 ) @@ -107,7 +107,7 @@ struct category_info *category_hitfunc(bits256 categoryhash,bits256 subhash,uint return(0); } -struct category_info *category_ishwmfunc(bits256 categoryhash,bits256 subhash,int32_t (*ishwm_func)(struct supernet_info *myinfo,void *categoryinfo,void *subinfo,bits256 blockhash,int32_t heighthint,uint64_t hwmwt,uint64_t prevwt,uint64_t hit)) +struct category_info *category_ishwmfunc(bits256 categoryhash,bits256 subhash,int32_t (*ishwm_func)(struct supernet_info *myinfo,void *categoryinfo,void *subinfo,void *blockhashp,int32_t hashlen,int32_t heighthint,uint64_t hwmwt,uint64_t prevwt,uint64_t hit)) { struct category_info *cat; if ( (cat= category_find(categoryhash,subhash)) != 0 ) diff --git a/iguana/icon128.png b/iguana/icon128.png new file mode 100644 index 0000000000000000000000000000000000000000..a10c52a5de62c2308265cb1e99d8ece921840bfd GIT binary patch literal 10729 zcma)Cg;$f`|EDD;3>cll1f)bnKsq)`Y6u7jNFz#jgLJ2KNtb|t(%n5moCrvalo;Ld zeLjD|?{{{#ojqsgIrl#I{eIQGk(%m?4~glCv9PcnDl5UXfbYQn-h>3eXRnm$DDZ{t zqNON@RXxGD4g4T5d!-1&di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&2=tAVWVICh|L-9dW5t|#6;;E-}eSn3z2!Rh`tjw!vi9%-NRMa1&s7&mqm^+6ZO z&iS3YYm6Ue>DGg?z2yAEQ=j#eH^%tJ1l*J-FQiQCLfOHxS62D0f zV$523_lH=f&8hasheaders = hasheaders; @@ -145,11 +170,11 @@ struct iguana_chain *iguana_createchain(cJSON *json) if ( (name= jstr(json,"description")) != 0 && strlen(name) < 32 ) strcpy(chain->name,name); if ( (hexstr= jstr(json,"pubval")) != 0 && strlen(hexstr) == 2 ) - decode_hex((uint8_t *)&chain->pubval,1,hexstr); + decode_hex((uint8_t *)&chain->pubtype,1,hexstr); if ( (hexstr= jstr(json,"scriptval")) != 0 && strlen(hexstr) == 2 ) - decode_hex((uint8_t *)&chain->p2shval,1,hexstr); - if ( (hexstr= jstr(json,"wipval")) != 0 && strlen(hexstr) == 2 ) - decode_hex((uint8_t *)&chain->wipval,1,hexstr); + decode_hex((uint8_t *)&chain->p2shtype,1,hexstr); + if ( (hexstr= jstr(json,"wiftype")) != 0 && strlen(hexstr) == 2 ) + decode_hex((uint8_t *)&chain->wiftype,1,hexstr); if ( (hexstr= jstr(json,"netmagic")) != 0 && strlen(hexstr) == 8 ) decode_hex((uint8_t *)chain->netmagic,1,hexstr); if ( (hexstr= jstr(json,"unitval")) != 0 && strlen(hexstr) == 2 ) diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index ff9ee214e..ab04f98f2 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -90,6 +90,7 @@ bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain) printf("genesis.(%s) len.%d hash.%s\n",chain->genesis_hex,(int32_t)sizeof(msg.H),str); iguana_blockconv(&block,&msg,hash2,0); //coin->latest.dep.numtxids = + block.RO.txn_count = 1; block.RO.numvouts = 1; iguana_gotdata(coin,0,0); if ( (ptr= iguana_blockhashset(coin,0,hash2,1)) != 0 ) diff --git a/iguana/iguana_json.c b/iguana/iguana_json.c index 752742eb0..617b31d5b 100755 --- a/iguana/iguana_json.c +++ b/iguana/iguana_json.c @@ -480,15 +480,19 @@ STRING_ARG(iguana,getconnectioncount,activecoin) } else return(clonestr("{\"error\":\"getconnectioncount needs coin\"}")); } -STRING_ARG(iguana,addcoin,activecoin) +STRING_ARG(iguana,addcoin,newcoin) { char *symbol; int32_t retval; - if ( (symbol= activecoin) == 0 && coin != 0 ) + if ( (symbol= newcoin) == 0 && coin != 0 ) symbol = coin->symbol; if ( symbol != 0 ) { if ( (retval= iguana_launchcoin(symbol,json)) > 0 ) + { + if ( myinfo->rpcsymbol[0] == 0 ) + safecopy(myinfo->rpcsymbol,symbol,sizeof(myinfo->rpcsymbol)); return(clonestr("{\"result\":\"coin added\"}")); + } else if ( retval == 0 ) return(clonestr("{\"result\":\"coin already there\"}")); else return(clonestr("{\"error\":\"error adding coin\"}")); @@ -680,7 +684,7 @@ TWO_STRINGS(hmac,whirlpool,message,passphrase) { return(hmac_dispatch(hmac_whirl STRING_ARG(SuperNET,bitcoinrpc,setcoin) { - if ( coin != 0 && setcoin != 0 && setcoin[0] != 0 ) + if ( setcoin != 0 && setcoin[0] != 0 ) { strcpy(myinfo->rpcsymbol,setcoin); touppercase(myinfo->rpcsymbol); @@ -724,9 +728,9 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSO char *coinstr; struct iguana_info *coin = 0; if ( remoteaddr != 0 && (remoteaddr[0] == 0 || strcmp(remoteaddr,"127.0.0.1") == 0) ) remoteaddr = 0; - if ( (coinstr= jstr(json,"activecoin")) != 0 ) - coin = iguana_coinfind(coinstr); - if ( coin == 0 && (coinstr= jstr(json,"coin")) != 0 ) + if ( (coinstr= jstr(json,"activecoin")) == 0 && (coinstr= jstr(json,"coin")) == 0 ) + coinstr = myinfo->rpcsymbol; + if ( coinstr != 0 && coinstr[0] != 0 ) coin = iguana_coinfind(coinstr); if ( strcmp(agent,"ramchain") == 0 && coin == 0 ) return(clonestr("{\"error\":\"ramchain needs coin\"}")); diff --git a/iguana/iguana_pubkeys.c b/iguana/iguana_pubkeys.c index 07afb5c69..0898eb01a 100755 --- a/iguana/iguana_pubkeys.c +++ b/iguana/iguana_pubkeys.c @@ -333,7 +333,7 @@ cstring *base58_decode_check(uint8_t *addrtype,const char *s_in) // validate with trailing hash, then remove hash hash = bits256_doublesha256(0,(uint8_t *)s->str,(int32_t)s->len - 4); //bu_Hash4(md32,s->str,s->len - 4); - if ( memcmp(hash.bytes,&s->str[s->len - 4],4) == 0 ) + if ( (s->str[s->len - 4]&0xff) == hash.bytes[31] && (s->str[s->len - 3]&0xff) == hash.bytes[30] &&(s->str[s->len - 2]&0xff) == hash.bytes[29] &&(s->str[s->len - 1]&0xff) == hash.bytes[28] ) { cstr_resize(s,s->len - 4); if ( addrtype ) // if addrtype requested, remove from front of data string @@ -343,6 +343,10 @@ cstring *base58_decode_check(uint8_t *addrtype,const char *s_in) } return(s); } + else + { + char str[65]; printf("checkhash mismatch %02x %02x %02x %02x vs %02x %02x %02x %02x (%s)\n",s->str[s->len - 4]&0xff,s->str[s->len - 3]&0xff,s->str[s->len - 2]&0xff,s->str[s->len - 1]&0xff,hash.bytes[31],hash.bytes[30],hash.bytes[29],hash.bytes[28],bits256_str(str,hash)); + } } cstr_free(s,true); } @@ -633,7 +637,7 @@ int32_t btc_addr2univ(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr) return(-1); } -int32_t btc_priv2wip(char *wipstr,uint8_t privkey[32],uint8_t addrtype) +int32_t btc_priv2wif(char *wifstr,uint8_t privkey[32],uint8_t addrtype) { uint8_t tmp[128]; char hexstr[67]; cstring *btc_addr; memcpy(tmp,privkey,32); @@ -641,17 +645,17 @@ int32_t btc_priv2wip(char *wipstr,uint8_t privkey[32],uint8_t addrtype) init_hexbytes_noT(hexstr,tmp,32); if ( (btc_addr= base58_encode_check(addrtype,true,tmp,33)) != 0 ) { - strcpy(wipstr,btc_addr->str); + strcpy(wifstr,btc_addr->str); cstr_free(btc_addr,true); } - printf("-> (%s) -> wip.(%s) addrtype.%02x\n",hexstr,wipstr,addrtype); + printf("-> (%s) -> wif.(%s) addrtype.%02x\n",hexstr,wifstr,addrtype); return(0); } -int32_t btc_wip2priv(uint8_t privkey[32],char *wipstr) +int32_t btc_wif2priv(uint8_t *addrtypep,uint8_t privkey[32],char *wifstr) { - uint8_t addrtype; cstring *cstr; int32_t len = -1; - if ( (cstr= base58_decode_check(&addrtype,(const char *)wipstr)) != 0 ) + cstring *cstr; int32_t len = -1; + if ( (cstr= base58_decode_check(addrtypep,(const char *)wifstr)) != 0 ) { init_hexbytes_noT((void *)privkey,(void *)cstr->str,cstr->len); if ( cstr->str[cstr->len-1] == 0x01 ) @@ -659,17 +663,17 @@ int32_t btc_wip2priv(uint8_t privkey[32],char *wipstr) memcpy(privkey,cstr->str,cstr->len); len = (int32_t)cstr->len; char tmp[138]; - btc_priv2wip(tmp,privkey,addrtype); - printf("addrtype.%02x wipstr.(%llx) len.%d\n",addrtype,*(long long *)privkey,len); + btc_priv2wif(tmp,privkey,*addrtypep); + printf("addrtype.%02x wifstr.(%llx) len.%d\n",*addrtypep,*(long long *)privkey,len); cstr_free(cstr,true); } return(len); } -int32_t btc_setprivkey(struct bp_key *key,char *wipstr) +int32_t btc_setprivkey(struct bp_key *key,char *wifstr) { - uint8_t privkey[512]; int32_t len; - len = btc_wip2priv(privkey,wipstr); + uint8_t privkey[512],privkeytype; int32_t len; + len = btc_wif2priv(&privkeytype,privkey,wifstr); if ( len < 0 || bp_key_init(key) == 0 || bp_key_secret_set(key,privkey,len) == 0 ) { printf("error setting privkey\n"); @@ -789,6 +793,19 @@ int32_t btc_pub65toaddr(char *coinaddr,uint8_t addrtype,char pubkey[131],uint8_t return(retval); } +struct iguana_waddress *iguana_waddresscalc(uint8_t pubtype,uint8_t wiftype,struct iguana_waddress *addr,bits256 privkey) +{ + memset(addr,0,sizeof(*addr)); + addr->privkey = privkey; + if ( btc_priv2pub(addr->pubkey,addr->privkey.bytes) == 0 && btc_priv2wif(addr->wifstr,addr->privkey.bytes,wiftype) == 0 && btc_pub2rmd(addr->rmd160,addr->pubkey) == 0 && btc_convrmd160(addr->coinaddr,pubtype,addr->rmd160) == 0 ) + { + addr->wiftype = wiftype; + addr->type = pubtype; + return(addr); + } + return(0); +} + /*char *iguana_txsign(struct iguana_info *coin,struct cointx_info *refT,int32_t redeemi,char *redeemscript,char sigs[][256],int32_t n,uint8_t privkey[32],int32_t privkeyind) { char hexstr[16384]; bits256 hash2; uint8_t data[4096],sigbuf[512]; struct bp_key key; @@ -965,8 +982,8 @@ int32_t iguana_scriptgen(struct iguana_info *coin,uint8_t *script,char *asmstr,s { char coinaddr[65]; uint8_t addrtype; int32_t scriptlen = 0; if ( type == IGUANA_SCRIPT_7688AC || type == IGUANA_SCRIPT_76AC ) - addrtype = coin->chain->pubval; - else addrtype = coin->chain->p2shval; + addrtype = coin->chain->pubtype; + else addrtype = coin->chain->p2shtype; btc_convrmd160(coinaddr,addrtype,p->rmd160); switch ( type ) { @@ -1107,18 +1124,7 @@ if ( bp_key_init(&key) != 0 && bp_key_secret_set(&key,privkey,32) != 0 ) return(clonestr(hexstr)); } */ -struct iguana_waddress *iguana_waddresscalc(struct iguana_info *coin,struct iguana_waddress *addr,bits256 privkey) -{ - memset(addr,0,sizeof(*addr)); - addr->privkey = privkey; - if ( btc_priv2pub(addr->pubkey,addr->privkey.bytes) == 0 && btc_priv2wip(addr->wipstr,addr->privkey.bytes,coin->chain->wipval) == 0 && btc_pub2rmd(addr->rmd160,addr->pubkey) == 0 && btc_convrmd160(addr->coinaddr,coin->chain->pubval,addr->rmd160) == 0 ) - { - addr->wiptype = coin->chain->wipval; - addr->type = coin->chain->pubval; - return(addr); - } - return(0); -} + /*static char *validateretstr(struct iguana_info *coin,char *coinaddr) { @@ -1149,7 +1155,7 @@ static char *validatepubkey(RPCARGS) char *makekeypair(struct iguana_info *coin) { struct iguana_waddress addr; char str[67]; cJSON *retjson = cJSON_CreateObject(); - if ( iguana_waddresscalc(coin,&addr,rand256(1)) == 0 ) + if ( iguana_waddresscalc(coin->chain->pubtype,coin->chain->wiftype,&addr,rand256(1)) == 0 ) { init_hexbytes_noT(str,addr.pubkey,33); jaddstr(retjson,"result",str); diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 6d90ef280..79b3a00f9 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -53,7 +53,7 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr, coin->numreqsent++; addr->pendblocks++; addr->pendtime = (uint32_t)time(NULL); - // printf("REQ.%s bundlei.%d hdrsi.%d\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1); + printf("REQ.%s bundlei.%d hdrsi.%d\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1); } else printf("MSG_BLOCK null datalen.%d\n",len); return(len); } @@ -149,6 +149,12 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i //printf("copy %p serialized[%d]\n",req->serialized,req->recvlen); memcpy(req->serialized,data,recvlen), req->copyflag = 1; } + if ( bits256_cmp(origtxdata->block.RO.hash2,coin->APIblockhash) == 0 ) + { + printf("MATCHED APIblockhash\n"); + coin->APIblockstr = calloc(1,recvlen*2+1); + init_hexbytes_noT(coin->APIblockstr,data,recvlen); + } txdata = origtxdata; if ( addr != 0 ) { @@ -722,7 +728,7 @@ int32_t iguana_blockQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t block = iguana_blockfind(coin,hash2); if ( priority != 0 || block == 0 || (block->queued == 0 && block->fpipbits == 0) ) { - if ( block != 0 ) + if ( block != 0 && bits256_cmp(coin->APIblockhash,hash2) != 0 ) { if ( block->fpipbits != 0 || block->queued != 0 || block->issued > time(NULL)-10 ) return(0); diff --git a/iguana/iguana_rpc.c b/iguana/iguana_rpc.c index cde615438..b3cf977a8 100755 --- a/iguana/iguana_rpc.c +++ b/iguana/iguana_rpc.c @@ -320,7 +320,7 @@ static char *dumpprivkey(RPCARGS) static char *importprivkey(RPCARGS) { - return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","importprivkey","wip",params[0])); + return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","importprivkey","wif",params[0])); } static char *dumpwallet(RPCARGS) diff --git a/iguana/iguana_tx.c b/iguana/iguana_tx.c index 15367377f..3d6b096b6 100755 --- a/iguana/iguana_tx.c +++ b/iguana/iguana_tx.c @@ -27,8 +27,8 @@ cJSON *iguana_voutjson(struct iguana_info *coin,struct iguana_msgvout *vout,char if ( vout->pk_script != 0 && vout->pk_scriptlen*2+1 < sizeof(scriptstr) ) { if ( iguana_calcrmd160(coin,rmd160,msigs160,&M,&N,vout->pk_script,vout->pk_scriptlen,zero) > 0 ) - addrtype = coin->chain->p2shval; - else addrtype = coin->chain->pubval; + addrtype = coin->chain->p2shtype; + else addrtype = coin->chain->pubtype; btc_convrmd160(coinaddr,addrtype,rmd160); jaddstr(json,"address",coinaddr); init_hexbytes_noT(scriptstr,vout->pk_script,vout->pk_scriptlen); @@ -40,7 +40,7 @@ cJSON *iguana_voutjson(struct iguana_info *coin,struct iguana_msgvout *vout,char addrs = cJSON_CreateArray(); for (i=0; ichain->pubval,msigs160[i]); + btc_convrmd160(coinaddr,coin->chain->pubtype,msigs160[i]); jaddistr(addrs,coinaddr); } jadd(json,"addrs",addrs); diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index 5b2f2b508..9c38e1fd9 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -62,13 +62,13 @@ int32_t iguana_addressvalidate(struct iguana_info *coin,char *coinaddr) char *getnewaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *account) { struct iguana_waddress addr; char str[67]; cJSON *retjson = cJSON_CreateObject(); - if ( iguana_waddresscalc(coin,&addr,rand256(1)) == 0 ) + if ( iguana_waddresscalc(coin->chain->pubtype,coin->chain->wiftype,&addr,rand256(1)) == 0 ) { jaddstr(retjson,"result",addr.coinaddr); init_hexbytes_noT(str,addr.pubkey,33); jaddstr(retjson,"pubkey",str); jaddstr(retjson,"privkey",bits256_str(str,addr.privkey)); - jaddstr(retjson,"wip",addr.wipstr); + jaddstr(retjson,"wif",addr.wifstr); init_hexbytes_noT(str,addr.rmd160,20); jaddstr(retjson,"rmd160",str); if ( iguana_waccountadd(coin,account,&addr) < 0 ) @@ -85,7 +85,7 @@ char *getaccountaddress(struct supernet_info *myinfo,struct iguana_info *coin,ch { if ( (wacct= iguana_waccountfind(coin,account)) == 0 ) { - if ( (waddr= iguana_waddresscalc(coin,&addr,rand256(1))) == 0 ) + if ( (waddr= iguana_waddresscalc(coin->chain->pubtype,coin->chain->wiftype,&addr,rand256(1))) == 0 ) return(clonestr("{\"error\":\"cant generate address\"}")); iguana_waccountswitch(coin,account,0,-1,addr.coinaddr); } @@ -94,7 +94,7 @@ char *getaccountaddress(struct supernet_info *myinfo,struct iguana_info *coin,ch init_hexbytes_noT(str,addr.pubkey,33); jaddstr(retjson,"pubkey",str); jaddstr(retjson,"privkey",bits256_str(str,waddr->privkey)); - jaddstr(retjson,"wip",waddr->wipstr); + jaddstr(retjson,"wif",waddr->wifstr); init_hexbytes_noT(str,waddr->rmd160,20); jaddstr(retjson,"rmd160",str); jaddstr(retjson,"account",account); @@ -112,7 +112,7 @@ char *setaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *acc return(clonestr("{\"error\":\"invalid coin address\"}")); if ( (wacct= iguana_waddressfind(coin,&ind,coinaddr)) == 0 ) { - if ( (waddr= iguana_waddresscalc(coin,&addr,rand256(1))) == 0 ) + if ( (waddr= iguana_waddresscalc(coin->chain->pubtype,coin->chain->wiftype,&addr,rand256(1))) == 0 ) return(clonestr("{\"error\":\"cant generate address\"}")); } iguana_waccountswitch(coin,account,wacct,ind,coinaddr); diff --git a/iguana/main.c b/iguana/main.c index 346985eca..f02cbe158 100644 --- a/iguana/main.c +++ b/iguana/main.c @@ -283,6 +283,18 @@ void iguana_main(void *arg) struct supernet_info *myinfo; int32_t i,len,flag,c; bits256 acct,seed,checkhash,wallethash,walletpub,wallet2shared,wallet2priv,wallet2pub; myinfo = SuperNET_MYINFO(0); + char str[65]; uint32_t t,s; + t = 1409839200;//(uint32_t)time(NULL); + for (i=0; i<1; i++) + { + utc_str(str,t-i); + s = OS_conv_utime(str); + //if ( s != t-i ) + printf("t.%u -> %s -> %u diff.[%d]\n",t-i,str,s,(t-i) - s); + } + iguana_chaingenesis(1,1403138561,0x1e0fffff,8359109,bits256_conv("fd1751cc6963d88feca94c0d01da8883852647a37a0a67ce254d62dd8c9d5b2b")); + iguana_chaingenesis(1,1409832000,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); + mycalloc(0,0,0); iguana_initQ(&helperQ,"helperQ"); OS_ensure_directory("confs"); @@ -417,7 +429,7 @@ void iguana_main(void *arg) vcalc_sha256(0,acct.bytes,(void *)myinfo->myaddr.persistent.bytes,sizeof(bits256)); myinfo->myaddr.nxt64bits = acct.txid; RS_encode(myinfo->myaddr.NXTADDR,myinfo->myaddr.nxt64bits); - char str[65],str2[65]; printf("%s %llu %p PRIV.%s PUB.%s persistent.%llx %llx\n",myinfo->myaddr.NXTADDR,(long long)myinfo->myaddr.nxt64bits,&myinfo->privkey,bits256_str(str,myinfo->privkey),bits256_str(str2,myinfo->myaddr.pubkey),(long long)myinfo->persistent_priv.txid,(long long)myinfo->myaddr.persistent.txid); + char str2[65]; printf("%s %llu %p PRIV.%s PUB.%s persistent.%llx %llx\n",myinfo->myaddr.NXTADDR,(long long)myinfo->myaddr.nxt64bits,&myinfo->privkey,bits256_str(str,myinfo->privkey),bits256_str(str2,myinfo->myaddr.pubkey),(long long)myinfo->persistent_priv.txid,(long long)myinfo->myaddr.persistent.txid); if ( confstr == 0 ) { uint8_t *compressed,*serialized; int32_t complen,maxsize = IGUANA_MAXPACKETSIZE; @@ -487,7 +499,7 @@ void iguana_main(void *arg) #ifdef __APPLE__ sleep(1); char *str; - if ( (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"wallet\":\"password\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":1,\"activecoin\":\"BTCD\",\"active\":0}"),0)) != 0 ) + if ( (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"wallet\":\"password\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":16,\"newcoin\":\"VPN\",\"active\":1}"),0)) != 0 ) { printf("got.(%s)\n",str); free(str); diff --git a/iguana/manifest.json b/iguana/manifest.json index 2c5cf921f..e620e6ff9 100755 --- a/iguana/manifest.json +++ b/iguana/manifest.json @@ -12,6 +12,6 @@ "name": "iguana", "background": { "scripts": ["background.js"] }, "sockets": { "tcp": { "connect": "" }, "tcpServer": { "listen": "127.0.0.1:*" } }, - "permissions": [ "unlimitedStorage", "filesystem", "storage", "system.storage", "system.display", "system.network","system.cpu" ] + "permissions": [ "unlimitedStorage", "storage", "system.storage", "system.display", "system.network","system.cpu" ] } } diff --git a/iguana/pangea_api.c b/iguana/pangea_api.c index 02389c4ba..8f26a5337 100755 --- a/iguana/pangea_api.c +++ b/iguana/pangea_api.c @@ -314,11 +314,10 @@ void pangea_addfunds(PANGEA_HANDARGS) void pangea_tablejoin(struct supernet_info *myinfo,struct table_info *tp,uint8_t *data,int32_t datalen,uint64_t signer64bits,uint32_t sigtimestamp,bits256 sigtablehash) { - char str[65],str2[65],space[4096]; struct tai t; int32_t i,seconds; cJSON *json; + char str[65],str2[65],space[4096]; int32_t i; cJSON *json; if ( tp->G.started != 0 ) { - OS_conv_unixtime(&t,&seconds,tp->G.finished == 0 ? tp->G.started : tp->G.finished); - printf("table.(%s) already %s %s\n",bits256_str(str,tp->G.tablehash),tp->G.finished == 0 ? "started" : "finished",utc_str(str2,t)); + printf("table.(%s) already %s %s\n",bits256_str(str,tp->G.tablehash),tp->G.finished == 0 ? "started" : "finished",utc_str(str2,tp->G.finished == 0 ? tp->G.started : tp->G.finished)); } else if ( tp->G.numactive >= tp->G.maxplayers ) { diff --git a/iguana/pangea_json.c b/iguana/pangea_json.c index 7dc7cc76d..42aff73b7 100755 --- a/iguana/pangea_json.c +++ b/iguana/pangea_json.c @@ -27,7 +27,7 @@ cJSON *pangea_playerjson(struct supernet_info *myinfo,struct table_info *tp,stru cJSON *pangea_tablejson(struct supernet_info *myinfo,struct table_info *tp) { - char ipaddr[64],str[64]; struct tai t; int32_t i,seconds; cJSON *array,*json; struct game_info *gp; + char ipaddr[64],str[64]; int32_t i; cJSON *array,*json; struct game_info *gp; gp = &tp->G; json = cJSON_CreateObject(); jaddbits256(json,"tablehash",gp->tablehash); @@ -48,17 +48,12 @@ cJSON *pangea_tablejson(struct supernet_info *myinfo,struct table_info *tp) jaddnum(json,"ante",dstr(gp->ante)); if ( gp->opentime != 0 ) { - OS_conv_unixtime(&t,&seconds,gp->opentime); - jaddstr(json,"opentime",utc_str(str,t)); + jaddstr(json,"opentime",utc_str(str,gp->opentime)); if ( gp->started != 0 ) { - OS_conv_unixtime(&t,&seconds,gp->started); - jaddstr(json,"started",utc_str(str,t)); + jaddstr(json,"started",utc_str(str,gp->started)); if ( gp->finished != 0 ) - { - OS_conv_unixtime(&t,&seconds,gp->finished); - jaddstr(json,"finished",utc_str(str,t)); - } + jaddstr(json,"finished",utc_str(str,gp->finished)); } } if ( tp->G.numactive > 0 ) diff --git a/iguana/ramchain_api.c b/iguana/ramchain_api.c index 9f2a2abac..edae00300 100755 --- a/iguana/ramchain_api.c +++ b/iguana/ramchain_api.c @@ -16,6 +16,50 @@ #include "iguana777.h" #include "../includes/iguana_apidefs.h" +HASH_AND_INT(ramchain,getblock,blockhash,localonly) +{ + int32_t i,len; char hexstr[(sizeof(uint32_t)+sizeof(struct iguana_msgblock))*2+1]; + uint8_t serialized[sizeof(uint32_t)+sizeof(struct iguana_msgblock)]; bits256 hash2; + struct iguana_msgblock msg; struct iguana_block *block; + cJSON *retjson = cJSON_CreateObject(); + memset(&msg,0,sizeof(msg)); + if ( localonly == 0 && (block= iguana_blockfind(coin,blockhash)) != 0 ) + { + msg.H.version = block->RO.version; + msg.H.merkle_root = block->RO.merkle_root; + msg.H.timestamp = block->RO.timestamp; + msg.H.bits = block->RO.bits; + msg.H.nonce = block->RO.nonce; + msg.txn_count = block->RO.txn_count; + len = iguana_rwblock(1,&hash2,serialized,&msg); + char str[65]; printf("timestamp.%u bits.%u nonce.%u v.%d (%s) len.%d (%ld %ld)\n",block->RO.timestamp,block->RO.bits,block->RO.nonce,block->RO.version,bits256_str(str,hash2),len,sizeof(serialized),sizeof(hexstr)); + init_hexbytes_noT(hexstr,serialized,len); + jaddstr(retjson,"result",hexstr); + } + else if ( coin->APIblockstr != 0 ) + jaddstr(retjson,"error","already have pending request"); + else + { + coin->APIblockhash = blockhash; + iguana_blockQ(coin,0,-1,blockhash,1); + for (i=0; i<10; i++) + { + if ( coin->APIblockstr != 0 ) + { + jaddstr(retjson,"result",coin->APIblockstr); + free(coin->APIblockstr); + memset(&coin->APIblockhash,0,sizeof(coin->APIblockhash)); + coin->APIblockstr = 0; + break; + } + sleep(1); + } + if ( i == 10 ) + jaddstr(retjson,"error","cant find blockhash"); + } + return(jprint(retjson,1)); +} + ZERO_ARGS(ramchain,getinfo) { cJSON *retjson = cJSON_CreateObject(); diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 11682fd23..84b15ad2f 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -13,6 +13,9 @@ * * ******************************************************************************/ +STRING_ARG(SuperNET,bitcoinrpc,setcoin); +HASH_AND_INT(ramchain,getblock,blockhash,localonly); + /*HASH_AND_ARRAY(pangea,userturn,tablehash,params); HASH_AND_ARRAY(pangea,status,tableid,params); HASH_AND_ARRAY(pangea,mode,tableid,params); @@ -24,7 +27,8 @@ HASH_AND_STRING(pangea,join,tablehash,handle); HASH_AND_ARRAY(pangea,start,tablehash,params); ZERO_ARGS(SuperNET,help); -STRING_ARG(SuperNET,bitcoinrpc,setcoin); +STRING_ARG(SuperNET,utime2utc,utime); +INT_ARG(SuperNET,utc2utime,utc); TWO_STRINGS(SuperNET,html,agentform,htmlfile); TWOSTRINGS_AND_TWOHASHES_AND_TWOINTS(SuperNET,DHT,hexmsg,destip,categoryhash,subhash,maxdelay,broadcast); @@ -32,6 +36,7 @@ TWOSTRINGS_AND_TWOHASHES_AND_TWOINTS(SuperNET,DHT,hexmsg,destip,categoryhash,sub THREE_STRINGS(SuperNET,rosetta,passphrase,pin,showprivkey); ZERO_ARGS(SuperNET,keypair); HASH_ARG(SuperNET,priv2pub,privkey); +STRING_ARG(SuperNET,wif2priv,wif); TWOHASHES_AND_STRING(SuperNET,cipher,privkey,destpubkey,message); TWOHASHES_AND_STRING(SuperNET,decipher,privkey,srcpubkey,cipherstr); @@ -65,7 +70,7 @@ HASH_ARRAY_STRING(SuperNET,layer,mypriv,otherpubs,str); STRING_ARG(iguana,peers,activecoin); STRING_AND_INT(iguana,maxpeers,activecoin,max); STRING_ARG(iguana,getconnectioncount,activecoin); -STRING_ARG(iguana,addcoin,activecoin); +STRING_ARG(iguana,addcoin,newcoin); STRING_ARG(iguana,startcoin,activecoin); STRING_ARG(iguana,pausecoin,activecoin); TWO_STRINGS(iguana,addnode,activecoin,ipaddr);