jl777 7 years ago
parent
commit
9be29c85de
  1. 16
      iguana/exchanges/LP_bitcoin.c
  2. 8
      iguana/exchanges/LP_include.h
  3. 8
      iguana/exchanges/LP_nativeDEX.c
  4. 10
      iguana/segwit_addr.c

16
iguana/exchanges/LP_bitcoin.c

@ -2020,7 +2020,21 @@ char *bitcoind_passthrut(char *coinstr,char *serverport,char *userpass,char *met
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;
bits256 hash; uint8_t *buf,_buf[26],data5[128]; char prefixaddr[64],hrp[64]; int32_t len,len5,offset;
if ( strcmp(symbol,"BCH") == 0 && strlen(coinaddr) == 42 )
{
strcpy(prefixaddr,"bitcoincash:");
strcat(prefixaddr,coinaddr);
if ( bech32_decode(hrp,data5,&len5,prefixaddr) == 0 )
{
printf("bitcoin_addr2rmd160 bech32_decode error.(%s)\n",coinaddr);
return(0);
}
}
else if ( strcmp(symbol,"GRS") == 0 )
{
return(0);
}
offset = 1 + (taddr != 0);
memset(rmd160,0,20);
*addrtypep = 0;

8
iguana/exchanges/LP_include.h

@ -353,7 +353,7 @@ struct LP_address
int64_t balance,total,instantdex_credits;
uint32_t timestamp,n,unspenttime;
int32_t unspentheight;
char coinaddr[40];
char coinaddr[64];
uint8_t pubsecp[33],didinstantdex;
};
@ -559,8 +559,8 @@ int64_t LP_outpoint_amount(char *symbol,bits256 txid,int32_t vout);
void LP_listunspent_query(char *symbol,char *coinaddr);
int32_t bitcoin_priv2wif(uint8_t wiftaddr,char *wifstr,bits256 privkey,uint8_t addrtype);
int bech32_convert_bits(uint8_t *out,size_t *outlen,int outbits,const uint8_t *in,size_t inlen,int inbits,int pad);
int bech32_decode(char *hrp,uint8_t *data,size_t *data_len,const char *input);
int bech32_encode(char *output,const char *hrp,const uint8_t *data,size_t data_len);
int bech32_convert_bits(uint8_t *out,int32_t *outlen,int outbits,const uint8_t *in,int32_t inlen,int inbits,int pad);
int bech32_decode(char *hrp,uint8_t *data,int32_t *data_len,const char *input);
int bech32_encode(char *output,const char *hrp,const uint8_t *data,int32_t data_len);
#endif

8
iguana/exchanges/LP_nativeDEX.c

@ -738,13 +738,19 @@ void bech32_tests()
//char *test = "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a";
char *test = "bitcoincash:qr95sy3j9xwd2ap32xkykttr4cvcu7as4y0qverfuy";
//char *test = "prefix:x64nx6hz";
uint8_t data[82],data2[64],rmd160[21],addrtype; char rebuild[92],hrp[84]; size_t data_len,data_len2; int32_t i;
uint8_t data[82],data2[64],rmd160[21],addrtype; char rebuild[92],hrp[84]; int32_t data_len,data_len2; int32_t i;
if ( bech32_decode(hrp,data,&data_len,test) == 0 )
{
printf("bech32_decode fails: '%s'\n",test);
}
else
{
data_len2 = 0;
if ( bech32_convert_bits(data2,&data_len2,8,data,data_len,5,0) == 0 )
printf("error converting data5\n");
for (i=0; i<data_len2; i++)
printf("%02x",data2[i]);
printf(" compacted 5's -> %d\n",data_len2);
bitcoin_addr2rmd160("BTC",0,&addrtype,rmd160+1,"1KXrWXciRDZUpQwQmuM1DbwsKDLYAYsVLR");
for (i=0; i<data_len; i++)
printf("%02x",data[i]);

10
iguana/segwit_addr.c

@ -39,14 +39,14 @@
uint64_t PolyMod_step(uint64_t c,uint8_t d)
{
uint8_t c0 = c >> 35;
printf("step (%llx) + %d -> ",(long long)c,d);
//printf("step (%llx) + %d -> ",(long long)c,d);
c = ((c & 0x07ffffffff) << 5) ^ d;
if (c0 & 0x01) c ^= 0x98f2bc8e61;
if (c0 & 0x02) c ^= 0x79b76d99e2;
if (c0 & 0x04) c ^= 0xf33e5fb3c4;
if (c0 & 0x08) c ^= 0xae2eabe2a8;
if (c0 & 0x10) c ^= 0x1e4f43e470;
printf("%llx\n",(long long)c);
//printf("%llx\n",(long long)c);
return(c);
}
@ -61,7 +61,7 @@ const int8_t charset_rev[128] = {
-1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1, 1, 0,
3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1};
int bech32_encode(char *output,const char *hrp,const uint8_t *data,size_t data_len)
int bech32_encode(char *output,const char *hrp,const uint8_t *data,int32_t data_len)
{
uint64_t chk = 1; size_t i = 0; int32_t ch,chklen = 8;
while ( hrp[i] != 0 )
@ -113,7 +113,7 @@ int bech32_encode(char *output,const char *hrp,const uint8_t *data,size_t data_l
return 1;
}
int bech32_decode(char *hrp,uint8_t *data,size_t *data_len,const char *input)
int bech32_decode(char *hrp,uint8_t *data,int32_t *data_len,const char *input)
{
uint64_t chk = 1; int32_t chklen = 8; size_t i,hrp_len,input_len = strlen(input);
int have_lower = 0, have_upper = 0;
@ -178,7 +178,7 @@ int bech32_decode(char *hrp,uint8_t *data,size_t *data_len,const char *input)
return chk == 1;
}
int bech32_convert_bits(uint8_t *out,size_t *outlen,int outbits,const uint8_t *in,size_t inlen,int inbits,int pad)
int bech32_convert_bits(uint8_t *out,int32_t *outlen,int outbits,const uint8_t *in,int32_t inlen,int inbits,int pad)
{
uint32_t val = 0;
int bits = 0;

Loading…
Cancel
Save