diff --git a/OSlibs/win/mingw.h b/OSlibs/win/mingw.h index 2c35aa78c..5690d6f91 100755 --- a/OSlibs/win/mingw.h +++ b/OSlibs/win/mingw.h @@ -5,8 +5,8 @@ #include #define _USE_W32_SOCKETS 1 -#define WIN32_LEAN_AND_MEAN -#include +//#define WIN32_LEAN_AND_MEAN +//#include #include #define PTW32_STATIC_LIB #include "pthread.h" diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index 4d15df781..be78a05e2 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -584,7 +584,12 @@ char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coi *completedp = 0; if ( signedtxidp != 0 ) memset(signedtxidp,0,sizeof(*signedtxidp)); - bitcoin_address(changeaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33); + + if (strcmp(coin->chain->symbol, "HUSH") == 0) + bitcoin_address_ex(coin->chain->symbol, changeaddr, 0x1c, coin->chain->pubtype, myinfo->persistent_pubkey33, 33); + else + bitcoin_address(changeaddr, coin->chain->pubtype, myinfo->persistent_pubkey33, 33); + txfee = (coin->txfee + duplicates*coin->txfee/10); if ( strcmp(coin->symbol,"GAME") == 0 ) printf("GAME txfee %.8f\n",dstr(txfee)); diff --git a/crypto777/OS_nonportable.c b/crypto777/OS_nonportable.c index ca3f90695..d46fb2b1b 100755 --- a/crypto777/OS_nonportable.c +++ b/crypto777/OS_nonportable.c @@ -26,10 +26,10 @@ * not from the mingw header, so we need to include the windows header * if we are compiling in windows 64bit */ -//#if defined(_M_X64) -//#define WIN32_LEAN_AND_MEAN -//#include -//#endif +#if defined(_M_X64) +#define WIN32_LEAN_AND_MEAN +#include +#endif #include "OS_portable.h" diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index 5b6734ff0..f4aeed7c6 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -385,8 +385,13 @@ void dpow_statemachinestart(void *ptr) return; } dp->ratifying += bp->isratify; - bitcoin_address(srcaddr,src->chain->pubtype,dp->minerkey33,33); - bitcoin_address(destaddr,dest->chain->pubtype,dp->minerkey33,33); + + if (strcmp(src->chain->symbol, "HUSH") == 0) + bitcoin_address_ex(src->chain->symbol, srcaddr, 0x1c, src->chain->pubtype, dp->minerkey33, 33); + else + bitcoin_address(srcaddr, src->chain->pubtype, dp->minerkey33, 33); + + bitcoin_address(destaddr,dest->chain->pubtype,dp->minerkey33,33); if ( kmdheight >= 0 ) { ht = kmdheight;///strcmp("KMD",src->symbol) == 0 ? kmdheight : bp->height; diff --git a/iguana/exchanges/bitcoin.c b/iguana/exchanges/bitcoin.c index 62c0ed592..f7a5661fa 100755 --- a/iguana/exchanges/bitcoin.c +++ b/iguana/exchanges/bitcoin.c @@ -22,6 +22,51 @@ char *bitcoind_passthru(char *coinstr,char *serverport,char *userpass,char *meth return(bitcoind_RPC(0,coinstr,serverport,userpass,method,params,0)); } + +int32_t bitcoin_addr2rmd160_ex(char *symbol, uint8_t taddr, uint8_t *addrtypep, uint8_t rmd160[20], char *coinaddr) +{ + bits256 hash; uint8_t *buf, _buf[26], data5[128], rmd21[21]; char prefixaddr[64], hrp[64]; int32_t len, len5, offset; + *addrtypep = 0; + memset(rmd160, 0, 20); + if (coinaddr == 0 || coinaddr[0] == 0) + return(0); + if (coinaddr[0] == '0' && coinaddr[1] == 'x' && is_hexstr(coinaddr + 2, 0) == 40) // for ETH + { + decode_hex(rmd160, 20, coinaddr + 2); // not rmd160 hash but hopefully close enough; + return(20); + } + + offset = 1 + (taddr != 0); + memset(rmd160, 0, 20); + *addrtypep = 0; + buf = _buf; + if ((len = bitcoin_base58decode(buf, coinaddr)) >= 4) + { + // validate with trailing hash, then remove hash + hash = bits256_doublesha256(0, buf, 20 + offset); + + *addrtypep = (taddr == 0) ? *buf : buf[1]; + memcpy(rmd160, buf + offset, 20); + if ((buf[20 + offset] & 0xff) == hash.bytes[31] && (buf[21 + offset] & 0xff) == hash.bytes[30] && (buf[22 + offset] & 0xff) == hash.bytes[29] && (buf[23 + offset] & 0xff) == hash.bytes[28]) + { + //printf("coinaddr.(%s) valid checksum addrtype.%02x\n",coinaddr,*addrtypep); + return(20); + } + else if ((strcmp(symbol, "GRS") == 0 || strcmp(symbol, "SMART") == 0) && (buf[20 + offset] & 0xff) == hash.bytes[0] && (buf[21 + offset] & 0xff) == hash.bytes[1] && (buf[22 + offset] & 0xff) == hash.bytes[2] && (buf[23 + offset] & 0xff) == hash.bytes[3]) + return(20); + else if (strcmp(symbol, "BTC") != 0 || *addrtypep == 0 || *addrtypep == 5) + { + int32_t i; + //if ( len > 20 ) + // hash = bits256_calcaddrhash(symbol,buf,len); + for (i = 0; iminerkey33,33,tmp); - bitcoin_address(srcaddr,src->chain->pubtype,dp->minerkey33,33); + + if (strcmp(src->chain->symbol, "HUSH") == 0) + bitcoin_address_ex(src->chain->symbol, srcaddr, 0x1c, src->chain->pubtype, dp->minerkey33, 33); + else + bitcoin_address(srcaddr, src->chain->pubtype, dp->minerkey33, 33); + if ( (retstr= dpow_validateaddress(myinfo,src,srcaddr)) != 0 ) { json = cJSON_Parse(retstr); diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index 14df8eaac..3051c728e 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -522,7 +522,12 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS printf("illegal destination address.(%s)\n",changeaddr); return(0); } - bitcoin_addr2rmd160(&addrtype,rmd160,changeaddr); + + if (strcmp(coin->symbol, "HUSH") == 0) + bitcoin_addr2rmd160_ex(coin->symbol, 0x1c, &addrtype, rmd160, changeaddr); + else + bitcoin_addr2rmd160(&addrtype,rmd160,changeaddr); + spendlen = bitcoin_standardspend(spendscript,0,rmd160); bitcoin_txoutput(txobj,spendscript,spendlen,change); if ( opreturn != 0 ) diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index d633ff569..3c46ff1fb 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -321,7 +321,10 @@ cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_i { HASH_ITER(hh,subset->waddr,waddr,tmp2) { - bitcoin_address(coinaddr,coin->chain->pubtype,waddr->rmd160,20); + if (strcmp(coin->chain->symbol, "HUSH") == 0) + bitcoin_address_ex(coin->chain->symbol, coinaddr, 0x1c, coin->chain->pubtype, waddr->rmd160, 20); + else + bitcoin_address(coinaddr, coin->chain->pubtype, waddr->rmd160, 20); printf("%s ",coinaddr); jaddistr(array,coinaddr); } @@ -329,12 +332,20 @@ cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_i } else { - bitcoin_address(refaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33); - HASH_ITER(hh,myinfo->wallet,subset,tmp) + if (strcmp(coin->chain->symbol, "HUSH") == 0) + bitcoin_address_ex(coin->chain->symbol, refaddr, 0x1c, coin->chain->pubtype, myinfo->persistent_pubkey33, 33); + else + bitcoin_address(refaddr, coin->chain->pubtype, myinfo->persistent_pubkey33, 33); + + HASH_ITER(hh,myinfo->wallet,subset,tmp) { HASH_ITER(hh,subset->waddr,waddr,tmp2) { - bitcoin_address(coinaddr,coin->chain->pubtype,waddr->rmd160,20); + if (strcmp(coin->chain->symbol, "HUSH") == 0) + bitcoin_address_ex(coin->chain->symbol, coinaddr, 0x1c, coin->chain->pubtype, waddr->rmd160, 20); + else + bitcoin_address(coinaddr, coin->chain->pubtype, waddr->rmd160, 20); + jaddistr(array,coinaddr); if ( strcmp(coinaddr,refaddr) == 0 ) refaddr[0] = 0; @@ -359,17 +370,36 @@ int32_t iguana_addressvalidate(struct iguana_info *coin,uint8_t *addrtypep,char char checkaddr[64]; uint8_t rmd160[20]; *addrtypep = 0; memset(rmd160,0,sizeof(rmd160)); - bitcoin_addr2rmd160(addrtypep,rmd160,address); + + if (strcmp(coin->symbol, "HUSH") == 0) + bitcoin_addr2rmd160_ex(coin->symbol, 0x1c, addrtypep, rmd160, address); + else + bitcoin_addr2rmd160(addrtypep,rmd160,address); + //int32_t i; for (i=0; i<20; i++) // printf("%02x",rmd160[i]); // 764692cd5473f62ffa8a93e55d876f567623de07 //printf(" rmd160 addrtype.%02x\n",*addrtypep); - if ( bitcoin_address(checkaddr,*addrtypep,rmd160,20) == checkaddr && strcmp(address,checkaddr) == 0 && (*addrtypep == coin->chain->pubtype || *addrtypep == coin->chain->p2shtype) ) - return(0); - else - { - //printf(" checkaddr.(%s) address.(%s) type.%02x vs (%02x %02x)\n",checkaddr,address,*addrtypep,coin->chain->pubtype,coin->chain->p2shtype); - return(-1); - } + + if (strcmp(coin->symbol, "HUSH") == 0) + { + if (bitcoin_address_ex(coin->symbol, checkaddr, 0x1c, *addrtypep, rmd160, 20) == checkaddr && strcmp(address, checkaddr) == 0 && (*addrtypep == coin->chain->pubtype || *addrtypep == coin->chain->p2shtype)) + return(0); + else + { + //printf(" checkaddr.(%s) address.(%s) type.%02x vs (%02x %02x)\n",checkaddr,address,*addrtypep,coin->chain->pubtype,coin->chain->p2shtype); + return(-1); + } + } + else + { + if (bitcoin_address(checkaddr, *addrtypep, rmd160, 20) == checkaddr && strcmp(address, checkaddr) == 0 && (*addrtypep == coin->chain->pubtype || *addrtypep == coin->chain->p2shtype)) + return(0); + else + { + //printf(" checkaddr.(%s) address.(%s) type.%02x vs (%02x %02x)\n",checkaddr,address,*addrtypep,coin->chain->pubtype,coin->chain->p2shtype); + return(-1); + } + } } cJSON *iguana_waddressjson(struct iguana_info *coin,cJSON *item,struct iguana_waddress *waddr) diff --git a/iguana/main.c b/iguana/main.c index 571f45549..96ccaec3c 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -891,7 +891,7 @@ uint8_t *SuperNET_ciphercalc(void **ptrp,int32_t *cipherlenp,bits256 *privkeyp,b cJSON *SuperNET_rosettajson(struct supernet_info *myinfo,bits256 privkey,int32_t showprivs) { uint8_t rmd160[20],pub[33]; uint64_t nxt64bits; bits256 pubkey; - char str2[41],wifbuf[64],pbuf[65],addr[64],str[128],coinwif[16]; cJSON *retjson; struct iguana_info *coin,*tmp; + char str2[41],wifbuf[64],pbuf[65],addr[64],str[128],coinwif[16],*paddr = 0; cJSON *retjson; struct iguana_info *coin,*tmp; pubkey = acct777_pubkey(privkey); nxt64bits = acct777_nxt64bits(pubkey); retjson = cJSON_CreateObject(); @@ -910,7 +910,12 @@ cJSON *SuperNET_rosettajson(struct supernet_info *myinfo,bits256 privkey,int32_t { if ( coin != 0 && coin->symbol[0] != 0 ) { - if ( bitcoin_address(addr,coin->chain->pubtype,pub,33) != 0 ) + if (strcmp(coin->chain->symbol, "HUSH") == 0) + paddr = bitcoin_address_ex(coin->chain->symbol, addr, 0x1c, coin->chain->pubtype, pub, 33); + else + paddr = bitcoin_address(addr, coin->chain->pubtype, pub, 33); + + if ( paddr != 0 ) { jaddstr(retjson,coin->symbol,addr); sprintf(coinwif,"%swif",coin->symbol); diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index b0fa20b84..934cc081a 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -327,6 +327,7 @@ char *_setVsigner(struct iguana_info *coin,struct vin_info *V,int32_t ind,char * char *bitcoin_json2hex(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,cJSON *txjson,struct vin_info *V); int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr); +int32_t bitcoin_addr2rmd160_ex(char *symbol, uint8_t taddr, uint8_t *addrtypep, uint8_t rmd160[20], char *coinaddr); char *issue_startForging(struct supernet_info *myinfo,char *secret); struct bitcoin_unspent *iguana_unspentsget(struct supernet_info *myinfo,struct iguana_info *coin,char **retstrp,double *balancep,int32_t *numunspentsp,double minconfirms,char *address); void iguana_chainparms(struct supernet_info *myinfo,struct iguana_chain *chain,cJSON *argjson); @@ -560,6 +561,7 @@ bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory); struct gecko_chain *category_find(bits256 categoryhash,bits256 subhash); void *category_subscribe(struct supernet_info *myinfo,bits256 category,bits256 keyhash); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); +char *bitcoin_address_ex(char *symbol, char *coinaddr, uint8_t taddr, uint8_t addrtype, uint8_t *pubkey_or_rmd160, int32_t len); char *SuperNET_JSON(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,uint16_t port); int64_t iguana_txdetails(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *item,bits256 txid,int32_t vout,int32_t height); int32_t iguana_txidheight(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid);