Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
142d7d194e
  1. 23
      crypto777/iguana_utils.c
  2. 3
      iguana/swaps/iguana_BTCswap.c

23
crypto777/iguana_utils.c

@ -100,25 +100,25 @@ int32_t bits256_cmp(bits256 a,bits256 b)
return(0); return(0);
} }
bits256 bits256_lshift(bits256 x) bits256 bits256_rshift(bits256 x)
{ {
int32_t i,carry,prevcarry = 0; uint64_t mask = (1LL << 63); int32_t i; uint64_t carry,prevcarry = 0;
for (i=0; i<4; i++) for (i=3; i>=0; i--)
{ {
carry = ((mask & x.ulongs[i]) != 0); carry = (1 & x.ulongs[i]) << 63;
x.ulongs[i] = (x.ulongs[i] << 1) | prevcarry; x.ulongs[i] = prevcarry | (x.ulongs[i] >> 1);
prevcarry = carry; prevcarry = carry;
} }
return(x); return(x);
} }
bits256 bits256_rshift(bits256 x) bits256 bits256_lshift(bits256 x)
{ {
int32_t i; uint64_t carry,prevcarry = 0; int32_t i,carry,prevcarry = 0; uint64_t mask = (1LL << 63);
for (i=3; i>=0; i--) for (i=0; i<4; i++)
{ {
carry = (1 & x.ulongs[i]) << 63; carry = ((mask & x.ulongs[i]) != 0);
x.ulongs[i] = prevcarry | (x.ulongs[i] >> 1); x.ulongs[i] = (x.ulongs[i] << 1) | prevcarry;
prevcarry = carry; prevcarry = carry;
} }
return(x); return(x);
@ -126,12 +126,13 @@ bits256 bits256_rshift(bits256 x)
bits256 bits256_from_compact(uint32_t c) bits256 bits256_from_compact(uint32_t c)
{ {
uint32_t nbytes,nbits,i; bits256 x; uint32_t nbytes,nbits,i; bits256 x;
memset(x.bytes,0,sizeof(x)); memset(x.bytes,0,sizeof(x));
nbytes = (c >> 24) & 0xFF; nbytes = (c >> 24) & 0xFF;
nbits = (8 * (nbytes - 3)); nbits = (8 * (nbytes - 3));
x.ulongs[0] = c & 0xFFFFFF; x.ulongs[0] = c & 0xFFFFFF;
for (i=0; i<nbits; i++) // horrible inefficient for (i=0; i<nbits; i++)
x = bits256_lshift(x); x = bits256_lshift(x);
return(x); return(x);
} }

3
iguana/swaps/iguana_BTCswap.c

@ -159,7 +159,7 @@ struct bitcoin_statetx *instantdex_signtx(struct supernet_info *myinfo,struct ig
if ( (signedtx= iguana_signrawtx(myinfo,coin,&signedtxid,&completed,vins,rawtx,privkey)) != 0 ) if ( (signedtx= iguana_signrawtx(myinfo,coin,&signedtxid,&completed,vins,rawtx,privkey)) != 0 )
{ {
iguana_unspentslock(myinfo,coin,vins); iguana_unspentslock(myinfo,coin,vins);
tx = calloc(1,sizeof(*tx) + strlen(rawtx) + 1); tx = calloc(1,sizeof(*tx) + strlen(signedtx) + 1);
strcpy(tx->txbytes,signedtx); strcpy(tx->txbytes,signedtx);
tx->txid = signedtxid; tx->txid = signedtxid;
printf("%s feetx.%s\n",myside != 0 ? "BOB" : "ALICE",signedtx); printf("%s feetx.%s\n",myside != 0 ? "BOB" : "ALICE",signedtx);
@ -171,6 +171,7 @@ struct bitcoin_statetx *instantdex_signtx(struct supernet_info *myinfo,struct ig
if ( flag == 2 ) if ( flag == 2 )
{ {
free_json(vins); free_json(vins);
printf("Free rawtx\n");
free(rawtx); free(rawtx);
} }
free(retstr); free(retstr);

Loading…
Cancel
Save