jl777 7 years ago
parent
commit
3e86a75e6f
  1. 36
      iguana/exchanges/LP_utxo.c
  2. 27
      iguana/exchanges/mm.c

36
iguana/exchanges/LP_utxo.c

@ -275,6 +275,29 @@ bits256 iguana_merkle(bits256 *tree,int32_t txn_count)
return(tree[n]);
}
bits256 validate_merkle(int32_t pos,bits256 txid,cJSON *proofarray,int32_t proofsize)
{
int32_t i; uint8_t serialized[sizeof(bits256) * 2]; bits256 hash,proof;
hash = txid;
for (i=0; i<proofsize; i++)
{
proof = jbits256i(proofarray,i);
if ( (pos & 1) == 0 )
{
iguana_rwbignum(1,&serialized[0],sizeof(hash),hash.bytes);
iguana_rwbignum(1,&serialized[sizeof(hash)],sizeof(proof),proof.bytes);
}
else
{
iguana_rwbignum(1,&serialized[0],sizeof(proof),proof.bytes);
iguana_rwbignum(1,&serialized[sizeof(hash)],sizeof(hash),hash.bytes);
}
hash = bits256_doublesha256(0,serialized,sizeof(serialized));
pos >>= 1;
}
return(hash);
}
cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret)
{
cJSON *array,*item,*merkobj,*merkles; int32_t n,i,m; uint64_t total; struct LP_address *ap=0,*atmp; struct LP_address_utxo *up,*tmp; struct electrum_info *ep,*backupep=0;
@ -294,19 +317,14 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum
{
if ( up->spendheight <= 0 && up->U.height > 0 )
{
if ( 0 && up->SPV == 0 && up->U.height > 0 )
if ( 1 && up->SPV == 0 && up->U.height > 0 )
{
if ( (merkobj= electrum_getmerkle(coin->symbol,backupep,&merkobj,up->U.txid,up->U.height)) != 0 )
{
char str[65],str2[65]; bits256 tree[256],roothash;
char str[65],str2[65]; bits256 roothash;
memset(roothash.bytes,0,sizeof(roothash));
if ( (merkles= jarray(&m,merkobj,"merkle")) != 0 && n > 0 && n < 15 )
{
tree[0] = up->U.txid;
for (i=0; i<m; i++)
tree[i+1] = jbits256i(merkles,i);
roothash = iguana_merkle(tree,m);
}
if ( (merkles= jarray(&m,merkobj,"merkle")) != 0 )
roothash = validate_merkle(jint(merkobj,"pos"),up->U.txid,merkles,m);
printf("MERK %s ht.%d -> %s root.(%s)\n",bits256_str(str,up->U.txid),up->U.height,jprint(merkobj,0),bits256_str(str2,roothash));
free_json(merkobj);
}

27
iguana/exchanges/mm.c

@ -811,29 +811,7 @@ if odd -> right, else left
then /= 2
*/
bits256 validate_merkle(int32_t pos,bits256 txid,bits256 *proof,int32_t proofsize)
{
int32_t i; uint8_t serialized[sizeof(bits256) * 2]; bits256 hash;
hash = txid;
for (i=0; i<proofsize; i++)
{
if ( (pos & 1) == 0 )
{
iguana_rwbignum(1,&serialized[0],sizeof(hash),hash.bytes);
iguana_rwbignum(1,&serialized[sizeof(hash)],sizeof(proof[i]),proof[i].bytes);
}
else
{
iguana_rwbignum(1,&serialized[0],sizeof(proof[i]),proof[i].bytes);
iguana_rwbignum(1,&serialized[sizeof(hash)],sizeof(hash),hash.bytes);
}
hash = bits256_doublesha256(0,serialized,sizeof(serialized));
pos >>= 1;
}
return(hash);
}
void testmerk()
/*void testmerk()
{
bits256 tree[256],roothash,txid; int32_t i; char str[65];
memset(tree,0,sizeof(tree));
@ -860,12 +838,11 @@ void testmerk()
decode_hex(txid.bytes,32,"c007e9c1881a83be453cb6ed3d1bd3bda85efd3b5ce60532c2e20ae3f8a82543");
roothash = validate_merkle(2,txid,tree,2);
printf("validate 2: %s\n",bits256_str(str,roothash));
}
}*/
void LP_main(void *ptr)
{
char *passphrase; double profitmargin; uint16_t port; cJSON *argjson = ptr;
testmerk();
if ( (passphrase= jstr(argjson,"passphrase")) != 0 )
{
profitmargin = jdouble(argjson,"profitmargin");

Loading…
Cancel
Save