Browse Source

Merge pull request #662 from jl777/jl777

Jl777
patch-3
jl777 7 years ago
committed by GitHub
parent
commit
3d37551d4e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      iguana/exchanges/LP_bitcoin.c
  2. 7
      iguana/exchanges/LP_commands.c
  3. 2
      iguana/exchanges/LP_include.h
  4. 40
      iguana/exchanges/LP_privkey.c
  5. 6
      iguana/exchanges/LP_rpc.c
  6. 151
      iguana/exchanges/LP_transaction.c
  7. 2
      iguana/exchanges/coins
  8. 6
      iguana/exchanges/opreturn
  9. 5
      iguana/exchanges/opreturndecrypt
  10. 2
      iguana/exchanges/stats.c

36
iguana/exchanges/LP_bitcoin.c

@ -2066,7 +2066,7 @@ int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_
memset(rmd160,0,20);
if ( coinaddr == 0 || coinaddr[0] == 0 )
return(0);
if ( coinaddr[0] == '0' && coinaddr[1] == 'x' && is_hexstr(coinaddr+2,0) == 40 )
if ( coinaddr[0] == '0' && coinaddr[1] == 'x' && is_hexstr(coinaddr+2,0) == 40 ) // for ETH
{
decode_hex(rmd160,20,coinaddr+2); // not rmd160 hash but hopefully close enough;
return(20);
@ -2101,12 +2101,12 @@ int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_
hash = bits256_calcaddrhash(symbol,buf,20+offset);
*addrtypep = (taddr == 0) ? *buf : buf[1];
memcpy(rmd160,buf+offset,20);
if ( strcmp(symbol,"GRS") != 0 && (buf[20+offset]&0xff) == hash.bytes[31] && (buf[21+offset]&0xff) == hash.bytes[30] && (buf[22+offset]&0xff) == hash.bytes[29] && (buf[23+offset]&0xff) == hash.bytes[28] )
if ( (buf[20+offset]&0xff) == hash.bytes[31] && (buf[21+offset]&0xff) == hash.bytes[30] && (buf[22+offset]&0xff) == hash.bytes[29] && (buf[23+offset]&0xff) == hash.bytes[28] )
{
//printf("coinaddr.(%s) valid checksum addrtype.%02x\n",coinaddr,*addrtypep);
return(20);
}
else if ( strcmp(symbol,"GRS") == 0 && (buf[20+offset]&0xff) == hash.bytes[0] && (buf[21+offset]&0xff) == hash.bytes[1] && (buf[22+offset]&0xff) == hash.bytes[2] && (buf[23+offset]&0xff) == hash.bytes[3] )
else if ( (strcmp(symbol,"GRS") == 0 || strcmp(symbol,"SMART") == 0) && (buf[20+offset]&0xff) == hash.bytes[0] && (buf[21+offset]&0xff) == hash.bytes[1] && (buf[22+offset]&0xff) == hash.bytes[2] && (buf[23+offset]&0xff) == hash.bytes[3] )
return(20);
else
{
@ -2187,7 +2187,7 @@ char *bitcoin_address(char *symbol,char *coinaddr,uint8_t taddr,uint8_t addrtype
data[1] = addrtype;
} else data[0] = addrtype;
hash = bits256_calcaddrhash(symbol,data,20+offset);
if ( strcmp(symbol,"GRS") != 0 )
if ( strcmp(symbol,"GRS") != 0 && strcmp(symbol,"SMART") != 0 )
{
for (i=0; i<4; i++)
data[20+offset+i] = hash.bytes[31-i];
@ -2199,6 +2199,7 @@ char *bitcoin_address(char *symbol,char *coinaddr,uint8_t taddr,uint8_t addrtype
}
if ( (coinaddr= bitcoin_base58encode(coinaddr,data,24+offset)) != 0 )
{
//printf("coinaddr.%p %s\n",coinaddr,coinaddr!=0?coinaddr:"null");
} else printf("null coinaddr taddr.%02x\n",taddr);
return(coinaddr);
}
@ -2251,7 +2252,7 @@ int32_t base58encode_checkbuf(char *symbol,uint8_t taddr,uint8_t addrtype,uint8_
//for (i=0; i<32; i++)
// printf("%02x",hash.bytes[i]);
//printf(" checkhash\n");
if ( strcmp(symbol,"GRS") != 0 )
if ( strcmp(symbol,"GRS") != 0 && strcmp(symbol,"SMART") != 0 )
{
for (i=0; i<4; i++)
data[data_len+i+offset] = hash.bytes[31-i];
@ -2287,7 +2288,7 @@ int32_t bitcoin_wif2priv(char *symbol,uint8_t wiftaddr,uint8_t *addrtypep,bits25
ptr = buf;
hash = bits256_calcaddrhash(symbol,ptr,len - 4);
*addrtypep = (wiftaddr == 0) ? *ptr : ptr[1];
if ( strcmp(symbol,"GRS") != 0 && (ptr[len - 4]&0xff) == hash.bytes[31] && (ptr[len - 3]&0xff) == hash.bytes[30] &&(ptr[len - 2]&0xff) == hash.bytes[29] && (ptr[len - 1]&0xff) == hash.bytes[28] )
if ( (ptr[len - 4]&0xff) == hash.bytes[31] && (ptr[len - 3]&0xff) == hash.bytes[30] &&(ptr[len - 2]&0xff) == hash.bytes[29] && (ptr[len - 1]&0xff) == hash.bytes[28] )
{
//int32_t i; for (i=0; i<len; i++)
// printf("%02x ",ptr[i]);
@ -2295,7 +2296,7 @@ int32_t bitcoin_wif2priv(char *symbol,uint8_t wiftaddr,uint8_t *addrtypep,bits25
//printf("wifstr.(%s) valid len.%d\n",wifstr,len);
return(32);
}
else if ( strcmp(symbol,"GRS") == 0 && (ptr[len - 4]&0xff) == hash.bytes[0] && (ptr[len - 3]&0xff) == hash.bytes[1] &&(ptr[len - 2]&0xff) == hash.bytes[2] && (ptr[len - 1]&0xff) == hash.bytes[3] )
else if ( (strcmp(symbol,"GRS") == 0 || strcmp(symbol,"SMART") == 0) && (ptr[len - 4]&0xff) == hash.bytes[0] && (ptr[len - 3]&0xff) == hash.bytes[1] &&(ptr[len - 2]&0xff) == hash.bytes[2] && (ptr[len - 1]&0xff) == hash.bytes[3] )
return(32);
else if ( 0 ) // gets errors when len is 37
{
@ -2309,14 +2310,16 @@ int32_t bitcoin_wif2priv(char *symbol,uint8_t wiftaddr,uint8_t *addrtypep,bits25
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];
bits256 privkey; int32_t len; uint8_t addrtype,pubkey33[33];
if ( strcmp(symbol,"BCH") == 0 )
symbol = "BTC";
coinaddr[0] = 0;
if ( bitcoin_wif2priv(symbol,wiftaddr,&addrtype,&privkey,wifstr) == sizeof(privkey) )
if ( (len= bitcoin_wif2priv(symbol,wiftaddr,&addrtype,&privkey,wifstr)) == sizeof(privkey) )
{
bitcoin_priv2pub(ctx,symbol,pubkey33,coinaddr,privkey,taddr,pubtype);
}
//printf("priv2pub returns.(%s)\n",coinaddr);
return(0);
} else printf("wif2priv returns len.%d\n",len);
return(-1);
}
@ -3412,12 +3415,13 @@ bits256 bitcoin_sigtxid(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2sht
sbtcflag = 1;
else if ( strcmp(symbol,"BTCP") == 0 )
btcpflag = 1;
// else printf("normal symbol.(%s)\n",symbol);
if ( ((hashtype & ~SIGHASH_FORKID) & 0xff) != SIGHASH_ALL )
{
printf("currently only SIGHASH_ALL supported, not %d\n",hashtype);
return(sigtxid);
}
if ( (hashtype & SIGHASH_FORKID) == 0 || sbtcflag != 0 )
if ( (hashtype & SIGHASH_FORKID) == 0 || sbtcflag != 0 || btcpflag != 0 )
{
for (i=0; i<dest.tx_in; i++)
{
@ -3449,7 +3453,7 @@ bits256 bitcoin_sigtxid(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2sht
if ( btcpflag != 0 )
{
hashtype = 0x2a41;
printf("BTCP detected: hardcode hashtype to %08x\n",hashtype);
//printf("BTCP detected: hardcode hashtype to %08x\n",hashtype);
}
len += iguana_rwnum(1,&serialized[len],sizeof(hashtype),&hashtype);
if ( sbtcflag != 0 )
@ -3533,10 +3537,10 @@ bits256 bitcoin_sigtxid(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2sht
len += iguana_voutparse(1,&serialized[len],&dest.vouts[i]);
outputhash = bits256_doublesha256(0,serialized,len);
char str[65]; printf("prevouthash.%s ",bits256_str(str,prevouthash));
printf("seqhash.%s ",bits256_str(str,seqhash));
printf("outputhash.%s ",bits256_str(str,outputhash));
printf("vini.%d prev.%s/v%d\n",vini,bits256_str(str,dest.vins[vini].prev_hash),dest.vins[vini].prev_vout);
//char str[65]; printf("prevouthash.%s ",bits256_str(str,prevouthash));
//printf("seqhash.%s ",bits256_str(str,seqhash));
//printf("outputhash.%s ",bits256_str(str,outputhash));
//printf("vini.%d prev.%s/v%d\n",vini,bits256_str(str,dest.vins[vini].prev_hash),dest.vins[vini].prev_vout);
/*01000000
997c1040c67ee2f9ab21abf7457f7aec4503970e974e532b6578f326c270b7eb
445066705e799022b7095f7ceca255149f43acfc47e7f59e551f7bce2930b13b

7
iguana/exchanges/LP_commands.c

@ -166,6 +166,7 @@ instantdex_deposit(weeks, amount, broadcast=1)\n\
instantdex_claim()\n\
timelock(coin, duration, destaddr=(tradeaddr), amount)\n\
unlockedspend(coin, txid)\n\
opreturndecrypt(coin, txid, passphrase)\n\
getendpoint()\n\
jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
\"}"));
@ -560,6 +561,10 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{
return(LP_timelock(coin,juint(argjson,"duration"),jstr(argjson,"destaddr"),jdouble(argjson,"amount")*SATOSHIDEN));
}
else if ( strcmp(method,"opreturndecrypt") == 0 )
{
return(LP_opreturndecrypt(ctx,coin,jbits256(argjson,"txid"),jstr(argjson,"passphrase")));
}
else if ( strcmp(method,"unlockedspend") == 0 )
{
return(LP_unlockedspend(ctx,coin,jbits256(argjson,"txid")));
@ -572,7 +577,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
if ( jobj(argjson,"outputs") == 0 )
if ( jobj(argjson,"outputs") == 0 && jstr(argjson,"opreturn") == 0 )
return(clonestr("{\"error\":\"withdraw needs to have outputs\"}"));
else return(LP_withdraw(ptr,argjson));
}

2
iguana/exchanges/LP_include.h

@ -508,6 +508,8 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re
int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_info *ep,bits256 txid,int32_t height);
cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr,bits256 reftxid);
cJSON *LP_myzdebits();
int32_t LP_opreturn_decrypt(uint16_t *ind16p,uint8_t *decoded,uint8_t *encoded,int32_t encodedlen,char *passphrase);
int32_t LP_opreturn_encrypt(uint8_t *dest,int32_t maxsize,uint8_t *data,int32_t datalen,char *passphrase,uint16_t ind16);
void LP_pendswap_add(uint32_t expiration,uint32_t requestid,uint32_t quoteid);
int32_t _LP_utxos_remove(bits256 txid,int32_t vout);
int32_t LP_utxos_remove(bits256 txid,int32_t vout);

40
iguana/exchanges/LP_privkey.c

@ -536,7 +536,7 @@ int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t
int32_t i; for (i=0; i<msglen; i++)
printf("%02x",encoded[i]);
printf(" encoded.%d\n",msglen);
return(msglen);
return(msglen);
}
uint8_t *JPG_decrypt(uint16_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES],uint8_t *encoded,bits256 privkey)
@ -552,11 +552,14 @@ uint8_t *JPG_decrypt(uint16_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTE
cipherlen = msglen - (len + crypto_box_NONCEBYTES);
if ( cipherlen > 0 && cipherlen <= JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES )
{
//int32_t i; for (i=0; i<cipherlen; i++)
// printf("%02x",cipher[i]);
//printf(" cipherlen\n");
if ( (extracted= _SuperNET_decipher(nonce,cipher,space,cipherlen,pubkey,privkey)) != 0 )
{
int32_t i; for (i=0; i<msglen; i++)
printf("%02x",encoded[i]);
printf(" restored\n");
//int32_t i; for (i=0; i<msglen; i++)
// printf("%02x",encoded[i]);
//printf(" restored\n");
msglen = (cipherlen - crypto_box_ZEROBYTES);
*recvlenp = msglen;
*indp = ind;
@ -565,6 +568,35 @@ uint8_t *JPG_decrypt(uint16_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTE
return(extracted);
}
int32_t LP_opreturn_decrypt(uint16_t *ind16p,uint8_t *decoded,uint8_t *encoded,int32_t encodedlen,char *passphrase)
{
bits256 privkey; int32_t msglen; uint8_t *extracted,space[JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES];
vcalc_sha256(0,privkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
msglen = ((int32_t)encoded[1] << 8) | encoded[0];
*ind16p = ((int32_t)encoded[3] << 8) | encoded[2];
if ( msglen == encodedlen && (extracted= JPG_decrypt(ind16p,&msglen,space,encoded,privkey)) != 0 )
{
memcpy(decoded,extracted,msglen);
return(msglen);
} else return(-1);
}
int32_t LP_opreturn_encrypt(uint8_t *dest,int32_t maxsize,uint8_t *data,int32_t datalen,char *passphrase,uint16_t ind16)
{
bits256 privkey; int32_t len; uint8_t encoded[JPG_ENCRYPTED_MAXSIZE];
vcalc_sha256(0,privkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
if ( (len= JPG_encrypt(ind16,encoded,data,datalen,privkey)) > 0 )
{
//printf("datalen.%d -> len.%d max.%d\n",datalen,len,maxsize);
if ( len <= maxsize )
{
memcpy(dest,encoded,len);
return(len);
}
}
return(-1);
}
// from https://github.com/owencm/C-Steganography-Framework
#include "../../crypto777/jpeg/cdjpeg.h" // Common decls for compressing and decompressing jpegs

6
iguana/exchanges/LP_rpc.c

@ -540,7 +540,8 @@ int32_t LP_importaddress(char *symbol,char *address)
return(-2);
coin = LP_coinfind(symbol);
if ( coin == 0 )
return(-2);
return(-3);
//printf("import.(%s %s)\n",symbol,address);
if ( coin->electrum != 0 )
{
/*if ( (retjson= electrum_address_subscribe(symbol,coin->electrum,&retjson,address)) != 0 )
@ -554,6 +555,7 @@ int32_t LP_importaddress(char *symbol,char *address)
{
if ( (validatejson= LP_validateaddress(symbol,address)) != 0 )
{
//printf("validated.(%s)\n",jprint(validatejson,0));
if ( (isvalid= is_cJSON_True(jobj(validatejson,"isvalid")) != 0) != 0 )
{
if ( is_cJSON_True(jobj(validatejson,"iswatchonly")) != 0 || is_cJSON_True(jobj(validatejson,"ismine")) != 0 )
@ -561,6 +563,7 @@ int32_t LP_importaddress(char *symbol,char *address)
}
free_json(validatejson);
}
//printf("%s (%s) isvalid.%d doneflag.%d\n",symbol,address,isvalid,doneflag);
if ( isvalid == 0 )
return(-1);
if ( doneflag != 0 )
@ -590,7 +593,6 @@ cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag)
ctx = bitcoin_ctx();
bitcoin_wif2addr(ctx,symbol,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr);
#ifdef LP_DONT_IMPORTPRIVKEY
//bitcoin_wif2addr(ctx,symbol,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr);
if ( LP_importaddress(symbol,address) < 0 )
{
printf("%s importaddress %s from %s failed, isvalid.%d\n",symbol,address,wifstr,bitcoin_validaddress(symbol,coin->taddr,coin->pubtype,coin->p2shtype,address));

151
iguana/exchanges/LP_transaction.c

@ -1226,10 +1226,10 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_
return(n);
}
char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_info *coin,struct vin_info *V,int32_t max,bits256 privkey,cJSON *outputs,cJSON *vins,cJSON *privkeys,int64_t txfee,bits256 utxotxid,int32_t utxovout,uint32_t locktime,char *opretstr)
char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_info *coin,struct vin_info *V,int32_t max,bits256 privkey,cJSON *outputs,cJSON *vins,cJSON *privkeys,int64_t txfee,bits256 utxotxid,int32_t utxovout,uint32_t locktime,char *opretstr,char *passphrase)
{
static void *ctx;
cJSON *txobj,*item; uint8_t addrtype,rmd160[20],script[8192],spendscript[256]; char *coinaddr,*rawtxbytes,*scriptstr; bits256 txid; uint32_t timestamp; int64_t change=0,adjust=0,total,value,amount = 0; int32_t i,len,dustcombine,scriptlen,spendlen,suppress_pubkeys,ignore_cltverr,numvouts=0,numvins=0,numutxos=0; struct LP_address_utxo *utxos[LP_MAXVINS*256]; struct LP_address *ap;
cJSON *txobj,*item; uint8_t addrtype,rmd160[20],data[8192+64],script[8192],spendscript[256]; char *coinaddr,*rawtxbytes,*scriptstr; bits256 txid; uint32_t crc32,timestamp; int64_t change=0,adjust=0,total,value,amount = 0; int32_t origspendlen=0,i,offset,len,dustcombine,scriptlen,spendlen,suppress_pubkeys,ignore_cltverr,numvouts=0,numvins=0,numutxos=0; struct LP_address_utxo *utxos[LP_MAXVINS*256]; struct LP_address *ap;
if ( ctx == 0 )
ctx = bitcoin_ctx();
*numvinsp = 0;
@ -1335,6 +1335,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
else
{
printf("custom script.%d too long %d\n",i,spendlen);
free_json(txobj);
return(0);
}
}
@ -1346,7 +1347,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
else spendlen = bitcoin_p2shspend(spendscript,0,rmd160);
if ( i == numvouts-1 && strcmp(coinaddr,coin->smartaddr) == 0 && change != 0 )
{
printf("combine last vout %.8f with change %.8f\n",dstr(value+adjust),dstr(change));
//printf("combine last vout %.8f with change %.8f\n",dstr(value+adjust),dstr(change));
value += change;
change = 0;
}
@ -1370,8 +1371,22 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
if ( opretstr != 0 )
{
spendlen = (int32_t)strlen(opretstr) >> 1;
if ( spendlen < sizeof(script) )
if ( spendlen < sizeof(script)-60 )
{
if ( passphrase != 0 && passphrase[0] != 0 )
{
decode_hex(data,spendlen,opretstr);
offset = 2 + (spendlen >= 16);
origspendlen = spendlen;
crc32 = calc_crc32(0,data,spendlen);
spendlen = LP_opreturn_encrypt(&script[offset],(int32_t)sizeof(script)-offset,data,spendlen,passphrase,crc32&0xffff);
if ( spendlen < 0 )
{
printf("error encrpting opreturn data\n");
free_json(txobj);
return(0);
}
} else offset = crc32 = 0;
len = 0;
script[len++] = SCRIPT_OP_RETURN;
if ( spendlen < 76 )
@ -1387,13 +1402,27 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
script[len++] = (spendlen & 0xff);
script[len++] = ((spendlen >> 8) & 0xff);
}
decode_hex(&script[len],spendlen,opretstr);
if ( passphrase != 0 && passphrase[0] != 0 )
{
if ( offset != len )
{
printf("offset.%d vs len.%d, reencrypt\n",offset,len);
spendlen = LP_opreturn_encrypt(&script[len],(int32_t)sizeof(script)-len,data,origspendlen,passphrase,crc32&0xffff);
if ( spendlen < 0 )
{
printf("error encrpting opreturn data\n");
free_json(txobj);
return(0);
}
} //else printf("offset.%d already in right place\n",offset);
} else decode_hex(&script[len],spendlen,opretstr);
txobj = bitcoin_txoutput(txobj,script,len + spendlen,0);
printf("OP_RETURN.[%d, %d] script.(%s)\n",len,spendlen,opretstr);
//printf("OP_RETURN.[%d, %d] script.(%s)\n",len,spendlen,opretstr);
}
else
{
printf("custom script.%d too long %d\n",i,spendlen);
free_json(txobj);
return(0);
}
}
@ -1405,10 +1434,96 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
return(rawtxbytes);
}
char *LP_opreturndecrypt(void *ctx,char *symbol,bits256 utxotxid,char *passphrase)
{
cJSON *txjson,*vouts,*opret,*sobj,*retjson; uint16_t utxovout; char *opretstr,*hexstr; uint8_t *opretdata,*databuf,*decoded; uint16_t ind16; uint32_t crc32; int32_t i,len,numvouts,opretlen,datalen; struct iguana_info *coin;
if ( (coin= LP_coinfind(symbol)) == 0 )
return(clonestr("{\"error\":\"cant find coin\"}"));
retjson = cJSON_CreateObject();
utxovout = 0;
if ( (txjson= LP_gettx("LP_opreturn_decrypt",coin->symbol,utxotxid,1)) != 0 )
{
if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts >= 1 )
{
opret = jitem(vouts,numvouts - 1);
jaddstr(retjson,"coin",symbol);
jaddbits256(retjson,"opreturntxid",utxotxid);
if ( (sobj= jobj(opret,"scriptPubKey")) != 0 )
{
if ( (opretstr= jstr(sobj,"hex")) != 0 )
{
jaddstr(retjson,"opreturn",opretstr);
opretlen = (int32_t)strlen(opretstr) >> 1;
opretdata = malloc(opretlen);
decode_hex(opretdata,opretlen,opretstr);
databuf = &opretdata[2];
datalen = 0;
if ( opretdata[0] != 0x6a )
jaddstr(retjson,"error","not opreturn data");
else if ( (datalen= opretdata[1]) < 76 )
{
if ( &databuf[datalen] != &opretdata[opretlen] )
databuf = 0, jaddstr(retjson,"error","mismatched short opretlen");
}
else if ( opretdata[1] == 0x4c )
{
datalen = opretdata[2];
databuf++;
if ( &databuf[datalen] != &opretdata[opretlen] )
databuf = 0, jaddstr(retjson,"error","mismatched opretlen");
}
else if ( opretdata[1] == 0x4d )
{
datalen = opretdata[3];
datalen <<= 8;
datalen |= opretdata[2];
databuf += 2;
if ( &databuf[datalen] != &opretdata[opretlen] )
databuf = 0, jaddstr(retjson,"error","mismatched big opretlen");
}
else databuf = 0, jaddstr(retjson,"error","unexpected opreturn data type");
if ( databuf != 0 )
{
decoded = calloc(1,opretlen+1);
if ( (len= LP_opreturn_decrypt(&ind16,decoded,databuf,datalen,passphrase)) < 0 )
jaddstr(retjson,"error","decrypt error");
else
{
crc32 = calc_crc32(0,decoded,len);
if ( (crc32 & 0xffff) == ind16 )
{
jaddstr(retjson,"result","success");
hexstr = malloc(len*2+1);
init_hexbytes_noT(hexstr,decoded,len);
jaddstr(retjson,"decrypted",hexstr);
for (i=0; i<len; i++)
if ( isprint(decoded[i]) == 0 )
break;
if ( i == len )
{
memcpy(hexstr,decoded,len);
hexstr[len] = 0;
jaddstr(retjson,"original",hexstr);
}
free(hexstr);
} else jaddstr(retjson,"error","decrypt crc16 error");
}
free(decoded);
}
free(opretdata);
}
}
}
free_json(txjson);
}
return(jprint(retjson,1));
}
char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
{
static void *ctx;
int32_t iter,i,utxovout,autofee,completed=0,maxV,numvins,numvouts,datalen,suppress_pubkeys; bits256 privkey; struct LP_address *ap; char changeaddr[64],vinaddr[64],str[65],*signedtx=0,*rawtx=0; struct vin_info *V; uint32_t locktime; cJSON *retjson,*item,*outputs,*vins=0,*txobj=0,*privkeys=0; struct iguana_msgtx msgtx; bits256 utxotxid,signedtxid; uint64_t txfee,newtxfee=10000;
int32_t allocated_outputs=0,iter,i,utxovout,autofee,completed=0,maxV,numvins,numvouts,datalen,suppress_pubkeys; bits256 privkey; struct LP_address *ap; char changeaddr[64],vinaddr[64],str[65],*signedtx=0,*rawtx=0; struct vin_info *V; uint32_t locktime; cJSON *retjson,*item,*outputs,*vins=0,*txobj=0,*privkeys=0; struct iguana_msgtx msgtx; bits256 utxotxid,signedtxid; uint64_t txfee,newtxfee=10000;
//printf("withdraw.%s %s\n",coin->symbol,jprint(argjson,0));
if ( coin->etomic[0] != 0 )
{
if ( (coin= LP_coinfind("ETOMIC")) == 0 )
@ -1418,8 +1533,20 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
ctx = bitcoin_ctx();
if ( (outputs= jarray(&numvouts,argjson,"outputs")) == 0 )
{
printf("no outputs in argjson (%s)\n",jprint(argjson,0));
return(clonestr("{\"error\":\"no outputs specified\"}"));
if ( jstr(argjson,"opreturn") == 0 )
{
printf("no outputs in argjson (%s)\n",jprint(argjson,0));
return(clonestr("{\"error\":\"no outputs specified\"}"));
}
else
{
outputs = cJSON_CreateArray();
item = cJSON_CreateObject();
jaddnum(item,coin->smartaddr,0.0001);
jaddi(outputs,item);
numvouts = 1;
allocated_outputs = 1;
}
}
utxotxid = jbits256(argjson,"utxotxid");
utxovout = jint(argjson,"utxovout");
@ -1446,13 +1573,15 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
{
printf("LP_withdraw error utxo reset %s\n",coin->symbol);
free(V);
if ( allocated_outputs != 0 )
free_json(outputs);
return(0);
}
privkeys = cJSON_CreateArray();
vins = cJSON_CreateArray();
memset(V,0,sizeof(*V) * maxV);
numvins = 0;
if ( (rawtx= LP_createrawtransaction(&txobj,&numvins,coin,V,maxV,privkey,outputs,vins,privkeys,iter == 0 ? txfee : newtxfee,utxotxid,utxovout,locktime,jstr(argjson,"opreturn"))) != 0 )
if ( (rawtx= LP_createrawtransaction(&txobj,&numvins,coin,V,maxV,privkey,outputs,vins,privkeys,iter == 0 ? txfee : newtxfee,utxotxid,utxovout,locktime,jstr(argjson,"opreturn"),jstr(argjson,"passphrase"))) != 0 )
{
completed = 0;
memset(&msgtx,0,sizeof(msgtx));
@ -1513,6 +1642,8 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
jadd(retjson,"tx",txobj);
jaddbits256(retjson,"txid",signedtxid);
jadd(retjson,"complete",completed!=0?jtrue():jfalse());
if ( allocated_outputs != 0 )
free_json(outputs);
return(jprint(retjson,1));
}

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

6
iguana/exchanges/opreturn

@ -0,0 +1,6 @@
#!/bin/bash
source userpass
curl -X POST --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"withdraw\",\"coin\":\"COQUI\",\"passphrase\":\"$2\", \"opreturn\":\"$(echo -n "$1" | od -A n -t x1 | perl -pe 's/\W+//g')\"}"
#curl -X POST --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"withdraw\",\"coin\":\"COQUI\",\"outputs\":[{\"RGCVXhUxepCxh77thy7XgMrQ5XU9u7SWSR\":0.01}], \"opreturn\":\"$(echo -n "$1" | od -A n -t x1 | perl -pe 's/\W+//g')\"}"
#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"withdraw\",\"coin\":\"HUSH\",\"outputs\":[{\"t1JTXxWyBrxdWNTaNa5gYPPfpJkhqESvyov\":$1}], \"opreturn\":\"deadbeef\"}"

5
iguana/exchanges/opreturndecrypt

@ -0,0 +1,5 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"opreturndecrypt\",\"coin\":\"KMD\",\"txid\":\"06e59c6e9217ef1e526a1419e231e5f927689765feab9cd48167e089301f6fc2\",\"passphrase\":\"test\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"opreturndecrypt\",\"coin\":\"KMD\",\"txid\":\"34bf4bc2247e43c0c6a2223b79d3f1a3e9962102fb4a563612e5bbb91fb85348\",\"passphrase\":\"test\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"opreturndecrypt\",\"coin\":\"KMD\",\"txid\":\"a9e94e6890d6998b3c2b89685e8c7c2b9e380a53fb813192701d0966480807eb\",\"passphrase\":\"test\"}"

2
iguana/exchanges/stats.c

@ -516,7 +516,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
cJSON *retitem,*retarray = cJSON_CreateArray();
origargjson = argjson;
symbol[0] = 0;
for (i=0; i<n; i++)
for (i=0; i<n; i++) // array cmd path doesnt support event streaming
{
argjson = jitem(origargjson,i);
if ( userpass != 0 && jstr(argjson,"userpass") == 0 )

Loading…
Cancel
Save