Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
9c80bff4b0
  1. 56
      iguana/exchanges/bitcoin.c
  2. 13
      iguana/iguana_pubkeys.c
  3. 14
      iguana/iguana_unspents.c
  4. 32
      iguana/iguana_wallet.c

56
iguana/exchanges/bitcoin.c

@ -265,24 +265,36 @@ bits256 bitcoin_pubkey33(uint8_t *data,bits256 privkey)
return(pubkey);
}
/*int32_t bitcoin_priv2wif(char *wifstr,uint8_t privkey[32],uint8_t addrtype)
int32_t bitcoin_priv2wif(char *wifstr,bits256 privkey,uint8_t addrtype)
{
uint8_t tmp[128]; char hexstr[67]; cstring *btc_addr;
memcpy(tmp,privkey,32);
tmp[32] = 1;
init_hexbytes_noT(hexstr,tmp,32);
if ( (btc_addr= base58_encode_check(addrtype,true,tmp,33)) != 0 )
{
strcpy(wifstr,btc_addr->str);
cstr_free(btc_addr,true);
}
printf("-> (%s) -> wif.(%s) addrtype.%02x\n",hexstr,wifstr,addrtype);
uint8_t data[128]; bits256 hash; int32_t i;
memcpy(data,privkey.bytes,sizeof(privkey));
data[32] = 1;
data[0] = addrtype;
hash = bits256_doublesha256(0,data,33);
for (i=0; i<4; i++)
data[33+i] = hash.bytes[31-i];
if ( bitcoin_base58encode(wifstr,data,33+4) == 0 )
return(-1);
char str[65]; printf("(%s) -> wif.(%s) addrtype.%02x\n",bits256_str(str,privkey),wifstr,addrtype);
return(0);
}
int32_t bitcoin_wif2priv(uint8_t *addrtypep,uint8_t privkey[32],char *wifstr)
/*int32_t bitcoin_wif2priv(uint8_t *addrtypep,uint8_t privkey[32],char *wifstr)
{
cstring *cstr; int32_t len = -1;
int32_t len = -1; bits256 hash; uint8_t buf[64];
if ( (len= bitcoin_base58decode(buf,wifstr)) >= 4 )
{
// validate with trailing hash, then remove hash
hash = bits256_doublesha256(0,buf,len - 4);
*addrtypep = *buf;
memcpy(rmd160,buf+1,20);
if ( (buf[len - 4]&0xff) == hash.bytes[31] && (buf[len - 3]&0xff) == hash.bytes[30] &&(buf[len - 2]&0xff) == hash.bytes[29] &&(buf[len - 1]&0xff) == hash.bytes[28] )
{
//printf("coinaddr.(%s) valid checksum\n",coinaddr);
return(20);
}
}
if ( (cstr= base58_decode_check(addrtypep,(const char *)wifstr)) != 0 )
{
init_hexbytes_noT((void *)privkey,(void *)cstr->str,cstr->len);
@ -291,13 +303,29 @@ int32_t bitcoin_wif2priv(uint8_t *addrtypep,uint8_t privkey[32],char *wifstr)
memcpy(privkey,cstr->str,cstr->len);
len = (int32_t)cstr->len;
char tmp[138];
btc_priv2wif(tmp,privkey,*addrtypep);
bitcoin_priv2wif(tmp,privkey,*addrtypep);
printf("addrtype.%02x wifstr.(%llx) len.%d\n",*addrtypep,*(long long *)privkey,len);
cstr_free(cstr,true);
}
return(len);
}*/
struct iguana_waddress *iguana_waddresscalc(uint8_t pubtype,uint8_t wiftype,struct iguana_waddress *addr,bits256 privkey)
{
memset(addr,0,sizeof(*addr));
addr->privkey = privkey;
bitcoin_pubkey33(addr->pubkey,addr->privkey);
calc_rmd160_sha256(addr->rmd160,addr->pubkey,33);
bitcoin_address(addr->coinaddr,pubtype,addr->rmd160,sizeof(addr->rmd160));
if ( bitcoin_priv2wif(addr->wifstr,addr->privkey,wiftype) == 0 )
{
addr->wiftype = wiftype;
addr->type = pubtype;
return(addr);
}
return(0);
}
int32_t bitcoin_sign(uint8_t *sig,int32_t maxlen,uint8_t *data,int32_t datalen,bits256 privkey)
{
uint32_t siglen; EC_KEY *KEY; uint8_t oddeven; bits256 pubkey; int32_t retval = -1;

13
iguana/iguana_pubkeys.c

@ -811,19 +811,6 @@ int32_t btc_pub65toaddr(char *coinaddr,uint8_t addrtype,char pubkey[131],uint8_t
return(retval);
}
struct iguana_waddress *iguana_waddresscalc(uint8_t pubtype,uint8_t wiftype,struct iguana_waddress *addr,bits256 privkey)
{
memset(addr,0,sizeof(*addr));
addr->privkey = privkey;
if ( btc_priv2pub(addr->pubkey,addr->privkey.bytes) == 0 && btc_priv2wif(addr->wifstr,addr->privkey.bytes,wiftype) == 0 && btc_pub2rmd(addr->rmd160,addr->pubkey) == 0 && bitcoin_address(addr->coinaddr,pubtype,addr->rmd160,10) != 0 )
{
addr->wiftype = wiftype;
addr->type = pubtype;
return(addr);
}
return(0);
}
int32_t iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,bits256 pub)
{
struct bp_key key; uint8_t pubkey[33];

14
iguana/iguana_unspents.c

@ -603,7 +603,7 @@ struct iguana_txid *iguana_txidfind(struct iguana_info *coin,int32_t *heightp,st
{
if ( (TXbits= ramchain->txbits) == 0 )
{
if ( coin->PREFETCHLAG >= 0 && coin->fastfind == 0 )
if ( coin->fastfind == 0 )
iguana_alloctxbits(coin,ramchain);
if ( (TXbits= ramchain->txbits) == 0 )
{
@ -613,7 +613,7 @@ struct iguana_txid *iguana_txidfind(struct iguana_info *coin,int32_t *heightp,st
}
if ( (T= ramchain->cacheT) == 0 )
{
if ( coin->PREFETCHLAG >= 0 && coin->fastfind == 0 )
if ( coin->fastfind == 0 )
iguana_alloccacheT(coin,ramchain);
if ( (T= ramchain->cacheT) == 0 )
T = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Toffset);
@ -868,8 +868,10 @@ static int _bignum_cmp(const void *a,const void *b)
uint32_t iguana_fastfindinit(struct iguana_info *coin)
{
int32_t i,j,iter,num,tablesize,*hashtable; uint8_t *sorted; char fname[1024];
if ( strcmp("BTC",coin->symbol) != 0 )
return(0);
//if ( strcmp("BTC",coin->symbol) != 0 )
// return(0);
if ( coin->fastfind != 0 )
return(coin->fastfind);
for (iter=0; iter<2; iter++)
{
for (i=0; i<0x100; i++)
@ -1868,6 +1870,8 @@ int32_t iguana_volatilesinit(struct iguana_info *coin)
coin->blocks.hwmchain = *block;
}
//printf("end volatilesinit\n");
if ( iguana_fastfindinit(coin) == 0 )//&& coin->PREFETCHLAG >= 0 )
iguana_fastfindcreate(coin);
return(coin->balanceswritten);
}
@ -1939,8 +1943,6 @@ void iguana_initfinal(struct iguana_info *coin,bits256 lastbundle)
hash2 = iguana_blockhash(coin,coin->balanceswritten * coin->chain->bundlesize);
if ( bits256_nonz(hash2) != 0 && (block= iguana_blockfind("initfinal",coin,hash2)) != 0 )
_iguana_chainlink(coin,block);
if ( iguana_fastfindinit(coin) == 0 && coin->PREFETCHLAG >= 0 )
iguana_fastfindcreate(coin);
}
int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi)

32
iguana/iguana_wallet.c

@ -143,6 +143,22 @@ struct iguana_waccount *iguana_waddressfind(struct iguana_info *coin,int32_t *in
return(0);
}
char *getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *account)
{
struct iguana_waccount *subset; struct iguana_waddress *waddr,*tmp; cJSON *retjson,*array;
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
if ( (subset= iguana_waccountfind(coin,account)) != 0 )
{
HASH_ITER(hh,subset->waddrs,waddr,tmp)
{
jaddistr(array,waddr->coinaddr);
}
} else jaddstr(retjson,"result","cant find account");
jadd(retjson,"addresses",array);
return(jprint(retjson,1));
}
int32_t iguana_addressvalidate(struct iguana_info *coin,uint8_t *addrtypep,uint8_t rmd160[20],char *address)
{
char checkaddr[64];
@ -226,22 +242,6 @@ char *getaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *coi
return(jprint(retjson,1));
}
char *getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *account)
{
struct iguana_waccount *subset; struct iguana_waddress *waddr,*tmp; cJSON *retjson,*array;
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
if ( (subset= iguana_waccountfind(coin,account)) != 0 )
{
HASH_ITER(hh,subset->waddrs,waddr,tmp)
{
jaddistr(array,waddr->coinaddr);
}
} else jaddstr(retjson,"result","cant find account");
jadd(retjson,"addresses",array);
return(jprint(retjson,1));
}
char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,double amount,char *comment,char *comment2)
{
uint8_t addrtype,rmd160[20];

Loading…
Cancel
Save