From efd9eab3bded8a50effd339c209ecf9e93aa051d Mon Sep 17 00:00:00 2001
From: DeckerSU <support@decker.su>
Date: Tue, 18 Sep 2018 03:04:59 +0300
Subject: [PATCH 01/10] fix win build of iguana: prevent winsock.h inclusion in
 dtls1.h

---
 OSlibs/win/mingw.h         | 4 ++--
 crypto777/OS_nonportable.c | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

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 <io.h>
 
 #define _USE_W32_SOCKETS 1
-#define WIN32_LEAN_AND_MEAN
-#include <winsock2.h>
+//#define WIN32_LEAN_AND_MEAN
+//#include <winsock2.h>
 #include <windows.h>
 #define PTW32_STATIC_LIB
 #include "pthread.h"
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 <WinSock2.h>
-//#endif
+#if defined(_M_X64)
+#define WIN32_LEAN_AND_MEAN
+#include <WinSock2.h>
+#endif
 
 #include "OS_portable.h"
 

From 3ccea559584e4067cd40963e03bfaa72d6982d98 Mon Sep 17 00:00:00 2001
From: DeckerSU <support@decker.su>
Date: Fri, 21 Sep 2018 01:53:31 +0300
Subject: [PATCH 02/10] First approach to make iguana work with 2 bytes prefix
 coins, like HUSH

Main additions:

+ bitcoin_address_ex
+ bitcoin_addr2rmd160_ex

These functions with support taddr param. For example, for HUSH prefix is
{ 0x1C, 0xB8 }, where is taddr = 0x1C and addrtype = 0xB8.

All functions that used bitcoin_address and bitcoin_addr2rmd160 should be
rewritten with new *_ex analogs. currently it's done only for functions
used in split funds.

Also, if we want to support other type of such coins, we should change
condition "if (strcmp(coin->chain->symbol, "HUSH") == 0)" on more universal.

For example we can taddr in struct iguana_chain, but this needs to rewrite
all logic, for example, init structures, init static struct iguana_chain Chains[]
array and other things.

Adding prefix byte causes global changes in iguana.

p.s. With these changes HUSH splitfund in iguana works fine, but we need
to test notarizations on testnet (!) first, and change these functions
calls:

bitcoin_address -> bitcoin_address_ex
bitcoin_addr2rmd160 -> bitcoin_addr2rmd160_ex

everywhere it used. This is not finished yet.
---
 basilisk/basilisk_bitcoin.c |  7 +++-
 iguana/exchanges/bitcoin.c  | 81 +++++++++++++++++++++++++++++++++++++
 iguana/exchanges/bitcoin.h  |  1 +
 iguana/iguana_payments.c    |  7 +++-
 iguana/iguana_wallet.c      | 54 +++++++++++++++++++------
 includes/iguana_funcs.h     |  1 +
 6 files changed, 137 insertions(+), 14 deletions(-)

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/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; i<len; i++)
+				printf("%02x ", hash.bytes[i]);
+			char str[65]; printf("\n%s addrtype.%d taddr.%02x checkhash.(%s) len.%d mismatch %02x %02x %02x %02x vs %02x %02x %02x %02x (%s)\n", symbol, *addrtypep, taddr, coinaddr, len, buf[len - 1] & 0xff, buf[len - 2] & 0xff, buf[len - 3] & 0xff, buf[len - 4] & 0xff, hash.bytes[31], hash.bytes[30], hash.bytes[29], hash.bytes[28], bits256_str(str, hash));
+		}
+	}
+	return(0);
+}
+
 int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr)
 {
     bits256 hash; uint8_t *buf,_buf[25]; int32_t len;
@@ -75,6 +120,42 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,
     return(coinaddr);
 }
 
+char *bitcoin_address_ex(char *symbol, char *coinaddr, uint8_t taddr, uint8_t addrtype, uint8_t *pubkey_or_rmd160, int32_t len)
+{
+	static void *ctx;
+	int32_t offset, i, len5; char prefixed[64]; uint8_t data[64], data5[64], bigpubkey[65]; bits256 hash; struct iguana_info *coin;
+
+	coinaddr[0] = 0;
+	offset = 1 + (taddr != 0);
+	if (len != 20)
+	{
+		calc_rmd160_sha256(data + offset, pubkey_or_rmd160, len);
+		//for (i=0; i<20; i++)
+		//    printf("%02x",data[offset+i]);
+		//printf(" rmd160\n");
+	}
+	else memcpy(data + offset, pubkey_or_rmd160, 20);
+
+	if (taddr != 0)
+	{
+		data[0] = taddr;
+		data[1] = addrtype;
+	}
+	else data[0] = addrtype;
+	
+	hash = bits256_doublesha256(0, data, 20 + offset);
+	
+	for (i = 0; i<4; i++)
+			data[20 + offset + i] = hash.bytes[31 - i];
+	
+	if ((coinaddr = bitcoin_base58encode(coinaddr, data, 24 + offset)) != 0)
+	{
+		//printf("coinaddr.%p %s\n",coinaddr,coinaddr!=0?coinaddr:"null");
+	}
+	else printf("null coinaddr taddr.%02x\n", taddr);
+	return(coinaddr);
+}
+
 int32_t bitcoin_validaddress(struct iguana_info *coin,char *coinaddr)
 {
     uint8_t rmd160[20],addrtype; char checkaddr[128];
diff --git a/iguana/exchanges/bitcoin.h b/iguana/exchanges/bitcoin.h
index ad362a5a2..ab7ce7165 100755
--- a/iguana/exchanges/bitcoin.h
+++ b/iguana/exchanges/bitcoin.h
@@ -46,6 +46,7 @@
 int32_t bitcoin_validaddress(struct iguana_info *coin,char *coinaddr);
 int32_t bitcoin_cltvscript(uint8_t p2shtype,char *ps2h_coinaddr,uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,char *senderaddr,char *otheraddr,uint8_t secret160[20],uint32_t locktime);
 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 *bitcoin_cltvtx(struct iguana_info *coin,char *changeaddr,char *senderaddr,char *senders_otheraddr,char *otheraddr,uint32_t locktime,uint64_t satoshis,bits256 txid,int32_t vout,uint64_t inputsatoshis,bits256 privkey);
 int32_t bitcoin_MofNspendscript(uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,const struct vin_info *vp);
 
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/includes/iguana_funcs.h b/includes/iguana_funcs.h
index b0fa20b84..946584592 100755
--- a/includes/iguana_funcs.h
+++ b/includes/iguana_funcs.h
@@ -560,6 +560,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);

From d65ba531bb17fdb35883e1bed1ac4cc9a9dd66e3 Mon Sep 17 00:00:00 2001
From: DeckerSU <support@decker.su>
Date: Fri, 21 Sep 2018 01:57:23 +0300
Subject: [PATCH 03/10] bitcoin_addr2rmd160_ex -> iguana_funcs.h

---
 includes/iguana_funcs.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h
index 946584592..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);

From a06cdb0106a8a0429b804380c9e4dd2a3d8cdacb Mon Sep 17 00:00:00 2001
From: DeckerSU <support@decker.su>
Date: Fri, 21 Sep 2018 02:25:15 +0300
Subject: [PATCH 04/10] fix HUSH dpow start

before this commit we have error:
{"error":"source address or dest address has no privkey, importprivkey","tag":"10659764395713204969"}
on dpow start, bcz src coin (HUSH) address validate fails.
---
 iguana/iguana_notary.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c
index db3808263..a56fd6ecd 100755
--- a/iguana/iguana_notary.c
+++ b/iguana/iguana_notary.c
@@ -384,7 +384,12 @@ THREE_STRINGS_AND_DOUBLE(iguana,dpow,symbol,dest,pubkey,freq)
     char tmp[67];
     safecopy(tmp,pubkey,sizeof(tmp));
     decode_hex(dp->minerkey33,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);

From 303cb95f08c258edb9adb7c297416dd69f43a757 Mon Sep 17 00:00:00 2001
From: DeckerSU <support@decker.su>
Date: Fri, 21 Sep 2018 03:59:44 +0300
Subject: [PATCH 05/10] +bitcoin_address_ex in dpow_statemachinestart

---
 iguana/dpow/dpow_fsm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c
index 4301f8c3a..a7e007c81 100755
--- a/iguana/dpow/dpow_fsm.c
+++ b/iguana/dpow/dpow_fsm.c
@@ -384,8 +384,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;

From a588931d61fc341b3995c525de9e4ea86d7089e2 Mon Sep 17 00:00:00 2001
From: DeckerSU <support@decker.su>
Date: Fri, 21 Sep 2018 04:08:42 +0300
Subject: [PATCH 06/10] +bitcoin_address_ex in SuperNET_rosettajson (fix
 walletpassphrase output)

---
 iguana/main.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

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);

From 4eabde521ee13ae68a0a69f524ca75f1b0e43fda Mon Sep 17 00:00:00 2001
From: DeckerSU <support@decker.su>
Date: Fri, 21 Sep 2018 04:34:41 +0300
Subject: [PATCH 07/10] possible heap corruption fix (revert this if i'm wrong)

we allocate bp via calloc earlier, but didn't free it at the end of proc.
---
 iguana/dpow/dpow_fsm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c
index a7e007c81..b6d99be3a 100755
--- a/iguana/dpow/dpow_fsm.c
+++ b/iguana/dpow/dpow_fsm.c
@@ -265,7 +265,8 @@ void dpow_statemachinestart(void *ptr)
     void **ptrs = ptr;
     struct supernet_info *myinfo; struct dpow_info *dp; struct dpow_checkpoint checkpoint;
     int32_t i,j,ht,extralen,destprevvout0,srcprevvout0,src_or_dest,numratified=0,kmdheight,myind = -1; uint8_t extras[10000],pubkeys[64][33]; cJSON *ratified=0,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,MoM,merkleroot,srchash,destprevtxid0,srcprevtxid0; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t MoMdepth,duration,minsigs,starttime,srctime;
-    memset(&zero,0,sizeof(zero));
+	int32_t bp_alloc = 0;
+	memset(&zero,0,sizeof(zero));
     MoM = zero;
     srcprevtxid0 = destprevtxid0 = zero;
     srcprevvout0 = destprevvout0 = -1;
@@ -297,7 +298,7 @@ void dpow_statemachinestart(void *ptr)
     }
     if ( (bp= dp->blocks[checkpoint.blockhash.height]) == 0 )
     {
-        bp = calloc(1,sizeof(*bp));
+		bp = calloc(1, sizeof(*bp)); bp_alloc = 1;
         //printf("allocate bp for %s ht.%d -> %s\n",src->symbol,checkpoint.blockhash.height,dest->symbol);
         Numallocated++;
         bp->MoM = MoM;
@@ -596,6 +597,9 @@ void dpow_statemachinestart(void *ptr)
     dp->ratifying -= bp->isratify;
     // dp->blocks[bp->height] = 0;
     bp->state = 0xffffffff;
+	
+	// heap corruption detected?
+	if (bp_alloc) free(bp);
     free(ptr);
 }
 

From 9065c0ab4763875c516e000220f5199c918fe198 Mon Sep 17 00:00:00 2001
From: jl777 <jameslee777@yahoo.com>
Date: Fri, 10 Aug 2018 03:05:00 -1100
Subject: [PATCH 08/10] Attempt to fix deckers  00 bug

---
 iguana/dpow/dpow_network.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c
index 5343f33c6..1fe0d849c 100755
--- a/iguana/dpow/dpow_network.c
+++ b/iguana/dpow/dpow_network.c
@@ -1869,13 +1869,13 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru
         return;
     if ( bp->isratify == 0 && bp->state != 0xffffffff && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 )
     {
-        if ( bits256_nonz(srcutxo) != 0 )
+        if ( senderind != bp->myind && bits256_nonz(srcutxo) != 0 )
         {
             bp->notaries[senderind].src.prev_hash = srcutxo;
             bp->notaries[senderind].src.prev_vout = srcvout;
             //char str[65]; printf("%s senderind.%d <- %s/v%d\n",dp->symbol,senderind,bits256_str(str,srcutxo),srcvout);
         }
-        if ( bits256_nonz(destutxo) != 0 )
+        if ( senderind != bp->myind && bits256_nonz(destutxo) != 0 )
         {
             bp->notaries[senderind].dest.prev_hash = destutxo;
             bp->notaries[senderind].dest.prev_vout = destvout;

From f7844bb94e9e419720b72596198ca1a72aee5577 Mon Sep 17 00:00:00 2001
From: jl777 <jameslee777@yahoo.com>
Date: Fri, 10 Aug 2018 03:24:15 -1100
Subject: [PATCH 09/10] Mysrc/dest utxo

---
 iguana/dPoW.h              |  2 +-
 iguana/dpow/dpow_fsm.c     |  5 +++++
 iguana/dpow/dpow_network.c | 22 +++++++++++++++-------
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/iguana/dPoW.h b/iguana/dPoW.h
index f4cb5ebed..bc343f144 100755
--- a/iguana/dPoW.h
+++ b/iguana/dPoW.h
@@ -109,7 +109,7 @@ struct dpow_recvdata { uint64_t recvmask,bestmask; int8_t bestk; };
 
 struct dpow_block
 {
-    bits256 hashmsg,desttxid,srctxid,beacon,commit,MoM;
+    bits256 hashmsg,desttxid,srctxid,beacon,commit,MoM,mysrcutxo,mydestutxo;
     struct iguana_info *srccoin,*destcoin; char *opret_symbol;
     uint64_t destsigsmasks[DPOW_MAXRELAYS],srcsigsmasks[DPOW_MAXRELAYS];
     uint64_t recvmask,bestmask,ratifybestmask,ratifyrecvmask,pendingbestmask,pendingratifybestmask,ratifysigmasks[2];
diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c
index b6d99be3a..5e014059d 100755
--- a/iguana/dpow/dpow_fsm.c
+++ b/iguana/dpow/dpow_fsm.c
@@ -494,6 +494,11 @@ void dpow_statemachinestart(void *ptr)
             bp->notaries[myind].ratifydestutxo = ep->dest.prev_hash;
             bp->notaries[myind].ratifydestvout = ep->dest.prev_vout;
         }
+        else
+        {
+            bp->mysrcutxo = ep->src.prev_hash;
+            bp->mydestutxo = ep->dest.prev_hash;
+        }
     }
     /*if ( strcmp(dp->symbol,"CHIPS") == 0 && myind == 0 )
     {
diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c
index 1fe0d849c..a13091b19 100755
--- a/iguana/dpow/dpow_network.c
+++ b/iguana/dpow/dpow_network.c
@@ -1869,16 +1869,24 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru
         return;
     if ( bp->isratify == 0 && bp->state != 0xffffffff && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 )
     {
-        if ( senderind != bp->myind && bits256_nonz(srcutxo) != 0 )
+        if ( bp->myind != senderind )
         {
-            bp->notaries[senderind].src.prev_hash = srcutxo;
-            bp->notaries[senderind].src.prev_vout = srcvout;
-            //char str[65]; printf("%s senderind.%d <- %s/v%d\n",dp->symbol,senderind,bits256_str(str,srcutxo),srcvout);
+            if ( bits256_nonz(srcutxo) != 0 )
+            {
+                bp->notaries[senderind].src.prev_hash = srcutxo;
+                bp->notaries[senderind].src.prev_vout = srcvout;
+                //char str[65]; printf("%s senderind.%d <- %s/v%d\n",dp->symbol,senderind,bits256_str(str,srcutxo),srcvout);
+            }
+            if ( bits256_nonz(destutxo) != 0 )
+            {
+                bp->notaries[senderind].dest.prev_hash = destutxo;
+                bp->notaries[senderind].dest.prev_vout = destvout;
+            }
         }
-        if ( senderind != bp->myind && bits256_nonz(destutxo) != 0 )
+        else
         {
-            bp->notaries[senderind].dest.prev_hash = destutxo;
-            bp->notaries[senderind].dest.prev_vout = destvout;
+            bp->notaries[bp->myind].src.prev_hash = bp->mysrcutxo;
+            bp->notaries[bp->myind].dest.prev_hash = bp->mydestutxo;
         }
         if ( bestmask != 0 )
             bp->notaries[senderind].bestmask = bestmask;

From 09e4cb9e7f62381a08ed99b241691fc2622f0cf5 Mon Sep 17 00:00:00 2001
From: DeckerSU <support@decker.su>
Date: Fri, 21 Sep 2018 22:20:51 +0300
Subject: [PATCH 10/10] Revert "possible heap corruption fix (revert this if
 i'm wrong)"

This reverts commit 4eabde521ee13ae68a0a69f524ca75f1b0e43fda.
---
 iguana/dpow/dpow_fsm.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c
index 5e014059d..743f96c67 100755
--- a/iguana/dpow/dpow_fsm.c
+++ b/iguana/dpow/dpow_fsm.c
@@ -265,8 +265,7 @@ void dpow_statemachinestart(void *ptr)
     void **ptrs = ptr;
     struct supernet_info *myinfo; struct dpow_info *dp; struct dpow_checkpoint checkpoint;
     int32_t i,j,ht,extralen,destprevvout0,srcprevvout0,src_or_dest,numratified=0,kmdheight,myind = -1; uint8_t extras[10000],pubkeys[64][33]; cJSON *ratified=0,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,MoM,merkleroot,srchash,destprevtxid0,srcprevtxid0; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t MoMdepth,duration,minsigs,starttime,srctime;
-	int32_t bp_alloc = 0;
-	memset(&zero,0,sizeof(zero));
+    memset(&zero,0,sizeof(zero));
     MoM = zero;
     srcprevtxid0 = destprevtxid0 = zero;
     srcprevvout0 = destprevvout0 = -1;
@@ -298,7 +297,7 @@ void dpow_statemachinestart(void *ptr)
     }
     if ( (bp= dp->blocks[checkpoint.blockhash.height]) == 0 )
     {
-		bp = calloc(1, sizeof(*bp)); bp_alloc = 1;
+        bp = calloc(1,sizeof(*bp));
         //printf("allocate bp for %s ht.%d -> %s\n",src->symbol,checkpoint.blockhash.height,dest->symbol);
         Numallocated++;
         bp->MoM = MoM;
@@ -602,9 +601,6 @@ void dpow_statemachinestart(void *ptr)
     dp->ratifying -= bp->isratify;
     // dp->blocks[bp->height] = 0;
     bp->state = 0xffffffff;
-	
-	// heap corruption detected?
-	if (bp_alloc) free(bp);
     free(ptr);
 }