Browse Source

Coin symbol in bitcoin_address and bitcoin_addr2rmd160

dev
jl777 7 years ago
parent
commit
599a618faf
  1. 64
      iguana/exchanges/LP_bitcoin.c
  2. 4
      iguana/exchanges/LP_coins.c
  3. 4
      iguana/exchanges/LP_commands.c
  4. 14
      iguana/exchanges/LP_instantdex.c
  5. 2
      iguana/exchanges/LP_nativeDEX.c
  6. 4
      iguana/exchanges/LP_ordermatch.c
  7. 6
      iguana/exchanges/LP_prices.c
  8. 10
      iguana/exchanges/LP_privkey.c
  9. 20
      iguana/exchanges/LP_remember.c
  10. 10
      iguana/exchanges/LP_rpc.c
  11. 10
      iguana/exchanges/LP_swap.c
  12. 64
      iguana/exchanges/LP_transaction.c
  13. 4
      iguana/exchanges/LP_utxo.c
  14. 16
      iguana/exchanges/mm.c
  15. 10
      iguana/segwit_addr.c

64
iguana/exchanges/LP_bitcoin.c

@ -2018,7 +2018,7 @@ char *bitcoind_passthrut(char *coinstr,char *serverport,char *userpass,char *met
return(bitcoind_RPC(0,coinstr,serverport,userpass,method,params,timeout));
}
int32_t bitcoin_addr2rmd160(uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr)
int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr)
{
bits256 hash; uint8_t *buf,_buf[26]; int32_t len,offset;
offset = 1 + (taddr != 0);
@ -2051,7 +2051,7 @@ int32_t bitcoin_addr2rmd160(uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],
return(0);
}
char *bitcoin_address(char *coinaddr,uint8_t taddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len)
char *bitcoin_address(char *symbol,char *coinaddr,uint8_t taddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len)
{
int32_t offset,i; uint8_t data[26]; bits256 hash;// char checkaddr[65];
offset = 1 + (taddr != 0);
@ -2073,7 +2073,7 @@ char *bitcoin_address(char *coinaddr,uint8_t taddr,uint8_t addrtype,uint8_t *pub
return(coinaddr);
}
void bitcoin_priv2pub(void *ctx,uint8_t *pubkey33,char *coinaddr,bits256 privkey,uint8_t taddr,uint8_t addrtype)
void bitcoin_priv2pub(void *ctx,char *symbol,uint8_t *pubkey33,char *coinaddr,bits256 privkey,uint8_t taddr,uint8_t addrtype)
{
bits256 pub; //char privstr[65],url[512],postdata[1024],*retstr,*pubstr,*addr; cJSON *retjson;
memset(pubkey33,0,33);
@ -2081,7 +2081,7 @@ void bitcoin_priv2pub(void *ctx,uint8_t *pubkey33,char *coinaddr,bits256 privkey
crypto_box_priv2pub(pub.bytes,privkey.bytes);
//jaddbits256(retjson,"curve25519",pub);
bitcoin_pubkey33(ctx,pubkey33,privkey);
bitcoin_address(coinaddr,taddr,addrtype,pubkey33,33);
bitcoin_address(symbol,coinaddr,taddr,addrtype,pubkey33,33);
/*bits256_str(privstr,privkey);
sprintf(url,"%s/?",IGUANA_URL);
@ -2100,16 +2100,16 @@ void bitcoin_priv2pub(void *ctx,uint8_t *pubkey33,char *coinaddr,bits256 privkey
}*/
}
int32_t bitcoin_validaddress(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,char *coinaddr)
int32_t bitcoin_validaddress(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,char *coinaddr)
{
uint8_t rmd160[20],addrtype; char checkaddr[128];
if ( coinaddr == 0 || coinaddr[0] == 0 )
return(-1);
else if ( bitcoin_addr2rmd160(taddr,&addrtype,rmd160,coinaddr) < 0 )
else if ( bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,coinaddr) < 0 )
return(-1);
else if ( addrtype != pubtype && addrtype != p2shtype )
return(-1);
else if ( bitcoin_address(checkaddr,addrtype,taddr,rmd160,sizeof(rmd160)) != checkaddr || strcmp(checkaddr,coinaddr) != 0 )
else if ( bitcoin_address(symbol,checkaddr,addrtype,taddr,rmd160,sizeof(rmd160)) != checkaddr || strcmp(checkaddr,coinaddr) != 0 )
return(-1);
return(0);
}
@ -2182,13 +2182,13 @@ int32_t bitcoin_wif2priv(uint8_t wiftaddr,uint8_t *addrtypep,bits256 *privkeyp,c
return(-1);
}
int32_t bitcoin_wif2addr(void *ctx,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,char *coinaddr,char *wifstr)
int32_t bitcoin_wif2addr(void *ctx,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,char *coinaddr,char *wifstr)
{
bits256 privkey; uint8_t addrtype,pubkey33[33];
coinaddr[0] = 0;
if ( bitcoin_wif2priv(wiftaddr,&addrtype,&privkey,wifstr) == sizeof(privkey) )
{
bitcoin_priv2pub(ctx,pubkey33,coinaddr,privkey,taddr,pubtype);
bitcoin_priv2pub(ctx,symbol,pubkey33,coinaddr,privkey,taddr,pubtype);
}
return(-1);
}
@ -2268,7 +2268,7 @@ uint8_t iguana_addrtype(uint8_t pubtype,uint8_t p2shtype,uint8_t script_type)
}
}
int32_t iguana_scriptgen(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,int32_t *Mp,int32_t *nump,char *coinaddr,uint8_t *script,char *asmstr,uint8_t rmd160[20],uint8_t type,const struct vin_info *vp,int32_t txi)
int32_t iguana_scriptgen(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,int32_t *Mp,int32_t *nump,char *coinaddr,uint8_t *script,char *asmstr,uint8_t rmd160[20],uint8_t type,const struct vin_info *vp,int32_t txi)
{
uint8_t addrtype; char rmd160str[41],pubkeystr[256]; int32_t plen,i,m,n,flag = 0,scriptlen = 0;
m = n = 0;
@ -2278,7 +2278,7 @@ int32_t iguana_scriptgen(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,int32_t
if ( type == IGUANA_SCRIPT_76A988AC || type == IGUANA_SCRIPT_AC || type == IGUANA_SCRIPT_76AC || type == IGUANA_SCRIPT_P2SH )
{
init_hexbytes_noT(rmd160str,rmd160,20);
bitcoin_address(coinaddr,taddr,addrtype,rmd160,20);
bitcoin_address(symbol,coinaddr,taddr,addrtype,rmd160,20);
}
switch ( type )
{
@ -2317,7 +2317,7 @@ int32_t iguana_scriptgen(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,int32_t
case IGUANA_SCRIPT_OPRETURN:
if ( asmstr != 0 )
strcpy(asmstr,"OP_RETURN ");
bitcoin_address(coinaddr,taddr,addrtype,(uint8_t *)&vp->spendscript[0],vp->spendlen);
bitcoin_address(symbol,coinaddr,taddr,addrtype,(uint8_t *)&vp->spendscript[0],vp->spendlen);
flag++;
break;
case IGUANA_SCRIPT_3of3: m = 3, n = 3; break;
@ -2330,13 +2330,13 @@ int32_t iguana_scriptgen(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,int32_t
case IGUANA_SCRIPT_DATA:
if ( asmstr != 0 )
strcpy(asmstr,"DATA ONLY");
bitcoin_address(coinaddr,taddr,addrtype,(uint8_t *)&vp->spendscript[0],vp->spendlen);
bitcoin_address(symbol,coinaddr,taddr,addrtype,(uint8_t *)&vp->spendscript[0],vp->spendlen);
flag++;
break;
case IGUANA_SCRIPT_STRANGE:
if ( asmstr != 0 )
strcpy(asmstr,"STRANGE SCRIPT ");
bitcoin_address(coinaddr,taddr,addrtype,(uint8_t *)&vp->spendscript[0],vp->spendlen);
bitcoin_address(symbol,coinaddr,taddr,addrtype,(uint8_t *)&vp->spendscript[0],vp->spendlen);
flag++;
break;
default: break;//printf("unexpected script type.%d\n",type); break;
@ -2344,7 +2344,7 @@ int32_t iguana_scriptgen(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,int32_t
if ( n > 0 )
{
scriptlen = bitcoin_MofNspendscript(rmd160,script,0,vp);
bitcoin_address(coinaddr,taddr,p2shtype,script,scriptlen);
bitcoin_address(symbol,coinaddr,taddr,p2shtype,script,scriptlen);
if ( asmstr != 0 )
{
sprintf(asmstr,"%d ",m);
@ -2439,11 +2439,11 @@ int32_t bitcoin_scriptget(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2s
}
if ( *userdatap == p2shscript )
*userdatap = 0;
vp->spendlen = iguana_scriptgen(taddr,pubtype,p2shtype,&vp->M,&vp->N,vp->coinaddr,vp->spendscript,0,vp->rmd160,vp->type,(const struct vin_info *)vp,vp->vin.prev_vout);
vp->spendlen = iguana_scriptgen(symbol,taddr,pubtype,p2shtype,&vp->M,&vp->N,vp->coinaddr,vp->spendscript,0,vp->rmd160,vp->type,(const struct vin_info *)vp,vp->vin.prev_vout);
return(vp->spendlen);
}
int32_t _iguana_calcrmd160(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,struct vin_info *vp)
int32_t _iguana_calcrmd160(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,struct vin_info *vp)
{
static uint8_t zero_rmd160[20];
char hexstr[8192]; uint8_t *script,type; int32_t i,n,m,plen;
@ -2518,7 +2518,7 @@ int32_t _iguana_calcrmd160(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,struct
}
memcpy(vp->signers[i].pubkey,script,plen);
calc_rmd160_sha256(vp->signers[i].rmd160,vp->signers[i].pubkey,plen);
bitcoin_address(vp->signers[i].coinaddr,taddr,pubtype,vp->signers[i].pubkey,plen);
bitcoin_address(symbol,vp->signers[i].coinaddr,taddr,pubtype,vp->signers[i].pubkey,plen);
}
if ( (int32_t)((long)script - (long)vp->spendscript) == vp->spendlen-2 )
{
@ -2571,7 +2571,7 @@ int32_t _iguana_calcrmd160(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,struct
return(type);
}
int32_t iguana_calcrmd160(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,char *asmstr,struct vin_info *vp,uint8_t *pk_script,int32_t pk_scriptlen,bits256 debugtxid,int32_t vout,uint32_t sequence)
int32_t iguana_calcrmd160(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,char *asmstr,struct vin_info *vp,uint8_t *pk_script,int32_t pk_scriptlen,bits256 debugtxid,int32_t vout,uint32_t sequence)
{
int32_t scriptlen; uint8_t script[IGUANA_MAXSCRIPTSIZE];
memset(vp,0,sizeof(*vp));
@ -2579,9 +2579,9 @@ int32_t iguana_calcrmd160(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,char *a
vp->spendlen = pk_scriptlen;
vp->vin.sequence = sequence;
memcpy(vp->spendscript,pk_script,pk_scriptlen);
if ( (vp->type= _iguana_calcrmd160(taddr,pubtype,p2shtype,vp)) >= 0 )
if ( (vp->type= _iguana_calcrmd160(symbol,taddr,pubtype,p2shtype,vp)) >= 0 )
{
scriptlen = iguana_scriptgen(taddr,pubtype,p2shtype,&vp->M,&vp->N,vp->coinaddr,script,asmstr,vp->rmd160,vp->type,(const struct vin_info *)vp,vout);
scriptlen = iguana_scriptgen(symbol,taddr,pubtype,p2shtype,&vp->M,&vp->N,vp->coinaddr,script,asmstr,vp->rmd160,vp->type,(const struct vin_info *)vp,vout);
if ( vp->M == 0 && vp->N == 0 )
{
vp->M = vp->N = 1;
@ -2624,11 +2624,11 @@ cJSON *bitcoin_txscript(char *asmstr,char **vardata,int32_t numvars)
return(scriptjson);
}
cJSON *iguana_scriptpubkeys(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t *script,int32_t scriptlen,bits256 txid,int16_t vout,uint32_t sequenceid)
cJSON *iguana_scriptpubkeys(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t *script,int32_t scriptlen,bits256 txid,int16_t vout,uint32_t sequenceid)
{
int32_t type,i,n,plen; struct vin_info V; cJSON *pubkeys; char pubkeystr[256];
pubkeys = cJSON_CreateArray();
if ( (type= iguana_calcrmd160(taddr,pubtype,p2shtype,0,&V,script,scriptlen,txid,vout,sequenceid)) >= 0 )
if ( (type= iguana_calcrmd160(symbol,taddr,pubtype,p2shtype,0,&V,script,scriptlen,txid,vout,sequenceid)) >= 0 )
{
if ( (n= V.N) == 0 )
n = 1;
@ -2680,7 +2680,7 @@ cJSON *iguana_pubkeysjson(uint8_t *pubkeyptrs[],int32_t numpubkeys)
return(pubkeysjson);
}
cJSON *bitcoin_txinput(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *spendscript,int32_t spendlen,uint8_t *redeemscript,int32_t p2shlen,uint8_t *pubkeys[],int32_t numpubkeys,uint8_t *sig,int32_t siglen)
cJSON *bitcoin_txinput(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *spendscript,int32_t spendlen,uint8_t *redeemscript,int32_t p2shlen,uint8_t *pubkeys[],int32_t numpubkeys,uint8_t *sig,int32_t siglen)
{
cJSON *item,*vins; char p2shscriptstr[IGUANA_MAXSCRIPTSIZE*2+1]; uint8_t *script,len=0;
vins = jduplicate(jobj(txobj,"vin"));
@ -2700,7 +2700,7 @@ cJSON *bitcoin_txinput(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,cJSON *txo
script = redeemscript, len = p2shlen;
} else script = 0;
if ( script != 0 && numpubkeys == 0 )
jadd(item,"pubkeys",iguana_scriptpubkeys(taddr,pubtype,p2shtype,script,len,txid,vout,sequenceid));
jadd(item,"pubkeys",iguana_scriptpubkeys(symbol,taddr,pubtype,p2shtype,script,len,txid,vout,sequenceid));
else if ( pubkeys != 0 && numpubkeys > 0 )
jadd(item,"pubkeys",iguana_pubkeysjson(pubkeys,numpubkeys));
jaddbits256(item,"txid",txid);
@ -2744,12 +2744,12 @@ cJSON *bitcoin_txoutput(cJSON *txobj,uint8_t *paymentscript,int32_t len,uint64_t
return(txobj);
}
int32_t bitcoin_txaddspend(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,cJSON *txobj,char *destaddress,uint64_t satoshis)
int32_t bitcoin_txaddspend(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,cJSON *txobj,char *destaddress,uint64_t satoshis)
{
uint8_t outputscript[128],addrtype,rmd160[20]; int32_t scriptlen;
if ( bitcoin_validaddress(taddr,pubtype,p2shtype,destaddress) == 0 && satoshis != 0 )
if ( bitcoin_validaddress(symbol,taddr,pubtype,p2shtype,destaddress) == 0 && satoshis != 0 )
{
bitcoin_addr2rmd160(taddr,&addrtype,rmd160,destaddress);
bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,destaddress);
scriptlen = bitcoin_standardspend(outputscript,0,rmd160);
bitcoin_txoutput(txobj,outputscript,scriptlen,satoshis);
return(0);
@ -3176,7 +3176,7 @@ int32_t iguana_parsevoutobj(uint8_t *serialized,int32_t maxsize,struct iguana_ms
return(len);
}
cJSON *iguana_voutjson(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,struct iguana_msgvout *vout,int32_t txi,bits256 txid)
cJSON *iguana_voutjson(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,struct iguana_msgvout *vout,int32_t txi,bits256 txid)
{
// 035f1321ed17d387e4433b2fa229c53616057964af065f98bfcae2233c5108055e OP_CHECKSIG
char scriptstr[IGUANA_MAXSCRIPTSIZE+1]; int32_t i,m,n,scriptlen,asmtype; struct vin_info *vp;
@ -3189,10 +3189,10 @@ cJSON *iguana_voutjson(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,struct igu
if ( vout->pk_script != 0 && vout->pk_scriptlen*2+1 < sizeof(scriptstr) )
{
memset(vp,0,sizeof(*vp));
if ( (asmtype= iguana_calcrmd160(taddr,pubtype,p2shtype,0,vp,vout->pk_script,vout->pk_scriptlen,txid,txi,0xffffffff)) >= 0 )
if ( (asmtype= iguana_calcrmd160(symbol,taddr,pubtype,p2shtype,0,vp,vout->pk_script,vout->pk_scriptlen,txid,txi,0xffffffff)) >= 0 )
{
skey = cJSON_CreateObject();
scriptlen = iguana_scriptgen(taddr,pubtype,p2shtype,&m,&n,vp->coinaddr,space,0,vp->rmd160,asmtype,vp,txi);
scriptlen = iguana_scriptgen(symbol,taddr,pubtype,p2shtype,&m,&n,vp->coinaddr,space,0,vp->rmd160,asmtype,vp,txi);
//if ( asmstr[0] != 0 )
// jaddstr(skey,"asm",asmstr);
addrs = cJSON_CreateArray();
@ -3601,7 +3601,7 @@ int32_t iguana_rwmsgtx(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shty
return(-1);
}
if ( voutarray != 0 )
jaddi(voutarray,iguana_voutjson(taddr,pubtype,p2shtype,&msg->vouts[i],i,*txidp));
jaddi(voutarray,iguana_voutjson(symbol,taddr,pubtype,p2shtype,&msg->vouts[i],i,*txidp));
}
if ( segwitflag != 0 )
{

4
iguana/exchanges/LP_coins.c

@ -519,7 +519,7 @@ void LP_otheraddress(char *destcoin,char *otheraddr,char *srccoin,char *coinaddr
uint8_t addrtype,rmd160[20]; struct iguana_info *src,*dest;
if ( (src= LP_coinfind(srccoin)) != 0 && (dest= LP_coinfind(destcoin)) != 0 )
{
bitcoin_addr2rmd160(src->taddr,&addrtype,rmd160,coinaddr);
bitcoin_address(otheraddr,dest->taddr,dest->pubtype,rmd160,20);
bitcoin_addr2rmd160(srccoin,src->taddr,&addrtype,rmd160,coinaddr);
bitcoin_address(destcoin,otheraddr,dest->taddr,dest->pubtype,rmd160,20);
} else printf("couldnt find %s or %s\n",srccoin,destcoin);
}

4
iguana/exchanges/LP_commands.c

@ -211,9 +211,9 @@ jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\
jaddbits256(retjson,"mypubkey",G.LP_mypub25519);
init_hexbytes_noT(pub33str,G.LP_pubsecp,33);
jaddstr(retjson,"pubsecp",pub33str);
bitcoin_address(coinaddr,0,60,G.LP_myrmd160,20);
bitcoin_address("KMD",coinaddr,0,60,G.LP_myrmd160,20);
jaddstr(retjson,"KMD",coinaddr);
bitcoin_address(coinaddr,0,0,G.LP_myrmd160,20);
bitcoin_address("BTC",coinaddr,0,0,G.LP_myrmd160,20);
jaddstr(retjson,"BTC",coinaddr);
jaddstr(retjson,"NXT",G.LP_NXTaddr);
jadd(retjson,"coins",LP_coinsjson(LP_showwif));

14
iguana/exchanges/LP_instantdex.c

@ -153,12 +153,12 @@ void LP_instantdex_depositadd(char *coinaddr,bits256 txid)
LP_instantdex_filescreate(coinaddr);
}
int32_t LP_deposit_addr(char *p2shaddr,uint8_t *script,uint8_t taddr,uint8_t p2shtype,uint32_t timestamp,uint8_t *pubsecp33)
int32_t LP_deposit_addr(char *symbol,char *p2shaddr,uint8_t *script,uint8_t taddr,uint8_t p2shtype,uint32_t timestamp,uint8_t *pubsecp33)
{
uint8_t elsepub33[33],p2sh_rmd160[20]; int32_t n;
decode_hex(elsepub33,33,BOTS_BONDPUBKEY33);
n = bitcoin_performancebond(p2sh_rmd160,script,0,timestamp,pubsecp33,elsepub33);
bitcoin_address(p2shaddr,taddr,p2shtype,script,n);
bitcoin_address(symbol,p2shaddr,taddr,p2shtype,script,n);
return(n);
}
@ -181,7 +181,7 @@ char *LP_instantdex_deposit(struct iguana_info *coin,int32_t weeks,double amount
if ( weeks >= 10000 )
return(clonestr("{\"error\":\"numweeks must be less than 10000\"}"));
} else timestamp = (uint32_t)time(NULL) + 300, weeki = 0;
scriptlen = LP_deposit_addr(p2shaddr,script,coin->taddr,coin->p2shtype,timestamp,G.LP_pubsecp);
scriptlen = LP_deposit_addr(coin->symbol,p2shaddr,script,coin->taddr,coin->p2shtype,timestamp,G.LP_pubsecp);
argjson = cJSON_CreateObject();
array = cJSON_CreateArray();
item = cJSON_CreateObject();
@ -306,7 +306,7 @@ int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info
if ( iter == 1 )
expiration = ((weeki * LP_WEEKMULTBAD + j*3600) + LP_FIRSTWEEKTIME);
else expiration = ((weeki * LP_WEEKMULT + j*3600) + LP_FIRSTWEEKTIME);
redeemlen = LP_deposit_addr(checkaddr,redeemscript,coin->taddr,coin->p2shtype,expiration,G.LP_pubsecp);
redeemlen = LP_deposit_addr(coin->symbol,checkaddr,redeemscript,coin->taddr,coin->p2shtype,expiration,G.LP_pubsecp);
if ( strcmp(checkaddr,vinaddr) == 0 )
{
flagi = 1;
@ -471,7 +471,7 @@ int64_t LP_dynamictrust(int64_t credits,bits256 pubkey,int64_t kmdvalue)
struct LP_pubswap *ptr,*tmp; struct LP_swapstats *sp; struct LP_pubkey_info *pubp; struct LP_address *ap; char coinaddr[64]; struct iguana_info *coin; int64_t swaps_kmdvalue = 0;
if ( (coin= LP_coinfind("KMD")) != 0 && (pubp= LP_pubkeyfind(pubkey)) != 0 )
{
bitcoin_address(coinaddr,coin->taddr,coin->pubtype,pubp->pubsecp,33);
bitcoin_address(coin->symbol,coinaddr,coin->taddr,coin->pubtype,pubp->pubsecp,33);
DL_FOREACH_SAFE(pubp->bobswaps,ptr,tmp)
{
if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 )
@ -513,8 +513,8 @@ int64_t LP_instantdex_proofcheck(char *coinaddr,cJSON *proof,int32_t num)
uint8_t rmd160[20],addrtype; int64_t credits=0; int32_t i,j; bits256 prevtxid,txid; char othersmartaddr[64]; struct iguana_info *coin; struct LP_address *ap = 0;
if ( (coin= LP_coinfind("KMD")) != 0 )
{
bitcoin_addr2rmd160(0,&addrtype,rmd160,coinaddr);
bitcoin_address(othersmartaddr,0,60,rmd160,20);
bitcoin_addr2rmd160(coin->symbol,0,&addrtype,rmd160,coinaddr);
bitcoin_address("KMD",othersmartaddr,0,60,rmd160,20);
//printf("proofcheck addrtype.%d (%s) -> %s\n",addrtype,coinaddr,othersmartaddr);
if ((ap= LP_address(coin,othersmartaddr)) != 0 )
{

2
iguana/exchanges/LP_nativeDEX.c

@ -745,7 +745,7 @@ void bech32_tests()
}
else
{
bitcoin_addr2rmd160(0,&addrtype,rmd160+1,"1KXrWXciRDZUpQwQmuM1DbwsKDLYAYsVLR");
bitcoin_addr2rmd160("BTC",0,&addrtype,rmd160+1,"1KXrWXciRDZUpQwQmuM1DbwsKDLYAYsVLR");
for (i=0; i<data_len; i++)
printf("%02x",data[i]);
printf(" datalen.%d <- %s (%s) -> ",(int32_t)data_len,test,"1KXrWXciRDZUpQwQmuM1DbwsKDLYAYsVLR");

4
iguana/exchanges/LP_ordermatch.c

@ -451,7 +451,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
printf("cant find coin.%s\n",qp->srccoin);
return(-1);
}
privkey = LP_privkey(coin->smartaddr,coin->taddr);
privkey = LP_privkey(coin->symbol,coin->smartaddr,coin->taddr);
if ( bits256_nonz(privkey) != 0 && bits256_cmp(G.LP_mypub25519,qp->srchash) == 0 )
{
LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis-qp->txfee,rel,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector);
@ -615,7 +615,7 @@ char *LP_connectedalice(struct LP_quoteinfo *qp,char *pairstr) // alice
LP_aliceid(qp->tradeid,qp->aliceid,"error6",0,0);
return(clonestr("{\"error\":\"cant get alicecoin\"}"));
}
qp->privkey = LP_privkey(qp->destaddr,coin->taddr);
qp->privkey = LP_privkey(coin->symbol,qp->destaddr,coin->taddr);
if ( bits256_nonz(qp->privkey) != 0 )//&& qp->quotetime >= qp->timestamp-3 )
{
retjson = cJSON_CreateObject();

6
iguana/exchanges/LP_prices.c

@ -260,7 +260,7 @@ struct LP_address *_LP_addressfind(struct iguana_info *coin,char *coinaddr)
HASH_FIND(hh,coin->addresses,coinaddr,strlen(coinaddr),ap);
if ( ap != 0 && bits256_nonz(ap->pubkey) == 0 )
{
bitcoin_addr2rmd160(coin->taddr,&addrtype,rmd160,coinaddr);
bitcoin_addr2rmd160(coin->symbol,coin->taddr,&addrtype,rmd160,coinaddr);
if ( (pubp= LP_pubkey_rmd160find(rmd160)) != 0 )
{
ap->pubkey = pubp->pubkey;
@ -275,7 +275,7 @@ struct LP_address *_LP_addressadd(struct iguana_info *coin,char *coinaddr)
uint8_t rmd160[20],addrtype; struct LP_address *ap; struct LP_pubkey_info *pubp;
ap = calloc(1,sizeof(*ap));
safecopy(ap->coinaddr,coinaddr,sizeof(ap->coinaddr));
bitcoin_addr2rmd160(coin->taddr,&addrtype,rmd160,coinaddr);
bitcoin_addr2rmd160(coin->symbol,coin->taddr,&addrtype,rmd160,coinaddr);
if ( (pubp= LP_pubkey_rmd160find(rmd160)) != 0 )
{
ap->pubkey = pubp->pubkey;
@ -797,7 +797,7 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char *
}
if ( pubp->timestamp < oldest )
continue;
bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160));
bitcoin_address(base,coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160));
avesatoshis = maxsatoshis = n = 0;
ap = 0;
if ( (price= LP_pubkey_price(&n,&avesatoshis,&maxsatoshis,pubp,baseid,relid)) > SMALLVAL ) //pubp->matrix[baseid][relid]) > SMALLVAL )//&& pubp->timestamps[baseid][relid] >= oldest )

10
iguana/exchanges/LP_privkey.c

@ -171,17 +171,17 @@ char *LP_secretaddresses(void *ctx,char *prefix,char *passphrase,int32_t n,uint8
else if ( n > 777 )
n = 777;
conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
bitcoin_priv2pub(ctx,pubkey33,coinaddr,privkey,taddr,pubtype);
bitcoin_priv2pub(ctx,"KMD",pubkey33,coinaddr,privkey,taddr,pubtype);
printf("generator (%s) secrets.[%d] <%s> t.%u p.%u\n",coinaddr,n,passphrase,taddr,pubtype);
sprintf(output,"\"addresses\":[");
for (i=0; i<n; i++)
{
sprintf(buf,"%s %s %03d",prefix,passphrase,i);
conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)buf,(int32_t)strlen(buf));
bitcoin_priv2pub(ctx,pubkey33,coinaddr,privkey,taddr,pubtype);
bitcoin_priv2pub(ctx,"KMD",pubkey33,coinaddr,privkey,taddr,pubtype);
bitcoin_priv2wif(0,wifstr,privkey,188);
bitcoin_wif2priv(0,&tmptype,&checkprivkey,wifstr);
bitcoin_addr2rmd160(taddr,&tmptype,rmd160,coinaddr);
bitcoin_addr2rmd160("KMD",taddr,&tmptype,rmd160,coinaddr);
if ( bits256_cmp(checkprivkey,privkey) != 0 )
{
printf("WIF.(%s) error -> %s vs %s?\n",wifstr,bits256_str(str,privkey),bits256_str(str2,checkprivkey));
@ -268,13 +268,13 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan
nxtaddr = conv_NXTpassword(tmpkey.bytes,pubkeyp->bytes,0,0);
RS_encode(G.LP_NXTaddr,nxtaddr);
}
bitcoin_priv2pub(ctx,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype);
bitcoin_priv2pub(ctx,coin->symbol,coin->pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype);
if ( coin->counter == 0 )
{
coin->counter++;
memcpy(G.LP_pubsecp,coin->pubkey33,33);
bitcoin_priv2wif(coin->wiftaddr,tmpstr,privkey,coin->wiftype);
bitcoin_addr2rmd160(coin->taddr,&tmptype,G.LP_myrmd160,coin->smartaddr);
bitcoin_addr2rmd160(coin->symbol,coin->taddr,&tmptype,G.LP_myrmd160,coin->smartaddr);
LP_privkeyadd(privkey,G.LP_myrmd160);
G.LP_privkey = privkey;
if ( G.counter++ == 0 )

20
iguana/exchanges/LP_remember.c

@ -73,7 +73,7 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx
fprintf(fp,",\"trigger\":\"%s\"",bits256_str(str,triggertxid));
if ( bits256_nonz(swap->I.pubAm) != 0 && bits256_nonz(swap->I.pubBn) != 0 )
{
basilisk_alicescript(redeemscript,&len,script,0,coinaddr,alicecoin->taddr,alicecoin->p2shtype,swap->I.pubAm,swap->I.pubBn);
basilisk_alicescript(alicecoin->symbol,redeemscript,&len,script,0,coinaddr,alicecoin->taddr,alicecoin->p2shtype,swap->I.pubAm,swap->I.pubBn);
LP_importaddress(swap->I.alicestr,coinaddr);
fprintf(fp,",\"Apayment\":\"%s\"",coinaddr);
}
@ -570,9 +570,9 @@ int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t
{
decode_hex(rswap->pubkey33,33,dest33);
if ( rswap->iambob != 0 && (coin= LP_coinfind(rswap->src)) != 0 )
bitcoin_address(rswap->destaddr,coin->taddr,coin->pubtype,rswap->pubkey33,33);
bitcoin_address(coin->symbol,rswap->destaddr,coin->taddr,coin->pubtype,rswap->pubkey33,33);
else if ( rswap->iambob == 0 && (coin= LP_coinfind(rswap->dest)) != 0 )
bitcoin_address(rswap->Adestaddr,coin->taddr,coin->pubtype,rswap->pubkey33,33);
bitcoin_address(coin->symbol,rswap->Adestaddr,coin->taddr,coin->pubtype,rswap->pubkey33,33);
//for (i=0; i<33; i++)
// printf("%02x",pubkey33[i]);
//printf(" <- %s dest33\n",dest33);
@ -586,9 +586,9 @@ int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t
if ( i < 33 )
memcpy(rswap->other33,other33,33);
if ( rswap->iambob != 0 && (coin= LP_coinfind(rswap->dest)) != 0 )
bitcoin_address(rswap->Adestaddr,coin->taddr,coin->pubtype,rswap->other33,33);
bitcoin_address(coin->symbol,rswap->Adestaddr,coin->taddr,coin->pubtype,rswap->other33,33);
else if ( rswap->iambob == 0 && (coin= LP_coinfind(rswap->src)) != 0 )
bitcoin_address(rswap->destaddr,coin->taddr,coin->pubtype,rswap->other33,33);
bitcoin_address(coin->symbol,rswap->destaddr,coin->taddr,coin->pubtype,rswap->other33,33);
//printf("(%s, %s) <- %s other33\n",rswap->destaddr,rswap->Adestaddr,dest33);
}
if ( (rswap->plocktime= juint(item,"plocktime")) == 0 )
@ -921,7 +921,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
{
if ( alice != 0 )
{
bitcoin_address(otheraddr,alice->taddr,alice->pubtype,rswap.other33,33);
bitcoin_address(alice->symbol,otheraddr,alice->taddr,alice->pubtype,rswap.other33,33);
destBdest = otheraddr;
destAdest = rswap.Adestaddr;
if ( LP_TECHSUPPORT == 0 && strcmp(alice->smartaddr,rswap.Adestaddr) != 0 )
@ -936,7 +936,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
}
if ( (bob= LP_coinfind(rswap.bobcoin)) != 0 )
{
bitcoin_address(rswap.Sdestaddr,bob->taddr,bob->pubtype,rswap.pubkey33,33);
bitcoin_address(bob->symbol,rswap.Sdestaddr,bob->taddr,bob->pubtype,rswap.pubkey33,33);
srcAdest = rswap.Sdestaddr;
}
srcBdest = rswap.destaddr;
@ -945,7 +945,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
{
if ( bob != 0 )
{
bitcoin_address(otheraddr,bob->taddr,bob->pubtype,rswap.other33,33);
bitcoin_address(bob->symbol,otheraddr,bob->taddr,bob->pubtype,rswap.other33,33);
srcAdest = otheraddr;
srcBdest = rswap.destaddr;
if ( LP_TECHSUPPORT == 0 && strcmp(bob->smartaddr,rswap.destaddr) != 0 )
@ -960,7 +960,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
}
if ( (alice= LP_coinfind(rswap.alicecoin)) != 0 )
{
bitcoin_address(rswap.Sdestaddr,alice->taddr,alice->pubtype,rswap.pubkey33,33);
bitcoin_address(alice->symbol,rswap.Sdestaddr,alice->taddr,alice->pubtype,rswap.pubkey33,33);
destBdest = rswap.Sdestaddr;
}
destAdest = rswap.Adestaddr;
@ -1021,7 +1021,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
{
char privaddr[64]; uint8_t privpub33[33];
bitcoin_pubkey33(ctx,privpub33,rswap.myprivs[0]);
bitcoin_address(privaddr,0,60,privpub33,33);
bitcoin_address(rswap.bobcoin,privaddr,0,60,privpub33,33);
printf("alicespend len.%d redeemlen.%d priv0addr.(%s) priv0.(%s)\n",len,redeemlen,privaddr,bits256_str(str,rswap.myprivs[0]));
}
for (j=0; j<32; j++)

10
iguana/exchanges/LP_rpc.c

@ -299,8 +299,8 @@ cJSON *LP_validateaddress(char *symbol,char *address)
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"address",address);
bitcoin_addr2rmd160(coin->taddr,&addrtype,rmd160,address);
bitcoin_address(checkaddr,coin->taddr,addrtype,rmd160,20);
bitcoin_addr2rmd160(symbol,coin->taddr,&addrtype,rmd160,address);
bitcoin_address(symbol,checkaddr,coin->taddr,addrtype,rmd160,20);
if ( addrtype != coin->pubtype && addrtype != coin->p2shtype )
{
jadd(retjson,"isvalid",cJSON_CreateFalse());
@ -316,7 +316,7 @@ cJSON *LP_validateaddress(char *symbol,char *address)
strcat(script,"88ac");
jaddstr(retjson,"scriptPubKey",script);
}
bitcoin_address(coinaddr,coin->taddr,coin->pubtype,G.LP_myrmd160,20);
bitcoin_address(symbol,coinaddr,coin->taddr,coin->pubtype,G.LP_myrmd160,20);
jadd(retjson,"ismine",strcmp(coinaddr,coin->smartaddr) == 0 ? cJSON_CreateTrue() : cJSON_CreateFalse());
jadd(retjson,"iswatchonly",cJSON_CreateTrue());
jadd(retjson,"isscript",addrtype == coin->p2shtype ? cJSON_CreateTrue() : cJSON_CreateFalse());
@ -571,9 +571,9 @@ cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag)
return(cJSON_Parse("{\"result\":\"electrum should have local wallet\"}"));
if ( ctx == 0 )
ctx = bitcoin_ctx();
bitcoin_wif2addr(ctx,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr);
bitcoin_wif2addr(ctx,symbol,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr);
#ifdef LP_DONT_IMPORTPRIVKEY
bitcoin_wif2addr(ctx,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr);
bitcoin_wif2addr(ctx,symbol,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr);
if ( LP_importaddress(symbol,address) < 0 )
return(cJSON_Parse("{\"error\":\"couldnt import\"}"));
else return(cJSON_Parse("{\"result\":\"success\"}"));

10
iguana/exchanges/LP_swap.c

@ -596,7 +596,7 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
memcpy(rawtx->redeemscript,&data[datalen],rawtx->I.redeemlen);
//for (i=0; i<rawtx->I.redeemlen; i++)
// printf("%02x",rawtx->redeemscript[i]);
bitcoin_address(redeemaddr,coin->taddr,coin->p2shtype,rawtx->redeemscript,rawtx->I.redeemlen);
bitcoin_address(coin->symbol,redeemaddr,coin->taddr,coin->p2shtype,rawtx->redeemscript,rawtx->I.redeemlen);
//printf(" received redeemscript.(%s) %s taddr.%d\n",redeemaddr,coin->symbol,coin->taddr);
LP_swap_coinaddr(coin,checkaddr,0,data,datalen,0);
if ( strcmp(redeemaddr,checkaddr) != 0 )
@ -662,7 +662,7 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
char str[65];
LP_swap_coinaddr(coin,rawtx->p2shaddr,0,data,datalen,0);
printf("got %s txid.%s (%s) -> %s\n",rawtx->name,bits256_str(str,rawtx->I.signedtxid),jprint(txobj,0),rawtx->p2shaddr);
} else bitcoin_address(rawtx->p2shaddr,coin->taddr,coin->p2shtype,rawtx->spendscript,hexlen);
} else bitcoin_address(coin->symbol,rawtx->p2shaddr,coin->taddr,coin->p2shtype,rawtx->spendscript,hexlen);
}
} else printf("%s satoshis %.8f ERROR.(%s) txfees.[%.8f %.8f: %.8f] amount.%.8f -> %.8f\n",rawtx->name,dstr(j64bits(vout,"satoshis")),jprint(txobj,0),dstr(swap->I.Atxfee),dstr(swap->I.Btxfee),dstr(txfee),dstr(rawtx->I.amount),dstr(rawtx->I.amount)-dstr(txfee));
}
@ -1019,13 +1019,13 @@ void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx *
if ( strcmp(coin->symbol,"BTC") == 0 && (quoteid % 10) == 0 )
decode_hex(rawtx->I.rmd160,20,TIERNOLAN_RMD160);
else decode_hex(rawtx->I.rmd160,20,INSTANTDEX_RMD160);
bitcoin_address(rawtx->I.destaddr,coin->taddr,coin->pubtype,rawtx->I.rmd160,20);
bitcoin_address(coin->symbol,rawtx->I.destaddr,coin->taddr,coin->pubtype,rawtx->I.rmd160,20);
}
if ( pubkey33 != 0 )
{
memcpy(rawtx->I.pubkey33,pubkey33,33);
bitcoin_address(rawtx->I.destaddr,coin->taddr,coin->pubtype,rawtx->I.pubkey33,33);
bitcoin_addr2rmd160(coin->taddr,&rawtx->I.addrtype,rawtx->I.rmd160,rawtx->I.destaddr);
bitcoin_address(coin->symbol,rawtx->I.destaddr,coin->taddr,coin->pubtype,rawtx->I.pubkey33,33);
bitcoin_addr2rmd160(coin->symbol,coin->taddr,&rawtx->I.addrtype,rawtx->I.rmd160,rawtx->I.destaddr);
}
if ( rawtx->I.vouttype <= 1 && rawtx->I.destaddr[0] != 0 )
{

64
iguana/exchanges/LP_transaction.c

@ -45,10 +45,10 @@ int32_t LP_privkeyadd(bits256 privkey,uint8_t rmd160[20])
return(G.LP_numprivkeys);
}
bits256 LP_privkey(char *coinaddr,uint8_t taddr)
bits256 LP_privkey(char *symbol,char *coinaddr,uint8_t taddr)
{
bits256 privkey; uint8_t addrtype,rmd160[20];
bitcoin_addr2rmd160(taddr,&addrtype,rmd160,coinaddr);
bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,coinaddr);
privkey = LP_privkeyfind(rmd160);
return(privkey);
}
@ -343,7 +343,7 @@ bits256 iguana_str2priv(uint8_t wiftaddr,char *str)
return(privkey);
}
int32_t iguana_vininfo_create(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msgtx,cJSON *vins,int32_t numinputs,struct vin_info *V)
int32_t iguana_vininfo_create(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msgtx,cJSON *vins,int32_t numinputs,struct vin_info *V)
{
int32_t i,plen,finalized = 1,len = 0; struct vin_info *vp; //struct iguana_waccount *wacct; struct iguana_waddress *waddr; uint32_t sigsize,pubkeysize,p2shsize,userdatalen;
msgtx->tx_in = numinputs;
@ -375,9 +375,9 @@ int32_t iguana_vininfo_create(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uin
{
memcpy(vp->spendscript,msgtx->vins[i].spendscript,msgtx->vins[i].spendlen);
vp->spendlen = msgtx->vins[i].spendlen;
_iguana_calcrmd160(taddr,pubtype,p2shtype,vp);
_iguana_calcrmd160(symbol,taddr,pubtype,p2shtype,vp);
if ( (plen= bitcoin_pubkeylen(vp->signers[0].pubkey)) > 0 )
bitcoin_address(vp->coinaddr,taddr,pubtype,vp->signers[0].pubkey,plen);
bitcoin_address(symbol,vp->coinaddr,taddr,pubtype,vp->signers[0].pubkey,plen);
}
if ( vp->M == 0 && vp->N == 0 )
vp->M = vp->N = 1;
@ -545,8 +545,8 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_
{
//for (j=0; j<msgtx->vins[i].p2shlen; j++)
// printf("%02x",msgtx->vins[i].redeemscript[j]);
bitcoin_address(coinaddr,taddr,p2shtype,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen);
type = iguana_calcrmd160(taddr,pubtype,p2shtype,0,&mvin,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen,zero,0,0);
bitcoin_address(symbol,coinaddr,taddr,p2shtype,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen);
type = iguana_calcrmd160(symbol,taddr,pubtype,p2shtype,0,&mvin,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen,zero,0,0);
for (j=0; j<mvin.N; j++)
{
if ( V->suppress_pubkeys == 0 )
@ -596,7 +596,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_
}
}
}
finalized = iguana_vininfo_create(taddr,pubtype,p2shtype,isPoS,serialized2,maxsize,msgtx,vins,numinputs,V);
finalized = iguana_vininfo_create(symbol,taddr,pubtype,p2shtype,isPoS,serialized2,maxsize,msgtx,vins,numinputs,V);
//printf("finalized.%d ignore_cltverr.%d suppress.%d\n",finalized,V[0].ignore_cltverr,V[0].suppress_pubkeys);
sighash = LP_sighash(symbol,zcash);
if ( (complete= bitcoin_verifyvins(ctx,symbol,taddr,pubtype,p2shtype,isPoS,height,signedtxidp,&signedtx,msgtx,serialized3,maxsize,V,sighash,1,V->suppress_pubkeys,zcash)) > 0 && signedtx != 0 )
@ -849,14 +849,14 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
}
jaddbits256(item,"txid",utxotxid);
jaddnum(item,"vout",utxovout);
bitcoin_address(tmpaddr,taddr,pubtype,pubkey33,33);
bitcoin_addr2rmd160(taddr,&addrtype,rmd160,tmpaddr);
bitcoin_address(symbol,tmpaddr,taddr,pubtype,pubkey33,33);
bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,tmpaddr);
if ( redeemlen != 0 )
{
init_hexbytes_noT(hexstr,redeemscript,redeemlen);
jaddstr(item,"redeemScript",hexstr);
if ( vinaddr != 0 )
bitcoin_addr2rmd160(taddr,&addrtype,rmd160,vinaddr);
bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,vinaddr);
spendlen = bitcoin_p2shspend(spendscript,0,rmd160);
//printf("P2SH path.%s\n",vinaddr!=0?vinaddr:0);
} else spendlen = bitcoin_standardspend(spendscript,0,rmd160);
@ -870,9 +870,9 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
if ( destaddr == 0 )
{
destaddr = _destaddr;
bitcoin_address(destaddr,taddr,pubtype,pubkey33,33);
bitcoin_address(symbol,destaddr,taddr,pubtype,pubkey33,33);
}
bitcoin_addr2rmd160(taddr,&addrtype,rmd160,destaddr);
bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,destaddr);
if ( addrtype == p2shtype )
spendlen = bitcoin_p2shspend(spendscript,0,rmd160);
else spendlen = bitcoin_standardspend(spendscript,0,rmd160);
@ -886,7 +886,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
if ( change != 0 )
{
int32_t changelen; uint8_t changescript[1024],changetype,changermd160[20];
bitcoin_addr2rmd160(taddr,&changetype,changermd160,changeaddr);
bitcoin_addr2rmd160(symbol,taddr,&changetype,changermd160,changeaddr);
changelen = bitcoin_standardspend(changescript,0,changermd160);
txobj = bitcoin_txoutput(txobj,changescript,changelen,change);
}
@ -1260,7 +1260,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
free_json(txobj);
return(0);
}
bitcoin_addr2rmd160(coin->taddr,&addrtype,rmd160,coinaddr);
bitcoin_addr2rmd160(coin->symbol,coin->taddr,&addrtype,rmd160,coinaddr);
if ( addrtype == coin->pubtype )
spendlen = bitcoin_standardspend(spendscript,0,rmd160);
else spendlen = bitcoin_p2shspend(spendscript,0,rmd160);
@ -1321,7 +1321,7 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
memset(signedtxid.bytes,0,sizeof(signedtxid));
safecopy(changeaddr,coin->smartaddr,sizeof(changeaddr));
safecopy(vinaddr,coin->smartaddr,sizeof(vinaddr));
privkey = LP_privkey(vinaddr,coin->taddr);
privkey = LP_privkey(coin->symbol,vinaddr,coin->taddr);
maxV = LP_MAXVINS;
V = malloc(maxV * sizeof(*V));
for (iter=0; iter<2; iter++)
@ -1490,7 +1490,7 @@ int32_t basilisk_rawtx_sign(char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t
if ( changermd160 != 0 )
{
changeaddr = _changeaddr;
bitcoin_address(changeaddr,taddr,pubtype,changermd160,20);
bitcoin_address(symbol,changeaddr,taddr,pubtype,changermd160,20);
//printf("changeaddr.(%s)\n",changeaddr);
}
for (iter=0; iter<2; iter++)
@ -1515,7 +1515,7 @@ int32_t basilisk_rawtx_sign(char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t
//return(_basilisk_rawtx_sign(symbol,pubtype,p2shtype,isPoS,wiftype,swap,timestamp,locktime,sequenceid,dest,rawtx,privkey,privkey2,userdata,userdatalen,ignore_cltverr));
}
int32_t basilisk_alicescript(uint8_t *redeemscript,int32_t *redeemlenp,uint8_t *script,int32_t n,char *msigaddr,uint8_t taddr,uint8_t altps2h,bits256 pubAm,bits256 pubBn)
int32_t basilisk_alicescript(char *symbol,uint8_t *redeemscript,int32_t *redeemlenp,uint8_t *script,int32_t n,char *msigaddr,uint8_t taddr,uint8_t altps2h,bits256 pubAm,bits256 pubBn)
{
uint8_t p2sh160[20]; struct vin_info V;
memset(&V,0,sizeof(V));
@ -1523,7 +1523,7 @@ int32_t basilisk_alicescript(uint8_t *redeemscript,int32_t *redeemlenp,uint8_t *
memcpy(&V.signers[1].pubkey[1],pubBn.bytes,sizeof(pubBn)), V.signers[1].pubkey[0] = 0x03;
V.M = V.N = 2;
*redeemlenp = bitcoin_MofNspendscript(p2sh160,redeemscript,n,&V);
bitcoin_address(msigaddr,taddr,altps2h,p2sh160,sizeof(p2sh160));
bitcoin_address(symbol,msigaddr,taddr,altps2h,p2sh160,sizeof(p2sh160));
n = bitcoin_p2shspend(script,0,p2sh160);
//for (i=0; i<*redeemlenp; i++)
// printf("%02x",redeemscript[i]);
@ -1541,7 +1541,7 @@ char *basilisk_swap_Aspend(char *name,char *symbol,uint64_t Atxfee,uint8_t wifta
//char str[65];
//printf("pubAm.(%s)\n",bits256_str(str,pubAm));
//printf("pubBn.(%s)\n",bits256_str(str,pubBn));
spendlen = basilisk_alicescript(redeemscript,&redeemlen,spendscript,0,msigaddr,taddr,p2shtype,pubAm,pubBn);
spendlen = basilisk_alicescript(symbol,redeemscript,&redeemlen,spendscript,0,msigaddr,taddr,p2shtype,pubAm,pubBn);
if ( (txfee= Atxfee) == 0 )
{
if ( (txfee= LP_getestimatedrate(LP_coinfind(symbol)) * LP_AVETXSIZE) < LP_MIN_TXFEE )
@ -1883,13 +1883,13 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i
int32_t j; char coinaddr[64],checkaddr[64]; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 )
{
bitcoin_address(coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20);
bitcoin_address(coin->symbol,coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20);
if ( genflag != 0 && swap->I.iambob == 0 )
printf("basilisk_bobscripts_set WARNING: alice generating BOB tx\n");
if ( depositflag == 0 )
{
swap->bobpayment.I.spendlen = basilisk_bobscript(swap->bobpayment.I.rmd160,swap->bobpayment.redeemscript,&swap->bobpayment.I.redeemlen,swap->bobpayment.spendscript,0,&swap->bobpayment.I.locktime,&swap->bobpayment.I.secretstart,&swap->I,0);
bitcoin_address(swap->bobpayment.p2shaddr,coin->taddr,coin->p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen);
bitcoin_address(coin->symbol,swap->bobpayment.p2shaddr,coin->taddr,coin->p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen);
strcpy(swap->bobpayment.I.destaddr,swap->bobpayment.p2shaddr);
//LP_importaddress(coin->symbol,swap->bobpayment.I.destaddr);
//int32_t i; for (i=0; i<swap->bobpayment.I.redeemlen; i++)
@ -1927,7 +1927,7 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i
else
{
swap->bobdeposit.I.spendlen = basilisk_bobscript(swap->bobdeposit.I.rmd160,swap->bobdeposit.redeemscript,&swap->bobdeposit.I.redeemlen,swap->bobdeposit.spendscript,0,&swap->bobdeposit.I.locktime,&swap->bobdeposit.I.secretstart,&swap->I,1);
bitcoin_address(swap->bobdeposit.p2shaddr,coin->taddr,coin->p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen);
bitcoin_address(coin->symbol,swap->bobdeposit.p2shaddr,coin->taddr,coin->p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen);
strcpy(swap->bobdeposit.I.destaddr,swap->bobdeposit.p2shaddr);
//int32_t i; for (i=0; i<swap->bobdeposit.I.redeemlen; i++)
// printf("%02x",swap->bobdeposit.redeemscript[i]);
@ -1997,8 +1997,8 @@ int32_t basilisk_alicepayment_spend(struct basilisk_swap *swap,struct basilisk_r
void basilisk_alicepayment(struct basilisk_swap *swap,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn)
{
char coinaddr[64];
alicepayment->I.spendlen = basilisk_alicescript(alicepayment->redeemscript,&alicepayment->I.redeemlen,alicepayment->spendscript,0,alicepayment->I.destaddr,coin->taddr,coin->p2shtype,pubAm,pubBn);
bitcoin_address(coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20);
alicepayment->I.spendlen = basilisk_alicescript(coin->symbol,alicepayment->redeemscript,&alicepayment->I.redeemlen,alicepayment->spendscript,0,alicepayment->I.destaddr,coin->taddr,coin->p2shtype,pubAm,pubBn);
bitcoin_address(coin->symbol,coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20);
//printf("%s suppress.%d fee.%d\n",coinaddr,alicepayment->I.suppress_pubkeys,swap->myfee.I.suppress_pubkeys);
basilisk_rawtx_gen(swap->ctx,"alicepayment",swap->I.started,swap->persistent_pubkey33,0,1,alicepayment,alicepayment->I.locktime,alicepayment->spendscript,alicepayment->I.spendlen,swap->I.Atxfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr);
}
@ -2014,7 +2014,7 @@ int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *d
printf("error alice generating payment.%d\n",swap->alicepayment.I.spendlen);
else
{
bitcoin_address(swap->alicepayment.I.destaddr,coin->taddr,coin->p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen);
bitcoin_address(coin->symbol,swap->alicepayment.I.destaddr,coin->taddr,coin->p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen);
//LP_importaddress(coin->symbol,swap->alicepayment.I.destaddr);
strcpy(swap->alicepayment.p2shaddr,swap->alicepayment.I.destaddr);
retval = 0;
@ -2028,7 +2028,7 @@ int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *d
if ( swap->myfee.I.datalen == 0 )
{
printf("%s generate fee %.8f from.%s\n",coin->symbol,dstr(strcmp(coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : coin->txfee),coin->smartaddr);
bitcoin_address(coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20);
bitcoin_address(coin->symbol,coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20);
if ( basilisk_rawtx_gen(swap->ctx,"myfee",swap->I.started,swap->persistent_pubkey33,swap->I.iambob,1,&swap->myfee,swap->myfee.I.locktime,swap->myfee.spendscript,swap->myfee.I.spendlen,strcmp(coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr) == 0 )
{
printf("rawtxsend %s %.8f\n",coin->symbol,dstr(strcmp(coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : coin->txfee));
@ -2120,7 +2120,7 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da
swap->aliceclaim.utxotxid = swap->bobdeposit.I.signedtxid;
memcpy(swap->I.userdata_aliceclaim,userdata,len);
swap->I.userdata_aliceclaimlen = len;
bitcoin_address(swap->bobdeposit.p2shaddr,coin->taddr,coin->p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen);
bitcoin_address(coin->symbol,swap->bobdeposit.p2shaddr,coin->taddr,coin->p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen);
strcpy(swap->bobdeposit.I.destaddr,swap->bobdeposit.p2shaddr);
basilisk_dontforget_update(swap,&swap->bobdeposit);
//int32_t i; char str[65]; for (i=0; i<swap->bobdeposit.I.datalen; i++)
@ -2132,7 +2132,7 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da
memcpy(swap->aliceclaim.redeemscript,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen);
swap->aliceclaim.I.redeemlen = swap->bobdeposit.I.redeemlen;
memcpy(swap->aliceclaim.I.pubkey33,swap->persistent_pubkey33,33);
bitcoin_address(swap->aliceclaim.I.destaddr,coin->taddr,coin->pubtype,swap->persistent_pubkey33,33);
bitcoin_address(coin->symbol,swap->aliceclaim.I.destaddr,coin->taddr,coin->pubtype,swap->persistent_pubkey33,33);
retval = 0;
if ( (retval= basilisk_rawtx_sign(coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,swap,&swap->aliceclaim,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->bobdeposit.I.destaddr,coin->zcash)) == 0 )
{
@ -2160,7 +2160,7 @@ int32_t LP_verify_alicepayment(struct basilisk_swap *swap,uint8_t *data,int32_t
{
swap->bobspend.utxovout = 0;
swap->bobspend.utxotxid = swap->alicepayment.I.signedtxid = LP_broadcast_tx(swap->alicepayment.name,coin->symbol,swap->alicepayment.txbytes,swap->alicepayment.I.datalen);
bitcoin_address(swap->alicepayment.p2shaddr,coin->taddr,coin->p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen);
bitcoin_address(coin->symbol,swap->alicepayment.p2shaddr,coin->taddr,coin->p2shtype,swap->alicepayment.redeemscript,swap->alicepayment.I.redeemlen);
strcpy(swap->alicepayment.I.destaddr,swap->alicepayment.p2shaddr);
if ( bits256_nonz(swap->alicepayment.I.signedtxid) != 0 )
swap->aliceunconf = 1;
@ -2190,7 +2190,7 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da
for (i=0; i<32; i++)
revAm.bytes[i] = swap->I.privAm.bytes[31-i];
len = basilisk_swapuserdata(userdata,revAm,0,swap->I.myprivs[0],swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen);
bitcoin_address(swap->bobpayment.p2shaddr,coin->taddr,coin->p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen);
bitcoin_address(coin->symbol,swap->bobpayment.p2shaddr,coin->taddr,coin->p2shtype,swap->bobpayment.redeemscript,swap->bobpayment.I.redeemlen);
strcpy(swap->bobpayment.I.destaddr,swap->bobpayment.p2shaddr);
basilisk_dontforget_update(swap,&swap->bobpayment);
//LP_importaddress(coin->symbol,swap->bobpayment.I.destaddr);
@ -2204,7 +2204,7 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da
swap->I.userdata_alicespendlen = len;
retval = 0;
memcpy(swap->alicespend.I.pubkey33,swap->persistent_pubkey33,33);
bitcoin_address(swap->alicespend.I.destaddr,coin->taddr,coin->pubtype,swap->persistent_pubkey33,33);
bitcoin_address(coin->symbol,swap->alicespend.I.destaddr,coin->taddr,coin->pubtype,swap->persistent_pubkey33,33);
//char str[65],str2[65]; printf("bobpaid privAm.(%s) myprivs[0].(%s)\n",bits256_str(str,swap->I.privAm),bits256_str(str2,swap->I.myprivs[0]));
if ( (retval= basilisk_rawtx_sign(coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,swap,&swap->alicespend,&swap->bobpayment,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->alicepayment.I.destaddr,coin->zcash)) == 0 )
{

4
iguana/exchanges/LP_utxo.c

@ -635,8 +635,8 @@ cJSON *LP_balances(char *coinaddr)
strcpy(address,coin->smartaddr);
else
{
bitcoin_addr2rmd160(taddr,&addrtype,rmd160,coinaddr);
bitcoin_address(address,coin->taddr,coin->pubtype,rmd160,20);
bitcoin_addr2rmd160(coin->symbol,taddr,&addrtype,rmd160,coinaddr);
bitcoin_address(coin->symbol,address,coin->taddr,coin->pubtype,rmd160,20);
//printf("%s taddr.%d addrtype.%u %s -> %s [%c %c].%d\n",coin->symbol,taddr,addrtype,coinaddr,address,coinaddr[0],coinaddr[1],coinaddr[0] == 't' && (coinaddr[1] == '1' || coinaddr[1] == '3'));
}
if ( (retjson= LP_address_balance(coin,address,1)) != 0 )

16
iguana/exchanges/mm.c

@ -107,18 +107,18 @@ int main(int argc, const char * argv[])
if ( strstr(argv[0],"btc2kmd") != 0 && argv[1] != 0 )
{
uint8_t addrtype,rmd160[20],rmd160b[20]; char coinaddr[64],coinaddr2[64];
bitcoin_addr2rmd160(0,&addrtype,rmd160,(char *)argv[1]);
bitcoin_addr2rmd160("BTC",0,&addrtype,rmd160,(char *)argv[1]);
if ( addrtype == 0 )
{
bitcoin_address(coinaddr,0,60,rmd160,20);
bitcoin_addr2rmd160(0,&addrtype,rmd160b,coinaddr);
bitcoin_address(coinaddr2,0,0,rmd160b,20);
bitcoin_address("KMD",coinaddr,0,60,rmd160,20);
bitcoin_addr2rmd160("KMD",0,&addrtype,rmd160b,coinaddr);
bitcoin_address("BTC",coinaddr2,0,0,rmd160b,20);
}
else if ( addrtype == 60 )
{
bitcoin_address(coinaddr,0,0,rmd160,20);
bitcoin_addr2rmd160(0,&addrtype,rmd160b,coinaddr);
bitcoin_address(coinaddr2,0,60,rmd160b,20);
bitcoin_address("BTC",coinaddr,0,0,rmd160,20);
bitcoin_addr2rmd160("BTC",0,&addrtype,rmd160b,coinaddr);
bitcoin_address("KMD",coinaddr2,0,60,rmd160b,20);
}
printf("(%s) -> %s -> %s\n",(char *)argv[1],coinaddr,coinaddr2);
if ( strcmp((char *)argv[1],coinaddr2) != 0 )
@ -167,7 +167,7 @@ int main(int argc, const char * argv[])
for (i=0; i<1000000000; i++)
{
OS_randombytes(privkey.bytes,sizeof(privkey));
bitcoin_priv2pub(ctx,pubkey33,coinaddr,privkey,0,60);
bitcoin_priv2pub(ctx,"KMD",pubkey33,coinaddr,privkey,0,60);
if ( strncmp(coinaddr+1,argv[2],len-1) == 0 )
{
bitcoin_priv2wif(0,wifstr,privkey,188);

10
iguana/segwit_addr.c

@ -79,7 +79,7 @@ int bech32_encode(char *output,const char *hrp,const uint8_t *data,size_t data_l
}
i++;
}
printf("bech32_encode after hrp.(%s)\n",hrp);
//printf("bech32_encode after hrp.(%s)\n",hrp);
if ( i + chklen + 2 + data_len > 90 )
return 0;
while ( *hrp != 0 )
@ -102,14 +102,14 @@ int bech32_encode(char *output,const char *hrp,const uint8_t *data,size_t data_l
for (i = 0; i < chklen; ++i)
chk = PolyMod_step(chk,0);
chk ^= 1;
printf("bech32_encode emit >>>>>>> ");
//printf("bech32_encode emit >>>>>>> ");
for (i = 0; i < chklen; ++i) {
*output = charset[(chk >> ((chklen - 1 - i) * 5)) & 0x1f];
printf("%c",*output);
//printf("%c",*output);
output++;
}
*output = 0;
printf(" checksum %llx\n",(long long)chk);
//printf(" checksum %llx\n",(long long)chk);
return 1;
}
@ -174,7 +174,7 @@ int bech32_decode(char *hrp,uint8_t *data,size_t *data_len,const char *input)
printf("bech32_decode: have_lower.%d have_upper.%d\n",have_lower,have_upper);
return 0;
}
printf("checksum chk.%llx lower.%d upper.%d inputlen.%d\n",(long long)chk,have_lower,have_upper,(int32_t)input_len);
//printf("checksum chk.%llx lower.%d upper.%d inputlen.%d\n",(long long)chk,have_lower,have_upper,(int32_t)input_len);
return chk == 1;
}

Loading…
Cancel
Save