Browse Source

Merge remote-tracking branch 'refs/remotes/jl777/master'

dPoW2
usamir 8 years ago
parent
commit
a22a7d34aa
  1. 12
      basilisk/basilisk.h
  2. 4
      basilisk/basilisk_DEX.c
  3. 2
      basilisk/basilisk_bitcoin.c
  4. 477
      basilisk/basilisk_swap.c
  5. 2
      iguana/coins/genanc
  6. 2
      iguana/coins/genanc.json
  7. 3
      iguana/exchanges/bitcoin.h
  8. 2
      iguana/iguana777.c
  9. 72
      iguana/iguana_interpreter.c
  10. 71
      iguana/iguana_payments.c
  11. 24
      iguana/iguana_realtime.c
  12. 14
      iguana/iguana_scripts.c
  13. 56
      iguana/iguana_sign.c
  14. 68
      iguana/iguana_unspents.c
  15. 4
      iguana/iguana_wallet.c
  16. 4
      iguana/swaps/iguana_BTCswap.c
  17. 2
      iguana/tests/decoderawtransaction
  18. 9
      includes/iguana_funcs.h
  19. 3
      includes/iguana_structs.h

12
basilisk/basilisk.h

@ -16,7 +16,7 @@
#ifndef H_BASILISK_H
#define H_BASILISK_H
//#define BASILISK_DISABLESENDTX
#define BASILISK_DISABLESENDTX
#define BASILISK_DISABLEWAITTX
#include "../iguana/iguana777.h"
@ -59,20 +59,21 @@ struct basilisk_rawtx
struct basilisk_swap
{
struct basilisk_request req;
struct supernet_info *myinfo; bits256 myhash,otherhash;
struct supernet_info *myinfo; bits256 myhash,otherhash,orderhash;
uint32_t statebits,otherstatebits,started,expiration,finished,dead,reftime,locktime;
struct iguana_info *bobcoin,*alicecoin; char bobstr[64],alicestr[64];
int32_t bobconfirms,aliceconfirms,iambob,reclaimed;
uint64_t alicesatoshis,bobsatoshis,bobinsurance,aliceinsurance;
bits256 privkeys[INSTANTDEX_DECKSIZE],myprivs[2],mypubs[2],otherpubs[2],pubA0,pubA1,pubB0,pubB1,privAm,pubAm,privBn,pubBn;
uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2];
bits256 myprivs[2],mypubs[2],otherpubs[2],pubA0,pubA1,pubB0,pubB1,privAm,pubAm,privBn,pubBn;
uint32_t crcs_mypub[2],crcs_mychoosei[2],crcs_myprivs[2],crcs_mypriv[2];
int32_t choosei,otherchoosei,cutverified,otherverifiedcut,numpubs,havestate,otherhavestate;
uint8_t secretAm[20],secretBn[20];
uint8_t secretAm256[32],secretBn256[32];
struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim;
bits256 privkeys[INSTANTDEX_DECKSIZE];
uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2];
uint8_t verifybuf[65536];
};
@ -122,10 +123,11 @@ void basilisk_request_goodbye(struct supernet_info *myinfo);
int32_t basilisk_update(char *symbol,uint32_t reftimestamp);
void basilisk_seqresult(struct supernet_info *myinfo,char *retstr);
struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbol,char *chainname,cJSON *valsobj);
void basilisk_alicepayment(struct supernet_info *myinfo,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn);
void basilisk_alicepayment(struct supernet_info *myinfo,struct basilisk_swap *swap,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn);
void basilisk_rawtx_setparms(char *name,struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,struct iguana_info *coin,int32_t numconfirms,int32_t vintype,uint64_t satoshis,int32_t vouttype,uint8_t *pubkey33);
void basilisk_setmyid(struct supernet_info *myinfo);
int32_t basilisk_rwDEXquote(int32_t rwflag,uint8_t *serialized,struct basilisk_request *rp);
cJSON *basilisk_requestjson(struct basilisk_request *rp);
void basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t depositflag,int32_t genflag);
#endif

4
basilisk/basilisk_DEX.c

@ -291,7 +291,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen,INSTANTDEX_LOCKTIME*2);
while ( numiters < 10 && (crc= basilisk_swapcrcsend(myinfo,buf,sizeof(buf),issueR.desthash,issueR.srchash,channel,msgid,data,datalen,crcs)) == 0 )
{
printf("didnt get back what was sent\n");
//printf("didnt get back what was sent\n");
sleep(3);
basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen,INSTANTDEX_LOCKTIME*2);
numiters++;
@ -547,7 +547,7 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr)
sleep(3);
while ( numiters < 10 && (crc= basilisk_swapcrcsend(myinfo,buf,sizeof(buf),hash,myinfo->myaddr.persistent,DEX_channel,msgid,serialized,datalen,crcs)) == 0 )
{
printf("didnt get back what was sent\n");
//printf("didnt get back what was sent\n");
sleep(3);
basilisk_channelsend(myinfo,myinfo->myaddr.persistent,hash,DEX_channel,msgid,serialized,datalen,60);
numiters++;

2
basilisk/basilisk_bitcoin.c

@ -566,7 +566,7 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
jadd(valsobj,"addresses",addresses);
}
//printf("use addresses.(%s)\n",jprint(addresses,0));
printf("(%s) vals.(%s) change.(%s) spend.%s\n",coin->symbol,jprint(valsobj,0),changeaddr,spendscriptstr);
//printf("(%s) vals.(%s) change.(%s) spend.%s\n",coin->symbol,jprint(valsobj,0),changeaddr,spendscriptstr);
if ( changeaddr == 0 || changeaddr[0] == 0 || spendscriptstr == 0 || spendscriptstr[0] == 0 )
return(clonestr("{\"error\":\"invalid changeaddr or spendscript or addresses\"}"));
if ( coin != 0 )

477
basilisk/basilisk_swap.c

@ -24,24 +24,42 @@
e) BEFORE Bob broadcasts deposit, Alice broadcasts BTC denominated fee in cltv so if trade isnt done fee is reclaimed
*/
//#define DISABLE_CHECKSIG
/*
both fees are standard payments: OP_DUP OP_HASH160 FEE_RMD160 OP_EQUALVERIFY OP_CHECKSIG
Alice altpayment: OP_2 <alice_pubM> <bob_pubN> OP_2 OP_CHECKMULTISIG
Bob deposit:
#ifndef DISABLE_CHECKSIG
OP_IF
<now + INSTANTDEX_LOCKTIME*2> OP_CLTV OP_DROP <alice_pubA0> OP_CHECKSIG
OP_ELSE
OP_HASH160 <hash(bob_privN)> OP_EQUALVERIFY <bob_pubB0> OP_CHECKSIG
OP_ENDIF
#else
OP_IF
<now + INSTANTDEX_LOCKTIME*2> OP_CLTV OP_DROP OP_SHA256 <sha256(alice_privA0)> OP_EQUAL
OP_ELSE
OP_HASH160 <hash(bob_privN)> OP_EQUALVERIFY OP_SHA256 <sha256(bob_privB0)> OP_EQUAL
OP_ENDIF
#endif
Bob paytx:
#ifndef DISABLE_CHECKSIG
OP_IF
<now + INSTANTDEX_LOCKTIME> OP_CLTV OP_DROP <bob_pubB1> OP_CHECKSIG
OP_ELSE
OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG
OP_ENDIF
#else
OP_IF
<now + INSTANTDEX_LOCKTIME> OP_CLTV OP_DROP OP_SHA256 <sha256(bob_privB1)> OP_EQUAL
OP_ELSE
OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY OP_SHA256 <sha256(alice_privA0)> OP_EQUAL
OP_ENDIF
#endif
Naming convention are pubAi are alice's pubkeys (seems only pubA0 and not pubA1)
pubBi are Bob's pubkeys
@ -53,7 +71,26 @@
Alice timeout event is triggered if INSTANTDEX_LOCKTIME elapses from the start of a FSM instance. Bob timeout event is triggered after INSTANTDEX_LOCKTIME*2
*/
//auto create utxo
/*
Bob sends bobdeposit and waits for alicepayment to confirm before sending bobpayment
Alice waits for bobdeposit to confirm and sends alicepayment
Alice spends bobpayment immediately divulging privAm
Bob spends alicepayment immediately after getting privAm and divulges privBn
Bob will spend bobdeposit after end of trade or INSTANTDEX_LOCKTIME, divulging privBn
Alice spends alicepayment as soon as privBn is seen
Bob will spend bobpayment after INSTANTDEX_LOCKTIME
Alice spends bobdeposit in 2*INSTANTDEX_LOCKTIME
*/
// negative spend if value too small
void basilisk_txlog(struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,int32_t delay)
{
// save in append only for backstop reclaiming
}
void revcalc_rmd160_sha256(uint8_t rmd160[20],bits256 revhash)
{
@ -63,32 +100,52 @@ void revcalc_rmd160_sha256(uint8_t rmd160[20],bits256 revhash)
calc_rmd160_sha256(rmd160,hash.bytes,sizeof(hash));
}
bits256 revcalc_sha256(bits256 revhash)
{
bits256 hash,dest; int32_t i;
for (i=0; i<32; i++)
hash.bytes[i] = revhash.bytes[31-i];
vcalc_sha256(0,dest.bytes,hash.bytes,sizeof(hash));
return(dest);
}
#define SCRIPT_OP_IF 0x63
#define SCRIPT_OP_ELSE 0x67
#define SCRIPT_OP_ENDIF 0x68
bits256 basilisk_revealkey(bits256 privkey,bits256 pubkey)
{
bits256 reveal;
#ifdef DISABLE_CHECKSIG
vcalc_sha256(0,reveal.bytes,privkey.bytes,sizeof(privkey));
//reveal = revcalc_sha256(privkey);
char str[65],str2[65]; printf("priv.(%s) -> reveal.(%s)\n",bits256_str(str,privkey),bits256_str(str2,reveal));
#else
reveal = pubkey;
#endif
return(reveal);
}
int32_t basilisk_bobscript(uint8_t *rmd160,uint8_t *redeemscript,int32_t *redeemlenp,uint8_t *script,int32_t n,uint32_t *locktimep,int32_t *secretstartp,struct basilisk_swap *swap,int32_t depositflag)
{
uint8_t pubkeyA[33],pubkeyB[33],*secret160,*secret256; bits256 cltvpub,destpub; int32_t i;
uint8_t pubkeyA[33],pubkeyB[33],*secret160,*secret256; bits256 privkey,cltvpub,destpub; int32_t i;
*locktimep = swap->locktime;
if ( depositflag != 0 )
{
*locktimep += INSTANTDEX_LOCKTIME;
cltvpub = swap->pubA0;
destpub = swap->pubB0;
pubkeyA[0] = 0x02, cltvpub = swap->pubA0;
pubkeyB[0] = 0x03, destpub = swap->pubB0;
privkey = swap->privBn;
secret160 = swap->secretBn;
secret256 = swap->secretBn256;
pubkeyA[0] = 0x02;
pubkeyB[0] = 0x03;
}
else
{
cltvpub = swap->pubB1;
destpub = swap->pubA0;
pubkeyA[0] = 0x03, cltvpub = swap->pubB1;
pubkeyB[0] = 0x02, destpub = swap->pubA0;
privkey = swap->privAm;
secret160 = swap->secretAm;
secret256 = swap->secretAm256;
pubkeyA[0] = 0x03;
pubkeyB[0] = 0x02;
}
for (i=0; i<32; i++)
printf("%02x",secret256[i]);
@ -104,12 +161,36 @@ int32_t basilisk_bobscript(uint8_t *rmd160,uint8_t *redeemscript,int32_t *redeem
memcpy(pubkeyB+1,destpub.bytes,sizeof(destpub));
redeemscript[n++] = SCRIPT_OP_IF;
n = bitcoin_checklocktimeverify(redeemscript,n,*locktimep);
#ifdef DISABLE_CHECKSIG
n = bitcoin_secret256spend(redeemscript,n,cltvpub);
#else
n = bitcoin_pubkeyspend(redeemscript,n,pubkeyA);
#endif
redeemscript[n++] = SCRIPT_OP_ELSE;
if ( secretstartp != 0 )
*secretstartp = n + 2;
if ( 0 )
n = bitcoin_revealsecret160(redeemscript,n,secret160);
if ( 1 )
{
if ( 1 && bits256_nonz(privkey) != 0 )
{
uint8_t bufA[20],bufB[20];
revcalc_rmd160_sha256(bufA,privkey);
calc_rmd160_sha256(bufB,privkey.bytes,sizeof(privkey));
/*if ( memcmp(bufA,secret160,sizeof(bufA)) == 0 )
printf("MATCHES BUFA\n");
else if ( memcmp(bufB,secret160,sizeof(bufB)) == 0 )
printf("MATCHES BUFB\n");
else printf("secret160 matches neither\n");
for (i=0; i<20; i++)
printf("%02x",bufA[i]);
printf(" <- revcalc\n");
for (i=0; i<20; i++)
printf("%02x",bufB[i]);
printf(" <- calc\n");*/
memcpy(secret160,bufB,20);
}
n = bitcoin_secret160verify(redeemscript,n,secret160);
}
else
{
redeemscript[n++] = 0xa8;//IGUANA_OP_SHA256;
@ -117,7 +198,11 @@ int32_t basilisk_bobscript(uint8_t *rmd160,uint8_t *redeemscript,int32_t *redeem
memcpy(&redeemscript[n],secret256,0x20), n += 0x20;
redeemscript[n++] = 0x88; //SCRIPT_OP_EQUALVERIFY;
}
#ifdef DISABLE_CHECKSIG
n = bitcoin_secret256spend(redeemscript,n,destpub);
#else
n = bitcoin_pubkeyspend(redeemscript,n,pubkeyB);
#endif
redeemscript[n++] = SCRIPT_OP_ENDIF;
*redeemlenp = n;
calc_rmd160_sha256(rmd160,redeemscript,n);
@ -201,15 +286,15 @@ bits256 basilisk_swap_broadcast(char *name,struct supernet_info *myinfo,struct b
signedtx = malloc(datalen*2 + 1);
init_hexbytes_noT(signedtx,data,datalen);
txid = iguana_sendrawtransaction(myinfo,coin,signedtx);
printf("%s <- sendrawtransaction %s.(%s)\n",name,signedtx,bits256_str(str,txid));
printf("sendrawtransaction %s.(%s)\n",name,bits256_str(str,txid));
free(signedtx);
}
return(txid);
}
int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct basilisk_swap *swap,struct basilisk_rawtx *dest,struct basilisk_rawtx *rawtx,bits256 privkey,bits256 *privkey2,uint8_t *userdata,int32_t userdatalen)
int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct basilisk_swap *swap,struct basilisk_rawtx *dest,struct basilisk_rawtx *rawtx,bits256 privkey,bits256 *privkey2,uint8_t *userdata,int32_t userdatalen,int32_t ignore_cltverr)
{
char *rawtxbytes,*signedtx,hexstr[999],wifstr[128]; cJSON *txobj,*vins,*item,*sobj,*privkeys; int32_t retval = -1; struct vin_info *V; uint32_t locktime=0;
char *rawtxbytes=0,*signedtx=0,hexstr[999],wifstr[128]; cJSON *txobj,*vins,*item,*sobj,*privkeys; int32_t needsig=1,retval = -1; struct vin_info *V; uint32_t locktime=0;
V = calloc(16,sizeof(*V));
if ( dest == &swap->aliceclaim )
locktime = swap->locktime + INSTANTDEX_LOCKTIME;
@ -228,9 +313,10 @@ int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct b
//char str[65]; printf("add second privkey.(%s) %s\n",jprint(privkeys,0),bits256_str(str,*privkey2));
} else V[0].N = V[0].M = 1;
V[0].suppress_pubkeys = dest->suppress_pubkeys;
V[0].ignore_cltverr = ignore_cltverr;
if ( dest->redeemlen != 0 )
memcpy(V[0].p2shscript,dest->redeemscript,dest->redeemlen), V[0].p2shlen = dest->redeemlen;
txobj = bitcoin_txcreate(rawtx->coin->chain->isPoS,locktime,rawtx->coin->chain->locktime_txversion);
txobj = bitcoin_txcreate(rawtx->coin->chain->isPoS,locktime,userdata == 0 ? 1 : 1);//rawtx->coin->chain->locktime_txversion);
vins = cJSON_CreateArray();
item = cJSON_CreateObject();
if ( userdata != 0 && userdatalen > 0 )
@ -239,6 +325,10 @@ int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct b
V[0].userdatalen = userdatalen;
init_hexbytes_noT(hexstr,userdata,userdatalen);
jaddstr(item,"userdata",hexstr);
//jaddnum(item,"sequence",0);
#ifdef DISABLE_CHECKSIG
needsig = 0;
#endif
}
if ( bits256_nonz(rawtx->actualtxid) != 0 )
jaddbits256(item,"txid",rawtx->actualtxid);
@ -249,8 +339,8 @@ int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct b
jaddstr(sobj,"hex",hexstr);
jadd(item,"scriptPubKey",sobj);
jaddnum(item,"suppress",dest->suppress_pubkeys);
if ( locktime != 0 )
jaddnum(item,"sequence",0);
//if ( locktime != 0 )
// jaddnum(item,"sequence",0);
if ( (dest->redeemlen= rawtx->redeemlen) != 0 )
{
init_hexbytes_noT(hexstr,rawtx->redeemscript,rawtx->redeemlen);
@ -260,19 +350,22 @@ int32_t basilisk_rawtx_sign(struct supernet_info *myinfo,int32_t height,struct b
jaddi(vins,item);
jdelete(txobj,"vin");
jadd(txobj,"vin",vins);
printf("basilisk_rawtx_sign locktime.%u/%u for %s spendscript.%s -> %s, suppress.%d\n",rawtx->locktime,dest->locktime,rawtx->name,hexstr,dest->name,dest->suppress_pubkeys);
//printf("basilisk_rawtx_sign locktime.%u/%u for %s spendscript.%s -> %s, suppress.%d\n",rawtx->locktime,dest->locktime,rawtx->name,hexstr,dest->name,dest->suppress_pubkeys);
txobj = bitcoin_txoutput(txobj,dest->spendscript,dest->spendlen,dest->amount);
if ( (rawtxbytes= bitcoin_json2hex(myinfo,rawtx->coin,&dest->txid,txobj,V)) != 0 )
{
printf("(%s) spend.%s rawtx.(%s) userdatalen.%d p2shlen.%d\n",jprint(txobj,0),rawtx->name,rawtxbytes,userdatalen,dest->redeemlen);
if ( (signedtx= iguana_signrawtx(myinfo,rawtx->coin,height,&dest->signedtxid,&dest->completed,vins,rawtxbytes,privkeys,V)) != 0 )
if ( needsig == 0 )
signedtx = rawtxbytes;
if ( signedtx != 0 || (signedtx= iguana_signrawtx(myinfo,rawtx->coin,height,&dest->signedtxid,&dest->completed,vins,rawtxbytes,privkeys,V)) != 0 )
{
printf("rawtx spend signedtx.(%s)\n",signedtx);
dest->datalen = (int32_t)strlen(signedtx) >> 1;
dest->txbytes = calloc(1,dest->datalen);
decode_hex(dest->txbytes,dest->datalen,signedtx);
if ( signedtx != rawtxbytes )
free(signedtx);
if ( dest->completed != 0 )
retval = 0;
else printf("couldnt sign transaction %s\n",rawtx->name);
} else printf("error signing\n");
free(rawtxbytes);
} else printf("error making rawtx\n");
@ -294,16 +387,26 @@ struct basilisk_rawtx *basilisk_swapdata_rawtx(struct supernet_info *myinfo,stru
int32_t basilisk_verify_otherfee(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)
{
struct basilisk_swap *swap = ptr;
// add verification
// add verification and broadcast
swap->otherfee.txbytes = calloc(1,datalen);
memcpy(swap->otherfee.txbytes,data,datalen);
swap->otherfee.actualtxid = swap->otherfee.signedtxid = bits256_doublesha256(0,data,datalen);
basilisk_txlog(myinfo,swap,&swap->otherfee,-1);
return(0);
}
int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *data,int32_t datalen,int32_t suppress_pubkeys)
int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys)
{
int32_t retval=-1,hexlen,n; cJSON *txobj,*skey,*vouts,*vout; char *hexstr;
int32_t datalen=0,retval=-1,hexlen,n; uint8_t *data; cJSON *txobj,*skey,*vouts,*vout; char *hexstr;
datalen = recvbuf[0];
datalen += (int32_t)recvbuf[1] << 8;
if ( datalen > 65536 )
return(-1);
rawtx->redeemlen = recvbuf[2];
data = &recvbuf[3];
if ( rawtx->redeemlen > 0 && rawtx->redeemlen < 0x100 )
memcpy(rawtx->redeemscript,&data[datalen],rawtx->redeemlen);
//printf("recvlen.%d datalen.%d redeemlen.%d\n",recvlen,datalen,rawtx->redeemlen);
if ( rawtx->txbytes == 0 )
{
rawtx->txbytes = calloc(1,datalen);
@ -319,12 +422,12 @@ int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,int32_t height,s
printf("%02x",rawtx->txbytes[i]);
printf(" <- rawtx\n");
printf("%s rawtx data compare error, len %d vs %d <<<<<<<<<< warning\n",rawtx->name,rawtx->datalen,datalen);
//return(-1);
return(-1);
}
if ( (txobj= bitcoin_data2json(rawtx->coin,height,&rawtx->signedtxid,&rawtx->msgtx,rawtx->extraspace,sizeof(rawtx->extraspace),data,datalen,0,suppress_pubkeys)) != 0 )
{
rawtx->actualtxid = rawtx->signedtxid;
char str[65]; printf("got txid.%s\n",bits256_str(str,rawtx->signedtxid));
//char str[65]; printf("got txid.%s (%s)\n",bits256_str(str,rawtx->signedtxid),jprint(txobj,0));
rawtx->locktime = rawtx->msgtx.lock_time;
if ( (vouts= jarray(&n,txobj,"vout")) != 0 && v < n )
{
@ -335,6 +438,7 @@ int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,int32_t height,s
{
decode_hex(rawtx->spendscript,hexlen,hexstr);
rawtx->spendlen = hexlen;
basilisk_txlog(myinfo,swap,rawtx,-1); // bobdeposit, bobpayment or alicepayment
retval = 0;
}
} else printf("%s ERROR.(%s)\n",rawtx->name,jprint(txobj,0));
@ -344,30 +448,20 @@ int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,int32_t height,s
return(retval);
}
int32_t basilisk_swapuserdata(uint8_t *userdata,int32_t pushpriv,bits256 privkey,uint8_t addrtype,bits256 pubkey,int32_t ifpath,int32_t revflag)
int32_t basilisk_swapuserdata(struct basilisk_swap *swap,uint8_t *userdata,bits256 privkey,int32_t ifpath,bits256 signpriv,uint8_t *redeemscript,int32_t redeemlen)
{
int32_t i,len = 0;
if ( 0 )
{
userdata[len++] = 33;
userdata[len++] = addrtype;
for (i=0; i<sizeof(pubkey); i++)
userdata[len++] = pubkey.bytes[i];
}
if ( pushpriv != 0 )
#ifdef DISABLE_CHECKSIG
userdata[len++] = sizeof(signpriv);
for (i=0; i<sizeof(privkey); i++)
userdata[len++] = signpriv.bytes[i];
#endif
if ( bits256_nonz(privkey) != 0 )
{
userdata[len++] = sizeof(privkey);
if ( revflag != 0 )
{
for (i=0; i<sizeof(privkey); i++)
userdata[len++] = privkey.bytes[i];
}
else
{
for (i=0; i<sizeof(privkey); i++)
userdata[len++] = privkey.bytes[sizeof(privkey) - 1 - i];
}
}
userdata[len++] = 0x51 * ifpath; // ifpath == 1 -> if path, 0 -> else path
return(len);
}
@ -381,29 +475,33 @@ int32_t basilisk_swapuserdata(uint8_t *userdata,int32_t pushpriv,bits256 privkey
int32_t basilisk_verify_bobdeposit(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)
{
uint8_t userdata[512]; int32_t len = 0; struct basilisk_swap *swap = ptr;
if ( basilisk_rawtx_spendscript(myinfo,swap->bobcoin->blocks.hwmchain.height,&swap->bobdeposit,0,data,datalen,0) == 0 )
uint8_t userdata[512]; int32_t retval,len = 0; static bits256 zero; struct basilisk_swap *swap = ptr;
if ( basilisk_rawtx_spendscript(myinfo,swap,swap->bobcoin->blocks.hwmchain.height,&swap->bobdeposit,0,data,datalen,0) == 0 )
{
len = basilisk_swapuserdata(swap,userdata,zero,1,swap->myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.redeemlen);
if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->aliceclaim,&swap->bobdeposit,swap->myprivs[0],0,userdata,len,1)) == 0 )
{
//len = basilisk_swapuserdata(userdata,0,GENESIS_PRIVKEY,0x02,swap->pubA0,1);
userdata[len++] = 0x51;
return(basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->aliceclaim,&swap->bobdeposit,swap->myprivs[0],0,userdata,len));
basilisk_txlog(myinfo,swap,&swap->aliceclaim,INSTANTDEX_LOCKTIME*2);
return(retval);
}
}
printf("error with bobdeposit\n");
return(-1);
}
int32_t basilisk_bobdeposit_refund(struct supernet_info *myinfo,struct basilisk_swap *swap)
int32_t basilisk_bobdeposit_refund(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t delay)
{
uint8_t userdata[512],revrmd160[20]; int32_t len = 0;
len = basilisk_swapuserdata(userdata,1,swap->privBn,0x03,swap->pubB0,0,0);
int32_t i; for (i=0; i<len; i++)
printf("%02x",userdata[i]);
char str[65]; printf(" <-basilisk_bobdeposit_refund privBn.(%s)\n",bits256_str(str,swap->privBn));
revcalc_rmd160_sha256(revrmd160,swap->privBn);
for (i=0; i<20; i++)
printf("%02x",revrmd160[i]);
printf(" <- revrmd160\n");
return(basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->bobrefund,&swap->bobdeposit,swap->myprivs[0],0,userdata,len));
uint8_t userdata[512]; int32_t i,retval,len = 0; char str[65];
len = basilisk_swapuserdata(swap,userdata,swap->privBn,0,swap->myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.redeemlen);
if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->bobrefund,&swap->bobdeposit,swap->myprivs[0],0,userdata,len,0)) == 0 )
{
for (i=0; i<swap->bobrefund.datalen; i++)
printf("%02x",swap->bobrefund.txbytes[i]);
printf(" <- bobrefund.(%s)\n",bits256_str(str,swap->bobrefund.txid));
basilisk_txlog(myinfo,swap,&swap->bobrefund,delay);
return(retval);
}
return(-1);
}
/*Bob paytx:
@ -413,53 +511,61 @@ int32_t basilisk_bobdeposit_refund(struct supernet_info *myinfo,struct basilisk_
OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG
OP_ENDIF*/
int32_t basilisk_bobpayment_reclaim(struct supernet_info *myinfo,struct basilisk_swap *swap)
int32_t basilisk_bobpayment_reclaim(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t delay)
{
uint8_t userdata[512]; int32_t len = 0;
uint8_t userdata[512]; int32_t retval,len = 0; static bits256 zero;
printf("basilisk_bobpayment_reclaim\n");
userdata[len++] = 0x51;
//len = basilisk_swapuserdata(userdata,0,GENESIS_PRIVKEY,0x03,swap->pubB1,1);
return(basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->bobreclaim,&swap->bobpayment,swap->myprivs[1],0,userdata,len));
len = basilisk_swapuserdata(swap,userdata,zero,1,swap->myprivs[1],swap->bobpayment.redeemscript,swap->bobpayment.redeemlen);
if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->bobreclaim,&swap->bobpayment,swap->myprivs[1],0,userdata,len,0)) == 0 )
{
basilisk_txlog(myinfo,swap,&swap->bobreclaim,delay);
return(retval);
}
return(-1);
}
int32_t basilisk_verify_bobpaid(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)
{
uint8_t userdata[512]; int32_t len = 0; struct basilisk_swap *swap = ptr;
if ( basilisk_rawtx_spendscript(myinfo,swap->bobcoin->blocks.hwmchain.height,&swap->bobpayment,0,data,datalen,0) == 0 )
uint8_t userdata[512]; int32_t i,retval,len = 0; bits256 revAm; struct basilisk_swap *swap = ptr;
if ( basilisk_rawtx_spendscript(myinfo,swap,swap->bobcoin->blocks.hwmchain.height,&swap->bobpayment,0,data,datalen,0) == 0 )
{
len = basilisk_swapuserdata(userdata,1,swap->privAm,0x02,swap->pubA0,0,0);
for (i=0; i<32; i++)
revAm.bytes[i] = swap->privAm.bytes[31-i];
len = basilisk_swapuserdata(swap,userdata,revAm,0,swap->myprivs[0],swap->bobpayment.redeemscript,swap->bobpayment.redeemlen);
char str[65]; printf("bobpaid.(%s)\n",bits256_str(str,swap->privAm));
return(basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->alicespend,&swap->bobpayment,swap->myprivs[0],0,userdata,len));
} else return(-1);
if ( (retval= basilisk_rawtx_sign(myinfo,swap->bobcoin->blocks.hwmchain.height,swap,&swap->alicespend,&swap->bobpayment,swap->myprivs[0],0,userdata,len,1)) == 0 )
{
for (i=0; i<swap->alicespend.datalen; i++)
printf("%02x",swap->alicespend.txbytes[i]);
printf(" <- alicespend\n\n");
basilisk_txlog(myinfo,swap,&swap->alicespend,-1);
return(retval);
}
}
return(-1);
}
int32_t basilisk_alicepayment_spend(struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *dest)
{
int32_t retval;
//printf("alicepayment_spend\n");
swap->alicepayment.spendlen = basilisk_alicescript(swap->alicepayment.redeemscript,&swap->alicepayment.redeemlen,swap->alicepayment.spendscript,0,swap->alicepayment.destaddr,swap->alicecoin->chain->p2shtype,swap->pubAm,swap->pubBn);
return(basilisk_rawtx_sign(myinfo,swap->alicecoin->blocks.hwmchain.height,swap,dest,&swap->alicepayment,swap->privAm,&swap->privBn,0,0));
if ( (retval= basilisk_rawtx_sign(myinfo,swap->alicecoin->blocks.hwmchain.height,swap,dest,&swap->alicepayment,swap->privAm,&swap->privBn,0,0,1)) == 0 )
{
basilisk_txlog(myinfo,swap,dest,0); // bobspend or alicereclaim
return(retval);
}
return(-1);
}
int32_t basilisk_verify_alicepaid(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)
{
struct basilisk_swap *swap = ptr;
if ( basilisk_rawtx_spendscript(myinfo,swap->alicecoin->blocks.hwmchain.height,&swap->alicepayment,0,data,datalen,0) == 0 )
if ( basilisk_rawtx_spendscript(myinfo,swap,swap->alicecoin->blocks.hwmchain.height,&swap->alicepayment,0,data,datalen,0) == 0 )
return(0);
else return(-1);
}
int32_t basilisk_privAm_extract(struct supernet_info *myinfo,struct basilisk_swap *swap)
{
// need to scan blockchain for alicespend of bobpayment
// search for swap->bobpayment.actualtxid in spends
if ( bits256_nonz(swap->privAm) != 0 && swap->bobspend.txbytes == 0 )
{
char str[65]; printf("have privAm.%s\n",bits256_str(str,swap->privAm));
return(basilisk_alicepayment_spend(myinfo,swap,&swap->bobspend));
}
return(-1);
}
int32_t basilisk_verify_pubpair(int32_t *wrongfirstbytep,struct basilisk_swap *swap,int32_t ind,uint8_t pub0,bits256 pubi,uint64_t txid)
{
if ( pub0 != (swap->iambob ^ 1) + 0x02 )
@ -554,7 +660,7 @@ int32_t basilisk_rawtx_return(struct supernet_info *myinfo,int32_t height,struct
return(retval);
}
int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,int32_t iambob,int32_t lockinputs,struct basilisk_rawtx *rawtx,uint32_t locktime,uint8_t *script,int32_t scriptlen,int64_t txfee,int32_t minconf)
int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob,int32_t lockinputs,struct basilisk_rawtx *rawtx,uint32_t locktime,uint8_t *script,int32_t scriptlen,int64_t txfee,int32_t minconf)
{
char *retstr,scriptstr[1024]; uint32_t basilisktag; int32_t flag,i,n,retval = -1; cJSON *valsobj,*retarray=0; struct vin_info *V;
//bitcoin_address(coinaddr,rawtx->coin->chain->pubtype,myinfo->persistent_pubkey33,33);
@ -574,12 +680,13 @@ int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,int32_t iambob
jaddnum(valsobj,"minconf",minconf);
jaddnum(valsobj,"locktime",locktime);
jaddnum(valsobj,"timeout",30000);
jaddnum(valsobj,"timestamp",swap->started);
rawtx->locktime = locktime;
printf("%s locktime.%u\n",rawtx->name,locktime);
//printf("%s locktime.%u\n",rawtx->name,locktime);
V = calloc(256,sizeof(*V));
if ( (retstr= basilisk_bitcoinrawtx(myinfo,rawtx->coin,"",basilisktag,jint(valsobj,"timeout"),valsobj,V)) != 0 )
{
printf("%s %s basilisk_bitcoinrawtx.(%s)\n",rawtx->name,str,retstr);
//printf("%s %s basilisk_bitcoinrawtx.(%s)\n",rawtx->name,str,retstr);
flag = 0;
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
@ -609,20 +716,22 @@ int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,int32_t iambob
return(retval);
}
void basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t depositflag)
void basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t depositflag,int32_t genflag)
{
int32_t i;
int32_t i,j; char str[65];
if ( genflag != 0 && swap->iambob == 0 )
printf("basilisk_bobscripts_set WARNING: alice generating BOB tx\n");
if ( depositflag == 0 )
{
swap->bobpayment.spendlen = basilisk_bobscript(swap->bobpayment.rmd160,swap->bobpayment.redeemscript,&swap->bobpayment.redeemlen,swap->bobpayment.spendscript,0,&swap->bobpayment.locktime,&swap->bobpayment.secretstart,swap,0);
for (i=0; i<swap->bobpayment.redeemlen; i++)
printf("%02x",swap->bobpayment.redeemscript[i]);
printf(" <- bobpayment.%d\n",i);
if ( bits256_nonz(*(bits256 *)swap->secretBn256) != 0 && swap->bobpayment.txbytes == 0 )
//for (i=0; i<swap->bobpayment.redeemlen; i++)
// printf("%02x",swap->bobpayment.redeemscript[i]);
//printf(" <- bobpayment.%d\n",i);
if ( genflag != 0 && bits256_nonz(*(bits256 *)swap->secretBn256) != 0 && swap->bobpayment.txbytes == 0 )
{
for (i=0; i<3; i++)
{
basilisk_rawtx_gen("payment",myinfo,1,1,&swap->bobpayment,swap->bobpayment.locktime,swap->bobpayment.spendscript,swap->bobpayment.spendlen,swap->bobpayment.coin->chain->txfee,1);
basilisk_rawtx_gen("payment",myinfo,swap,1,1,&swap->bobpayment,swap->bobpayment.locktime,swap->bobpayment.spendscript,swap->bobpayment.spendlen,swap->bobpayment.coin->chain->txfee,1);
if ( swap->bobpayment.txbytes == 0 || swap->bobpayment.spendlen == 0 )
{
printf("error bob generating %p payment.%d\n",swap->bobpayment.txbytes,swap->bobpayment.spendlen);
@ -630,8 +739,15 @@ void basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swap *
}
else
{
for (j=0; j<swap->bobpayment.datalen; j++)
printf("%02x",swap->bobpayment.txbytes[j]);
printf(" <- bobpayment.%d\n",swap->bobpayment.datalen);
for (j=0; j<swap->bobpayment.redeemlen; j++)
printf("%02x",swap->bobpayment.redeemscript[j]);
printf(" <- redeem.%d\n",swap->bobpayment.redeemlen);
printf("GENERATED BOB PAYMENT\n");
iguana_unspents_mark(myinfo,swap->bobcoin,swap->bobpayment.vins);
basilisk_bobpayment_reclaim(myinfo,swap,INSTANTDEX_LOCKTIME);
break;
}
}
@ -640,9 +756,34 @@ void basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swap *
else
{
swap->bobdeposit.spendlen = basilisk_bobscript(swap->bobdeposit.rmd160,swap->bobdeposit.redeemscript,&swap->bobdeposit.redeemlen,swap->bobdeposit.spendscript,0,&swap->bobdeposit.locktime,&swap->bobdeposit.secretstart,swap,1);
for (i=0; i<swap->bobdeposit.redeemlen; i++)
printf("%02x",swap->bobdeposit.redeemscript[i]);
printf(" <- bobdeposit.%d\n",i);
if ( genflag != 0 )
{
for (i=0; i<3; i++)
{
basilisk_rawtx_gen("deposit",myinfo,swap,1,1,&swap->bobdeposit,swap->bobdeposit.locktime,swap->bobdeposit.spendscript,swap->bobdeposit.spendlen,swap->bobdeposit.coin->chain->txfee,1);
if ( swap->bobdeposit.txbytes == 0 || swap->bobdeposit.spendlen == 0 )
{
printf("error bob generating %p deposit.%d\n",swap->bobdeposit.txbytes,swap->bobdeposit.spendlen);
sleep(3);
}
else
{
for (j=0; j<swap->bobdeposit.datalen; j++)
printf("%02x",swap->bobdeposit.txbytes[j]);
printf(" <- bobdeposit.%d\n",swap->bobdeposit.datalen);
for (j=0; j<swap->bobdeposit.redeemlen; j++)
printf("%02x",swap->bobdeposit.redeemscript[j]);
printf(" <- redeem.%d\n",swap->bobdeposit.redeemlen);
printf("GENERATED BOB DEPOSIT\n");
iguana_unspents_mark(myinfo,swap->bobcoin,swap->bobdeposit.vins);
basilisk_bobdeposit_refund(myinfo,swap,INSTANTDEX_LOCKTIME);
break;
}
}
}
//for (i=0; i<swap->bobdeposit.redeemlen; i++)
// printf("%02x",swap->bobdeposit.redeemscript[i]);
//printf(" <- bobdeposit.%d\n",i);
}
}
@ -663,14 +804,13 @@ int32_t basilisk_verify_privi(struct supernet_info *myinfo,void *ptr,uint8_t *da
swap->privAm = privkey;
vcalc_sha256(0,swap->secretAm256,privkey.bytes,sizeof(privkey));
printf("set privAm.%s %s\n",bits256_str(str,swap->privAm),bits256_str(str2,*(bits256 *)swap->secretAm256));
basilisk_bobscripts_set(myinfo,swap,0);
basilisk_bobscripts_set(myinfo,swap,0,1);
}
else
{
swap->privBn = privkey;
vcalc_sha256(0,swap->secretBn256,privkey.bytes,sizeof(privkey));
printf("set privBn.%s %s\n",bits256_str(str,swap->privBn),bits256_str(str2,*(bits256 *)swap->secretBn256));
basilisk_bobscripts_set(myinfo,swap,1);
}
char str[65]; printf("privi verified.(%s)\n",bits256_str(str,privkey));
return(0);
@ -788,10 +928,33 @@ uint32_t basilisk_swapsend(struct supernet_info *myinfo,struct basilisk_swap *sw
return(0);
}
int32_t basilisk_priviextract(struct supernet_info *myinfo,struct iguana_info *coin,char *name,bits256 *destp,uint8_t secret160[20],bits256 srctxid,int32_t srcvout)
{
bits256 txid,privkey; char str[65]; int32_t i,vini,scriptlen; uint8_t rmd160[20],scriptsig[IGUANA_MAXSCRIPTSIZE];
if ( (vini= iguana_vinifind(myinfo,coin,&txid,srctxid,srcvout)) >= 0 )
{
if ( (scriptlen= iguana_scriptsigextract(myinfo,coin,scriptsig,sizeof(scriptsig),txid,vini)) > 0 )
{
for (i=0; i<32; i++)
privkey.bytes[i] = scriptsig[scriptlen - 33 + i];
revcalc_rmd160_sha256(rmd160,privkey);//.bytes,sizeof(privkey));
if ( memcmp(secret160,rmd160,sizeof(rmd160)) == sizeof(rmd160) )
{
*destp = privkey;
printf("found %s (%s)\n",name,bits256_str(str,privkey));
return(0);
}
}
}
return(-1);
}
int32_t basilisk_privBn_extract(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{
// need to scan blockchain for bobrefund
// search for swap->bobrefund.actualtxid in spends
if ( basilisk_priviextract(myinfo,swap->bobcoin,"privBn",&swap->privBn,swap->secretBn,swap->bobrefund.actualtxid,0) == 0 )
{
}
if ( basilisk_swapget(myinfo,swap,0x40000000,data,maxlen,basilisk_verify_privi) == 0 )
{
if ( bits256_nonz(swap->privBn) != 0 && swap->alicereclaim.txbytes == 0 )
@ -802,7 +965,20 @@ int32_t basilisk_privBn_extract(struct supernet_info *myinfo,struct basilisk_swa
}
return(-1);
}
// end of coin protocol dependent
int32_t basilisk_privAm_extract(struct supernet_info *myinfo,struct basilisk_swap *swap)
{
if ( basilisk_priviextract(myinfo,swap->bobcoin,"privAm",&swap->privAm,swap->secretAm,swap->bobpayment.actualtxid,0) == 0 )
{
}
if ( bits256_nonz(swap->privAm) != 0 && swap->bobspend.txbytes == 0 )
{
char str[65]; printf("have privAm.%s\n",bits256_str(str,swap->privAm));
return(basilisk_alicepayment_spend(myinfo,swap,&swap->bobspend));
}
return(-1);
}
bits256 instantdex_derivekeypair(struct supernet_info *myinfo,bits256 *newprivp,uint8_t pubkey[33],bits256 privkey,bits256 orderhash)
{
@ -814,7 +990,7 @@ bits256 instantdex_derivekeypair(struct supernet_info *myinfo,bits256 *newprivp,
int32_t instantdex_pubkeyargs(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t numpubs,bits256 privkey,bits256 hash,int32_t firstbyte)
{
char buf[3]; int32_t i,n,m,len=0; bits256 pubi; uint64_t txid; uint8_t secret160[20],pubkey[33];
char buf[3]; int32_t i,n,m,len=0; bits256 pubi,reveal; uint64_t txid; uint8_t secret160[20],pubkey[33];
sprintf(buf,"%c0",'A' - 0x02 + firstbyte);
if ( numpubs > 2 )
{
@ -834,19 +1010,20 @@ int32_t instantdex_pubkeyargs(struct supernet_info *myinfo,struct basilisk_swap
{
swap->myprivs[n] = privkey;
memcpy(swap->mypubs[n].bytes,pubkey+1,sizeof(bits256));
reveal = basilisk_revealkey(privkey,swap->mypubs[n]);
if ( swap->iambob != 0 )
{
if ( n == 0 )
swap->pubB0 = swap->mypubs[n];
swap->pubB0 = reveal;
else if ( n == 1 )
swap->pubB1 = swap->mypubs[n];
swap->pubB1 = reveal;
}
else if ( swap->iambob == 0 )
{
if ( n == 0 )
swap->pubA0 = swap->mypubs[n];
swap->pubA0 = reveal;
else if ( n == 1 )
swap->pubA1 = swap->mypubs[n];
swap->pubA1 = reveal;
}
}
}
@ -993,7 +1170,7 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil
printf("neither src nor dest error\n");
return(0);
}
if ( bits256_nonz(myinfo->persistent_priv) == 0 || (x= instantdex_pubkeyargs(myinfo,swap,2 + INSTANTDEX_DECKSIZE,myinfo->persistent_priv,swap->myhash,0x02+swap->iambob)) != 2 + INSTANTDEX_DECKSIZE )
if ( bits256_nonz(myinfo->persistent_priv) == 0 || (x= instantdex_pubkeyargs(myinfo,swap,2 + INSTANTDEX_DECKSIZE,myinfo->persistent_priv,swap->orderhash,0x02+swap->iambob)) != 2 + INSTANTDEX_DECKSIZE )
{
printf("couldnt generate privkeys %d\n",x);
return(0);
@ -1027,6 +1204,7 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil
swap->bobspend.suppress_pubkeys = 1;
basilisk_rawtx_setparms("alicereclaim",myinfo,swap,&swap->alicereclaim,swap->alicecoin,swap->aliceconfirms,2,swap->alicesatoshis-swap->alicecoin->txfee,1,alicepub33);
swap->alicereclaim.suppress_pubkeys = 1;
printf("IAMBOB.%d\n",swap->iambob);
return(swap);
}
// end of alice/bob code
@ -1156,7 +1334,7 @@ int32_t basilisk_verify_privkeys(struct supernet_info *myinfo,void *ptr,uint8_t
swap->secretAm[i] = data[len++];
for (i=0; i<32; i++)
swap->secretAm256[i] = data[len++];
basilisk_bobscripts_set(myinfo,swap,1);
basilisk_bobscripts_set(myinfo,swap,1,1);
}
else
{
@ -1166,7 +1344,7 @@ int32_t basilisk_verify_privkeys(struct supernet_info *myinfo,void *ptr,uint8_t
swap->secretBn[i] = data[len++];
for (i=0; i<32; i++)
swap->secretBn256[i] = data[len++];
basilisk_bobscripts_set(myinfo,swap,0);
//basilisk_bobscripts_set(myinfo,swap,0);
}
} else printf("failed verification: wrong firstbyte.%d errs.%d\n",wrongfirstbyte,errs);
}
@ -1176,14 +1354,30 @@ int32_t basilisk_verify_privkeys(struct supernet_info *myinfo,void *ptr,uint8_t
uint32_t basilisk_swapdata_rawtxsend(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx,uint32_t nextbits)
{
uint8_t sendbuf[32768]; int32_t sendlen;
if ( basilisk_swapdata_rawtx(myinfo,swap,data,maxlen,rawtx) != 0 )
{
//if ( bits256_nonz(rawtx->signedtxid) != 0 && bits256_nonz(rawtx->actualtxid) == 0 )
if ( bits256_nonz(rawtx->signedtxid) != 0 )//&& bits256_nonz(rawtx->actualtxid) == 0 )
{
char str[65],str2[65];
rawtx->actualtxid = basilisk_swap_broadcast(rawtx->name,myinfo,swap,rawtx->coin,rawtx->txbytes,rawtx->datalen);
char str[65],str2[65]; printf("%s rawtxsend %s vs %s\n",rawtx->name,bits256_str(str,rawtx->signedtxid),bits256_str(str2,rawtx->actualtxid));
if ( bits256_nonz(rawtx->actualtxid) == 0 )
printf("%s rawtxsend %s vs %s\n",rawtx->name,bits256_str(str,rawtx->signedtxid),bits256_str(str2,rawtx->actualtxid));
if ( bits256_nonz(rawtx->actualtxid) != 0 && msgbits != 0 )
return(basilisk_swapsend(myinfo,swap,msgbits,rawtx->txbytes,rawtx->datalen,nextbits,rawtx->crcs));
{
sendlen = 0;
sendbuf[sendlen++] = rawtx->datalen & 0xff;
sendbuf[sendlen++] = (rawtx->datalen >> 8) & 0xff;
sendbuf[sendlen++] = rawtx->redeemlen;
memcpy(&sendbuf[sendlen],rawtx->txbytes,rawtx->datalen), sendlen += rawtx->datalen;
if ( rawtx->redeemlen > 0 && rawtx->redeemlen < 0x100 )
{
memcpy(&sendbuf[sendlen],rawtx->redeemscript,rawtx->redeemlen);
sendlen += rawtx->redeemlen;
}
//printf("sendlen.%d datalen.%d redeemlen.%d\n",sendlen,rawtx->datalen,rawtx->redeemlen);
return(basilisk_swapsend(myinfo,swap,msgbits,sendbuf,sendlen,nextbits,rawtx->crcs));
}
}
return(nextbits);
} else printf("error from basilisk_swapdata_rawtx %p len.%d\n",rawtx->txbytes,rawtx->datalen);
@ -1256,7 +1450,7 @@ void basilisk_waitchoosei(struct supernet_info *myinfo,struct basilisk_swap *swa
vcalc_sha256(0,swap->secretBn256,swap->privBn.bytes,sizeof(swap->privBn));
swap->pubBn = bitcoin_pubkey33(myinfo->ctx,pubkey33,swap->privBn);
printf("set privBn.%s %s\n",bits256_str(str,swap->privBn),bits256_str(str2,*(bits256 *)swap->secretBn256));
basilisk_bobscripts_set(myinfo,swap,1);
basilisk_bobscripts_set(myinfo,swap,1,1);
}
}
else
@ -1269,7 +1463,7 @@ void basilisk_waitchoosei(struct supernet_info *myinfo,struct basilisk_swap *swa
vcalc_sha256(0,swap->secretAm256,swap->privAm.bytes,sizeof(swap->privAm));
swap->pubAm = bitcoin_pubkey33(myinfo->ctx,pubkey33,swap->privAm);
printf("set privAm.%s %s\n",bits256_str(str,swap->privAm),bits256_str(str2,*(bits256 *)swap->secretAm256));
basilisk_bobscripts_set(myinfo,swap,0);
//basilisk_bobscripts_set(myinfo,swap,0);
}
}
swap->statebits |= 0x08;
@ -1307,10 +1501,10 @@ void basilisk_sendmostprivs(struct supernet_info *myinfo,struct basilisk_swap *s
swap->statebits |= basilisk_swapsend(myinfo,swap,0x20,data,datalen,0x10,swap->crcs_myprivs);
}
void basilisk_alicepayment(struct supernet_info *myinfo,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn)
void basilisk_alicepayment(struct supernet_info *myinfo,struct basilisk_swap *swap,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn)
{
alicepayment->spendlen = basilisk_alicescript(alicepayment->redeemscript,&alicepayment->redeemlen,alicepayment->spendscript,0,alicepayment->destaddr,coin->chain->p2shtype,pubAm,pubBn);
basilisk_rawtx_gen("alicepayment",myinfo,0,1,alicepayment,alicepayment->locktime,alicepayment->spendscript,alicepayment->spendlen,coin->chain->txfee,1);
basilisk_rawtx_gen("alicepayment",myinfo,swap,0,1,alicepayment,alicepayment->locktime,alicepayment->spendscript,alicepayment->spendlen,coin->chain->txfee,1);
}
// detect insufficient funds/inputs
@ -1387,38 +1581,15 @@ void basilisk_swaploop(void *_swap)
for (i=0; i<32; i++)
printf("%02x",swap->pubB1.bytes[i]);
printf(" <- pubB1\n");
basilisk_bobscripts_set(myinfo,swap,1);
if ( swap->iambob != 0 )
{
for (i=0; i<3; i++)
{
basilisk_rawtx_gen("deposit",myinfo,1,1,&swap->bobdeposit,swap->bobdeposit.locktime,swap->bobdeposit.spendscript,swap->bobdeposit.spendlen,swap->bobdeposit.coin->chain->txfee,1);
if ( swap->bobdeposit.txbytes == 0 || swap->bobdeposit.spendlen == 0 )
{
printf("error bob generating %p deposit.%d\n",swap->bobdeposit.txbytes,swap->bobdeposit.spendlen);
retval = -2;
sleep(3);
}
else
{
retval = 0;
printf("GENERATED BOB DEPOSIT\n");
iguana_unspents_mark(myinfo,swap->bobcoin,swap->bobdeposit.vins);
break;
}
}
basilisk_bobscripts_set(myinfo,swap,0);
/*if ( basilisk_bobpayment_reclaim(myinfo,swap) < 0 || basilisk_bobdeposit_refund(myinfo,swap) < 0 )
{
printf("error bob reclaiming\n");
retval = -3;
}*/
basilisk_bobscripts_set(myinfo,swap,1,1);
}
else
{
for (i=0; i<3; i++)
{
basilisk_alicepayment(myinfo,swap->alicepayment.coin,&swap->alicepayment,swap->pubAm,swap->pubBn);
basilisk_alicepayment(myinfo,swap,swap->alicepayment.coin,&swap->alicepayment,swap->pubAm,swap->pubBn);
if ( swap->alicepayment.txbytes == 0 || swap->alicepayment.spendlen == 0 )
{
printf("error alice generating payment.%d\n",swap->alicepayment.spendlen);
@ -1430,14 +1601,16 @@ void basilisk_swaploop(void *_swap)
retval = 0;
printf("ALICE PAYMENT created\n");
iguana_unspents_mark(myinfo,swap->alicecoin,swap->alicepayment.vins);
basilisk_txlog(myinfo,swap,&swap->alicepayment,-1);
break;
}
}
}
if ( basilisk_rawtx_gen("myfee",myinfo,swap->iambob,1,&swap->myfee,0,swap->myfee.spendscript,swap->myfee.spendlen,swap->myfee.coin->chain->txfee,1) == 0 )
if ( basilisk_rawtx_gen("myfee",myinfo,swap,swap->iambob,1,&swap->myfee,0,swap->myfee.spendscript,swap->myfee.spendlen,swap->myfee.coin->chain->txfee,1) == 0 )
{
swap->statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40);
iguana_unspents_mark(myinfo,swap->iambob!=0?swap->bobcoin:swap->alicecoin,swap->myfee.vins);
basilisk_txlog(myinfo,swap,&swap->myfee,-1);
}
else
{
@ -1445,6 +1618,7 @@ void basilisk_swaploop(void *_swap)
retval = -6;
}
}
basilisk_txlog(myinfo,swap,0,-1);
}
while ( retval == 0 && time(NULL) < swap->expiration )
{
@ -1470,10 +1644,11 @@ void basilisk_swaploop(void *_swap)
}
while ( retval == 0 && time(NULL) < swap->expiration ) // both sides have setup required data and paid txfee
{
if ( (rand() % 30) == 0 )
printf("E r%u/q%u swapstate.%x otherstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits,swap->otherstatebits);
if ( swap->iambob != 0 )
{
printf("BOB\n");
//printf("BOB\n");
if ( (swap->statebits & 0x100) == 0 )
{
printf("send bobdeposit\n");
@ -1499,6 +1674,7 @@ void basilisk_swaploop(void *_swap)
}
else if ( (swap->statebits & 0x4000) == 0 )
{
basilisk_bobscripts_set(myinfo,swap,0,1);
printf("send bobpayment\n");
swap->statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000);
}
@ -1553,7 +1729,7 @@ void basilisk_swaploop(void *_swap)
}
else
{
printf("ALICE\n");
//printf("ALICE\n");
// [BLOCKING: depfound] Alice waits for deposit to confirm and sends altpayment
if ( (swap->statebits & 0x200) == 0 )
{
@ -1584,6 +1760,7 @@ void basilisk_swaploop(void *_swap)
if ( basilisk_swapget(myinfo,swap,0x8000,data,maxlen,basilisk_verify_bobpaid) == 0 )
{
printf("got bobpayment\n");
basilisk_swap_balancingtrade(myinfo,swap,0);
// verify payment and submit, set confirmed height
swap->statebits |= 0x8000;
}
@ -1599,14 +1776,12 @@ void basilisk_swaploop(void *_swap)
else if ( (swap->statebits & 0x20000) == 0 )
{
printf("alicespend bobpayment\n");
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicespend,0x20000) != 0 )
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicespend,0x20000) != 0 && basilisk_numconfirms(myinfo,&swap->alicespend) > 0 )
{
// maybe wait for alicespend to be confirmed
for (j=datalen=0; j<32; j++)
data[datalen++] = swap->privAm.bytes[j];
printf("send privAm\n");
swap->statebits |= basilisk_swapsend(myinfo,swap,0x40000,data,datalen,0x20000,swap->crcs_mypriv);
basilisk_swap_balancingtrade(myinfo,swap,0);
}
}
else if ( (swap->statebits & 0x40000) == 0 )
@ -1636,8 +1811,9 @@ void basilisk_swaploop(void *_swap)
break;
}
}
if ( (rand() % 30) == 0 )
printf("finished swapstate.%x other.%x\n",swap->statebits,swap->otherstatebits);
sleep(1 + (swap->iambob == 0));
sleep(1);//3 + (swap->iambob == 0));
basilisk_sendstate(myinfo,swap,data,maxlen);
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits);
}
@ -1645,7 +1821,7 @@ void basilisk_swaploop(void *_swap)
if ( swap->iambob != 0 )//&& bits256_nonz(swap->bobdeposit.txid) != 0 )
{
printf("BOB reclaims refund\n");
basilisk_bobdeposit_refund(myinfo,swap);
basilisk_bobdeposit_refund(myinfo,swap,0);
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobrefund,0x40000000) == 0 ) // use secretBn
{
printf("Bob submit error getting refund of deposit\n");
@ -1672,6 +1848,7 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct
if ( i == myinfo->numswaps && i < sizeof(myinfo->swaps)/sizeof(*myinfo->swaps) )
{
swap = calloc(1,sizeof(*swap));
vcalc_sha256(0,swap->orderhash.bytes,(uint8_t *)rp,sizeof(*rp));
swap->req = *rp;
swap->myinfo = myinfo;
printf("START swap requestid.%u\n",rp->requestid);

2
iguana/coins/genanc

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"maxpeers\":256,\"newcoin\":\"ANC\",\"name\":\"AnonCoin\",\"netmagic\":\"facabada\",\"p2p\":9377,\"rpc\":28332,\"pubval\":23,\"p2shval\":5,\"wifval\":151,\"txfee_satoshis\":\"2000000\",\"minconfirms\":2,\"genesishash\":\"00000be19c5a519257aa921349037d55548af7cabf112741eb905a26bb73e468\",\"genesis\":{\"version\":1,\"timestamp\":1370190760,\"nBits\":\"1e0ffff0\",\"nonce\":347089008,\"merkle_root\":\"7ce7004d764515f9b43cb9f07547c8e2e00d94c9348b3da33c8681d350f2c736\"},\"alertpubkey\":\"04c6db35c11724e526f6725cc5bd5293b4bc9382397856e1bcef7111fb44ce357fd12442b34c496d937a348c1dca1e36ae0c0e128905eb3d301433887e8f0b4536\"}"
curl --url "http://127.0.0.1:7778" --data "{\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"maxpeers\":256,\"newcoin\":\"ANC\",\"name\":\"AnonCoin\",\"netmagic\":\"facabada\",\"p2p\":9377,\"rpc\":28332,\"pubval\":23,\"p2shval\":5,\"wifval\":151,\"txfee_satoshis\":\"2000000\",\"minconfirms\":2,\"genesishash\":\"00000be19c5a519257aa921349037d55548af7cabf112741eb905a26bb73e468\",\"genesis\":{\"version\":1,\"timestamp\":1370190760,\"nBits\":\"1e0ffff0\",\"nonce\":347089008,\"merkle_root\":\"7ce7004d764515f9b43cb9f07547c8e2e00d94c9348b3da33c8681d350f2c736\"},\"alertpubkey\":\"04c6db35c11724e526f6725cc5bd5293b4bc9382397856e1bcef7111fb44ce357fd12442b34c496d937a348c1dca1e36ae0c0e128905eb3d301433887e8f0b4536\",\"protover\":70010}"

2
iguana/coins/genanc.json

@ -1 +1 @@
{"RELAY":1,"VALIDATE":1,"prefetchlag":-1,"poll":10,"active":1,"agent":"iguana","method":"addcoin","maxpeers":256,"newcoin":"ANC","name":"AnonCoin","netmagic":"facabada","p2p":9377,"rpc":28332,"pubval":23,"p2shval":5,"wifval":151,"txfee_satoshis":"2000000","minconfirms":2,"genesishash":"00000be19c5a519257aa921349037d55548af7cabf112741eb905a26bb73e468","genesis":{"version":1,"timestamp":1370190760,"nBits":"1e0ffff0","nonce":347089008,"merkle_root":"7ce7004d764515f9b43cb9f07547c8e2e00d94c9348b3da33c8681d350f2c736"},"alertpubkey":"04c6db35c11724e526f6725cc5bd5293b4bc9382397856e1bcef7111fb44ce357fd12442b34c496d937a348c1dca1e36ae0c0e128905eb3d301433887e8f0b4536"}
{"RELAY":1,"VALIDATE":1,"prefetchlag":-1,"poll":10,"active":1,"agent":"iguana","method":"addcoin","maxpeers":256,"newcoin":"ANC","name":"AnonCoin","netmagic":"facabada","p2p":9377,"rpc":28332,"pubval":23,"p2shval":5,"wifval":151,"txfee_satoshis":"2000000","minconfirms":2,"genesishash":"00000be19c5a519257aa921349037d55548af7cabf112741eb905a26bb73e468","genesis":{"version":1,"timestamp":1370190760,"nBits":"1e0ffff0","nonce":347089008,"merkle_root":"7ce7004d764515f9b43cb9f07547c8e2e00d94c9348b3da33c8681d350f2c736"},"alertpubkey":"04c6db35c11724e526f6725cc5bd5293b4bc9382397856e1bcef7111fb44ce357fd12442b34c496d937a348c1dca1e36ae0c0e128905eb3d301433887e8f0b4536",\"protover\":70010}

3
iguana/exchanges/bitcoin.h

@ -33,7 +33,9 @@
#define SCRIPT_OP_ENDIF 0x68
#define SCRIPT_OP_DROP 0x75
#define SCRIPT_OP_EQUALVERIFY 0x88
#define SCRIPT_OP_SHA256 0xa8
#define SCRIPT_OP_HASH160 0xa9
#define SCRIPT_OP_EQUAL 0x87
#define SCRIPT_OP_CHECKSIG 0xac
#define SCRIPT_OP_CHECKMULTISIG 0xae
@ -49,7 +51,6 @@ int32_t bitcoin_MofNspendscript(uint8_t p2sh_rmd160[20],uint8_t *script,int32_t
int32_t bitcoin_pubkeyspend(uint8_t *script,int32_t n,uint8_t pubkey[66]);
int32_t bitcoin_p2shspend(uint8_t *script,int32_t n,uint8_t rmd160[20]);
int32_t bitcoin_revealsecret160(uint8_t *script,int32_t n,uint8_t secret160[20]);
int32_t bitcoin_standardspend(uint8_t *script,int32_t n,uint8_t rmd160[20]);
int32_t bitcoin_pubkeylen(const uint8_t *pubkey);

2
iguana/iguana777.c

@ -829,6 +829,8 @@ void iguana_callcoinstart(struct supernet_info *myinfo,struct iguana_info *coin)
}
sprintf(dirname,"%s/%s",GLOBAL_TMPDIR,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%s/%s/RT",GLOBAL_TMPDIR,coin->symbol), OS_ensure_directory(dirname);
printf("CALL MARKINIT.%s\n",coin->symbol);
iguana_unspents_markinit(myinfo,coin);
iguana_coinstart(myinfo,coin,coin->initialheight,coin->mapflags);
coin->chain->minconfirms = coin->minconfirms;
coin->started = coin;

72
iguana/iguana_interpreter.c

@ -733,6 +733,7 @@ int32_t iguana_checksig(struct iguana_info *coin,struct iguana_stackdata pubkeya
{
if ( (retval= (bitcoin_verify(coin->ctx,sig,siglen-1,sigtxid,pubkey,plen) == 0)) == 0 )
{
}
if ( 0 )
{
int32_t i; char str[65];
@ -741,8 +742,7 @@ int32_t iguana_checksig(struct iguana_info *coin,struct iguana_stackdata pubkeya
printf(" sig, ");
for (i=0; i<plen; i++)
printf("%02x",pubkey[i]);
printf(" checksig sigtxid.%s\n",bits256_str(str,sigtxid));
}
printf(" checksig sigtxid.%s, retval.%d\n",bits256_str(str,sigtxid),retval);
}
return(retval);
}
@ -785,7 +785,7 @@ int32_t iguana_checkmultisig(struct iguana_info *coin,struct iguana_interpreter
printf("iguana_checkmultisig n.%d != N.%d\n",n,N);
return(0);
}
printf("n.%d stackdepth.%d\n",n,stacks->stackdepth);
//printf("n.%d stackdepth.%d\n",n,stacks->stackdepth);
for (i=0; i<N; i++)
{
if ( stacks->stackdepth <= 0 )
@ -794,9 +794,9 @@ int32_t iguana_checkmultisig(struct iguana_info *coin,struct iguana_interpreter
if ( len == bitcoin_pubkeylen(pubkeys[i]) )
{
numsigners++;
for (j=0; j<33; j++)
printf("%02x",pubkeys[i][j]);
printf(" <- pubkey.[%d]\n",i);
//for (j=0; j<33; j++)
// printf("%02x",pubkeys[i][j]);
//printf(" <- pubkey.[%d]\n",i);
}
else
{
@ -810,7 +810,7 @@ int32_t iguana_checkmultisig(struct iguana_info *coin,struct iguana_interpreter
if ( stacks->stackdepth <= 0 )
return(0);
m = (int32_t)iguana_num(iguana_pop(stacks));
printf("m.%d stackdepth.%d\n",m,stacks->stackdepth);
//printf("m.%d stackdepth.%d\n",m,stacks->stackdepth);
if ( m != M )
{
@ -824,13 +824,13 @@ int32_t iguana_checkmultisig(struct iguana_info *coin,struct iguana_interpreter
siglens[i] = iguana_databuf(sigs[i],iguana_pop(stacks));
if ( siglens[i] <= 0 || siglens[i] > 74 )
break;
for (j=0; j<siglens[i]; j++)
printf("%02x",sigs[i][j]);
printf(" <- sigs[%d]\n",i);
//for (j=0; j<siglens[i]; j++)
// printf("%02x",sigs[i][j]);
//printf(" <- sigs[%d]\n",i);
}
if ( i == numsigners )
{
char str[65]; printf("sigtxid.(%s)\n",bits256_str(str,txhash2));
//char str[65]; printf("sigtxid.(%s)\n",bits256_str(str,txhash2));
if ( stacks->stackdepth > 0 )
iguana_pop(stacks); // for backward compatibility
j = numsigners-1;
@ -849,7 +849,7 @@ int32_t iguana_checkmultisig(struct iguana_info *coin,struct iguana_interpreter
}
}
}
printf("valid.%d j.%d M.%d N.%d numsigners.%d\n",valid,j,M,N,numsigners);
//printf("valid.%d j.%d M.%d N.%d numsigners.%d\n",valid,j,M,N,numsigners);
return(0);
}
@ -858,12 +858,21 @@ int32_t iguana_checklocktimeverify(struct iguana_info *coin,int64_t tx_lockval,u
{
int64_t nLockTime = iguana_num(Snum);
if ( nLockTime < 0 || tx_lockval < 0 )
{
printf("CLTV.0 nLockTime.%lld tx_lockval.%lld\n",(long long)nLockTime,(long long)tx_lockval);
return(-1);
}
else if ( ((tx_lockval < LOCKTIME_THRESHOLD && nLockTime < LOCKTIME_THRESHOLD) ||
(tx_lockval >= LOCKTIME_THRESHOLD && nLockTime >= LOCKTIME_THRESHOLD)) == 0 )
{
printf("CLTV.1 nLockTime.%lld tx_lockval.%lld\n",(long long)nLockTime,(long long)tx_lockval);
return(-1);
}
else if ( nLockTime > tx_lockval )
{
printf("CLTV.2 nLockTime.%lld tx_lockval.%lld\n",(long long)nLockTime,(long long)tx_lockval);
return(-1);
}
return(0);
}
@ -1233,7 +1242,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
errs++;
}
stacks->ifdepth--;
//printf("OP_ENDIF status.%d depth.%d\n",stacks->lastpath[stacks->ifdepth],stacks->stackdepth);
printf("OP_ENDIF status.%d depth.%d\n",stacks->lastpath[stacks->ifdepth],stacks->stackdepth);
break;
case IGUANA_OP_VERIFY:
break;
@ -1323,8 +1332,9 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
{
if ( iguana_cmp(&args[0],&args[1]) == 0 )
iguana_pushdata(stacks,1,0,0);
else iguana_pushdata(stacks,0,0,0);
else
{
iguana_pushdata(stacks,0,0,0);
for (i=0; i<args[0].size; i++)
printf("%02x",args[0].U.pubkey[i]);
printf(" <- args[0]\n");
@ -1336,8 +1346,10 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
}
else if ( (op->flags & IGUANA_CRYPTOFLAG) != 0 )
{
uint8_t rmd160[20]; bits256 hash;
uint8_t rmd160[20],revdatabuf[MAX_SCRIPT_ELEMENT_SIZE]; bits256 hash;
datalen = iguana_databuf(databuf,args[0]);
for (i=0; i<datalen; i++)
revdatabuf[i] = databuf[datalen-1-i];
switch ( op->opcode )
{
case IGUANA_OP_RIPEMD160:
@ -1349,11 +1361,39 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
iguana_pushdata(stacks,0,rmd160,sizeof(rmd160));
break;
case IGUANA_OP_HASH160:
/*if ( datalen == 32 )
{
revcalc_rmd160_sha256(rmd160,*(bits256 *)databuf);
printf("SPECIAL CASE REVERSE\n");
} else
for (i=0; i<32; i++)
printf("%02x",databuf[i]);
printf(" <- databuf\n");
for (i=0; i<32; i++)
printf("%02x",revdatabuf[i]);
printf(" <- revdatabuf\n");
calc_rmd160_sha256(rmd160,revdatabuf,datalen);
for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
printf(" <- rmd160 revdatabuf\n");
revcalc_rmd160_sha256(rmd160,*(bits256 *)databuf);
for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
printf(" <- rmd160 special\n");
calc_rmd160_sha256(rmd160,databuf,datalen);
for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
printf(" <- rmd160 databuf\n");*/
if ( datalen == 32 )
calc_rmd160_sha256(rmd160,revdatabuf,datalen);
else calc_rmd160_sha256(rmd160,databuf,datalen);
iguana_pushdata(stacks,0,rmd160,sizeof(rmd160));
break;
case IGUANA_OP_SHA256:
vcalc_sha256(0,hash.bytes,databuf,datalen);
for (i=0; i<datalen; i++)
printf("%02x",databuf[i]);
printf(" -> sha256 %s\n",bits256_str(str,hash));
iguana_pushdata(stacks,0,hash.bytes,sizeof(hash));
break;
case IGUANA_OP_HASH256:
@ -1376,7 +1416,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
}
else if ( op->opcode == IGUANA_OP_CHECKLOCKTIMEVERIFY ) // former OP_NOP2
{
if ( iguana_checklocktimeverify(coin,nLockTime,V->sequence,args[0]) < 0 )
if ( V->ignore_cltverr == 0 && iguana_checklocktimeverify(coin,nLockTime,V->sequence,args[0]) < 0 )
{
iguana_stack(stacks,args,1,"0","");
errs++;

71
iguana/iguana_payments.c

@ -241,75 +241,6 @@ cJSON *iguana_RTinputsjson(struct supernet_info *myinfo,struct iguana_info *coin
//printf("%s value %.8f -> remains %.8f\n",coinaddr,dstr(value),dstr(remains));
if ( remains <= 0 )
break;
/*continue;
if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 )
{
if ( (spendlen= basilisk_unspentfind(myinfo,coin,&txid,&vout,spendscript,outpt,outpt.value)) > 0 )
{
jaddi(vins,iguana_inputjson(txid,vout,spendscript,spendlen));
total += outpt.value;
remains -= outpt.value;
//printf("%s value %.8f -> remains %.8f\n",coinaddr,dstr(value),dstr(remains));
if ( remains <= 0 )
break;
}
continue;
}
if ( (spendlen= _iguana_RTunspentfind(myinfo,coin,&txid,&vout,spendscript,outpt,outpt.value)) > 0 )
{
jaddi(vins,iguana_inputjson(txid,vout,spendscript,spendlen));
total += outpt.value;
remains -= outpt.value;
//printf("%s value %.8f -> remains %.8f\n",coinaddr,dstr(value),dstr(remains));
if ( remains <= 0 )
break;
continue;
}
if ( (bp= coin->bundles[outpt.hdrsi]) == 0 )
{
printf("no bundle.[%d]\n",outpt.hdrsi);
free_json(vins);
return(0);
}
ramchain = &bp->ramchain;
if ( (rdata= ramchain->H.data) == 0 )
continue;
U = RAMCHAIN_PTR(rdata,Uoffset);
T = RAMCHAIN_PTR(rdata,Toffset);
if ( outpt.unspentind > 0 && outpt.unspentind < rdata->numunspents )
{
u = &U[outpt.unspentind];
if ( (txidind= u->txidind) > 0 && txidind < rdata->numtxids )
{
if ( iguana_RTunspentindfind(myinfo,coin,&outpt2,coinaddr,spendscript,&spendlen,&amount,&height,T[txidind].txid,u->vout,coin->bundlescount-1,0) == 0 && spendlen > 0 )
{
jaddi(vins,iguana_inputjson(T[txidind].txid,u->vout,spendscript,spendlen));
total += outpt.value;
remains -= outpt.value;
//printf("%s value %.8f -> remains %.8f\n",coinaddr,dstr(value),dstr(remains));
if ( remains <= 0 )
break;
}
else
{
char str[65];printf("couldnt get script for %s.%d\n",bits256_str(str,T[txidind].txid),u->vout);
free_json(vins);
return(0);
}
}
else
{
printf("illegal txidind.%d [%d]\n",txidind,outpt.hdrsi);
free_json(vins);
return(0);
}
}
else
{
printf("%s illegal unspentind.u%d [%d]\n",coin->symbol,outpt.unspentind,outpt.hdrsi);
free_json(vins);
return(0);
}*/
}
*totalp = total;
return(vins);
@ -338,7 +269,7 @@ char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,int
if ( flag != 0 )
free_json(privkeys);
}
char str[65]; printf("completed.%d %s signed.(%s)\n",*completedp,bits256_str(str,*signedtxidp),signedtx!=0?signedtx:"");
//char str[65]; printf("completed.%d %s signed.(%s)\n",*completedp,bits256_str(str,*signedtxidp),signedtx!=0?signedtx:"");
return(signedtx);
}

24
iguana/iguana_realtime.c

@ -543,6 +543,30 @@ char *iguana_txidcategory(struct supernet_info *myinfo,struct iguana_info *coin,
} else return("unknown");
}
int32_t iguana_scriptsigextract(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *script,int32_t maxsize,bits256 txid,int32_t vini)
{
return(-1);
}
int32_t iguana_vinifind(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *spentfrom,bits256 txid,int32_t vout)
{
int32_t vini = -1; //char *txbytes; char str[65]; cJSON *txobj;
memset(spentfrom,0,sizeof(*spentfrom));
/*if ( (txbytes= iguana_txbytes(myinfo,swap->bobcoin,txid)) != 0 )
{
if ( (txobj= iguana_hex2json(myinfo,swap->bobcoin,txbytes)) != 0 )
{
if ( (vins= jarray(&n,txobj,"vins")) != 0 && vini < n )
{
} else printf("iguana_vinifind no vins.%p or illegal vini.%d vs n.%d\n",txobj,vini,n);
free_json(txobj);
} else printf("iguana_vinifind couldnt parse %s.(%s)\n",swap->bobcoin->symbol,txbytes);
free(txbytes);
} else printf("iguana_vinifind cant get txbytes for %s.(%s)\n",swap->bobcoin->symbol,bits256_str(str,txid));*/
return(vini);
}
void iguana_RTunmap(uint8_t *ptr,uint32_t len)
{
OS_releasemap(&ptr[-2*sizeof(len)],len+2*sizeof(len));

14
iguana/iguana_scripts.c

@ -34,7 +34,7 @@ int32_t bitcoin_p2shspend(uint8_t *script,int32_t n,uint8_t rmd160[20])
return(n);
}
int32_t bitcoin_revealsecret160(uint8_t *script,int32_t n,uint8_t secret160[20])
int32_t bitcoin_secret160verify(uint8_t *script,int32_t n,uint8_t secret160[20])
{
script[n++] = SCRIPT_OP_HASH160;
script[n++] = 0x14;
@ -44,6 +44,16 @@ int32_t bitcoin_revealsecret160(uint8_t *script,int32_t n,uint8_t secret160[20])
return(n);
}
int32_t bitcoin_secret256spend(uint8_t *script,int32_t n,bits256 secret)
{
script[n++] = SCRIPT_OP_SHA256;
script[n++] = 0x20;
memcpy(&script[n],secret.bytes,0x20);
n += 0x20;
script[n++] = SCRIPT_OP_EQUAL;
return(n);
}
// OP_DUP OP_HASH160 <hash of pubkey> OP_EQUALVERIFY OP_CHECKSIG
int32_t bitcoin_standardspend(uint8_t *script,int32_t n,uint8_t rmd160[20])
{
@ -168,7 +178,7 @@ int32_t bitcoin_cltvscript(uint8_t p2shtype,char *ps2h_coinaddr,uint8_t p2sh_rmd
n = bitcoin_checklocktimeverify(script,n,locktime);
n = bitcoin_standardspend(script,n,rmd160A);
script[n++] = SCRIPT_OP_ELSE;
n = bitcoin_revealsecret160(script,n,secret160);
n = bitcoin_secret160verify(script,n,secret160);
n = bitcoin_standardspend(script,n,rmd160B);
script[n++] = SCRIPT_OP_ENDIF;
calc_rmd160_sha256(p2sh_rmd160,script,n);

56
iguana/iguana_sign.c

@ -22,6 +22,7 @@ int32_t iguana_vinparse(struct iguana_info *coin,int32_t rwflag,uint8_t *seriali
{
int32_t p2shlen,len = 0; uint32_t tmp;
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->prev_hash),msg->prev_hash.bytes);
//char str[65]; printf("prev_hash.(%s)\n",bits256_str(str,msg->prev_hash));
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->prev_vout),&msg->prev_vout);
if ( rwflag == 1 )
{
@ -204,6 +205,7 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
if ( (hexstr= jstr(vinobj,"coinbase")) == 0 )
{
vin->prev_hash = jbits256(vinobj,"txid");
//char str[65]; printf("vin->prev_hash.(%s)\n",bits256_str(str,vin->prev_hash));
vin->prev_vout = jint(vinobj,"vout");
if ( (scriptjson= jobj(vinobj,"scriptSig")) != 0 )
hexstr = jstr(scriptjson,"hex");
@ -212,6 +214,8 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
if ( (obj= jobj(vinobj,"scriptPub")) != 0 || (obj= jobj(vinobj,"scriptPubKey")) != 0 )
{
spendstr = jstr(obj,"hex");
if ( spendstr[0] != 0 )
{
lastbyte = _decode_hex(&spendstr[strlen(spendstr)-2]);
//if ( lastbyte == SCRIPT_OP_CHECKMULTISIG )
// need_op0 = 1;
@ -222,6 +226,7 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
}
}
}
}
if ( (redeemstr= jstr(vinobj,"redeemScript")) == 0 || is_hexstr(redeemstr,(int32_t)strlen(redeemstr)) <= 0 )
{
if ( (obj= jobj(vinobj,"redeemScript")) != 0 )
@ -238,6 +243,7 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
userdata = jstr(obj,"hex");
}
}
//char str[65]; printf("rw.%d prevhash.(%s)\n",rwflag,bits256_str(str,vin->prev_hash));
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(vin->prev_hash),vin->prev_hash.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(vin->prev_vout),&vin->prev_vout);
if ( V != 0 )
@ -299,14 +305,14 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
}
len += n;
} //else printf("iguana_parsevinobj: hex script missing (%s)\n",jprint(vinobj,0));
if ( (pubkeysjson= jarray(&n,vinobj,"pubkeys")) != 0 )
if ( (pubkeysjson= jarray(&n,vinobj,"pubkeys")) != 0 && vin->vinscript != 0 )
{
if ( vin->vinscript == 0 )
/*if ( vin->vinscript == 0 )
{
vin->vinscript = serialized;
vin->vinscript[0] = 0;
vin->scriptlen = 1;
}
}*/
for (i=0; i<n; i++)
{
if ( (pubkeystr= jstr(jitem(pubkeysjson,i),0)) != 0 && (plen= (int32_t)strlen(pubkeystr) >> 1) > 0 )
@ -503,11 +509,13 @@ bits256 bitcoin_sigtxid(struct iguana_info *coin,int32_t height,uint8_t *seriali
}
dest.vins[i].p2shlen = 0;
dest.vins[i].redeemscript = 0;
dest.vins[i].userdata = 0;
dest.vins[i].userdatalen = 0;
}
len = iguana_rwmsgtx(coin,height,1,0,serialized,maxlen,&dest,&txid,vpnstr,0,0,0,suppress_pubkeys);
//for (i=0; i<len; i++)
// printf("%02x",serialized[i]);
//printf(" <- sigtx\n");
//printf(" <- sigtx len.%d supp.%d user[0].%d\n",len,suppress_pubkeys,dest.vins[0].userdatalen);
if ( len > 0 ) // (dest.tx_in != 1 || bits256_nonz(dest.vins[0].prev_hash) != 0) && dest.vins[0].scriptlen > 0 &&
{
#ifdef BTC2_VERSION
@ -593,6 +601,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
iguana_vinobjset(&msg->vins[i],jitem(vins,i),spendscript,sizeof(spendscript));
if ( (n= iguana_vinparse(coin,rwflag,&serialized[len],&msg->vins[i])) < 0 )
return(-1);
//printf("serialized vin.[%02x %02x %02x]\n",serialized[len],serialized[len+1],serialized[len+2]);
if ( msg->vins[i].spendscript == spendscript )
msg->vins[i].spendscript = 0;
//printf("vin.%d n.%d len.%d\n",i,n,len);
@ -694,7 +703,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *txstartp,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,cJSON *txobj,struct vin_info *V)
{
int32_t i,numvins,numvouts,len = 0,rwflag=1; cJSON *array=0; bits256 txid; char vpnstr[64];
int32_t i,j,n,numvins,numvouts,len = 0,rwflag=1; cJSON *array=0; bits256 txid; char vpnstr[64];
memset(&txid,0,sizeof(txid));
memset(msg,0,sizeof(*msg));
*txstartp = 0;
@ -723,8 +732,11 @@ bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin,
{
for (i=0; i<msg->tx_in; i++)
{
//printf("parsetxobj vinobj.%d starts offset.%d\n",i,len);
len += iguana_parsevinobj(myinfo,coin,&serialized[len],maxsize,&msg->vins[i],jitem(array,i),V!=0?&V[i]:0);
n = iguana_parsevinobj(myinfo,coin,&serialized[len],maxsize,&msg->vins[i],jitem(array,i),V!=0?&V[i]:0);
for (j=0; j<8; j++)
printf("%02x",serialized[len+j]);
char str[65]; printf(" <- vinobj.%d starts offset.%d %s\n",i,len,bits256_str(str,msg->vins[i].prev_hash));
len += n;
}
}
}
@ -964,13 +976,14 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign
bitcoin_pubkey33(coin->ctx,vp->signers[j].pubkey,vp->signers[j].privkey);
sig[siglen++] = sighash;
vp->signers[j].siglen = siglen;
/*int32_t i; for (i=0; i<siglen; i++)
/*char str[65]; printf("SIGTXID.(%s) ",bits256_str(str,sigtxid));
int32_t i; for (i=0; i<siglen; i++)
printf("%02x",sig[i]);
printf(" sig, ");
for (i=0; i<plen; i++)
printf("%02x",vp->signers[j].pubkey[i]);
// s2 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1;
char str[65]; printf(" SIGNEDTX.[%02x] siglen.%d priv.%s\n",sig[siglen-1],siglen,bits256_str(str,vp->signers[j].privkey));*/
printf(" SIGNEDTX.[%02x] siglen.%d priv.%s\n",sig[siglen-1],siglen,bits256_str(str,vp->signers[j].privkey));*/
}
if ( sig == 0 || siglen == 0 )
{
@ -980,7 +993,7 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign
if ( bitcoin_verify(coin->ctx,sig,siglen-1,sigtxid,vp->signers[j].pubkey,bitcoin_pubkeylen(vp->signers[j].pubkey)) < 0 )
{
//printf("SIG.%d.%d ERROR siglen.%d\n",vini,j,siglen);
printf("SIG.%d.%d ERROR siglen.%d\n",vini,j,siglen);
}
else
{
@ -989,10 +1002,10 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign
/*int32_t z;
for (z=0; z<siglen-1; z++)
printf("%02x",sig[z]);
printf(" <- sig[%d]n\n",j);
printf(" <- sig[%d]\n",j);
for (z=0; z<33; z++)
printf("%02x",vp->signers[j].pubkey[z]);*/
//printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M);
printf("%02x",vp->signers[j].pubkey[z]);
printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M);*/
}
}
if ( numsigs >= vp->M )
@ -1253,9 +1266,11 @@ cJSON *bitcoin_txoutput(cJSON *txobj,uint8_t *paymentscript,int32_t len,uint64_t
int32_t iguana_interpreter(struct iguana_info *coin,cJSON *logarray,int64_t nLockTime,struct vin_info *V,int32_t numvins)
{
uint8_t script[IGUANA_MAXSCRIPTSIZE],*activescript; char str[IGUANA_MAXSCRIPTSIZE*2+1]; int32_t vini,scriptlen,activescriptlen,errs = 0; cJSON *spendscript,*item;
uint8_t script[IGUANA_MAXSCRIPTSIZE],*activescript,savescript[IGUANA_MAXSCRIPTSIZE]; char str[IGUANA_MAXSCRIPTSIZE*2+1]; int32_t vini,scriptlen,activescriptlen,savelen,errs = 0; cJSON *spendscript,*item;
for (vini=0; vini<numvins; vini++)
{
savelen = V[vini].spendlen;
memcpy(savescript,V[vini].spendscript,savelen);
if ( V[vini].p2shlen > 0 )
{
activescript = V[vini].p2shscript;
@ -1266,12 +1281,15 @@ int32_t iguana_interpreter(struct iguana_info *coin,cJSON *logarray,int64_t nLoc
activescript = V[vini].spendscript;
activescriptlen = V[vini].spendlen;
}
memcpy(V[vini].spendscript,activescript,activescriptlen);
V[vini].spendlen = activescriptlen;
spendscript = iguana_spendasm(coin,activescript,activescriptlen);
if ( activescriptlen < 16 )
continue;
//printf("interpreter.(%s)\n",jprint(spendscript,0));
if ( (scriptlen= bitcoin_assembler(coin,logarray,script,spendscript,1,nLockTime,&V[vini])) < 0 )
{
printf("bitcoin_assembler error scriptlen.%d\n",scriptlen);
errs++;
}
else if ( scriptlen != activescriptlen || memcmp(script,activescript,scriptlen) != 0 )
@ -1280,14 +1298,22 @@ int32_t iguana_interpreter(struct iguana_info *coin,cJSON *logarray,int64_t nLoc
{
item = cJSON_CreateObject();
jaddstr(item,"error","script reconstruction failed");
}
init_hexbytes_noT(str,activescript,activescriptlen);
//printf("activescript.(%s)\n",str);
if ( logarray != 0 )
jaddstr(item,"original",str);
init_hexbytes_noT(str,script,scriptlen);
//printf("reconstructed.(%s)\n",str);
if ( logarray != 0 )
{
jaddstr(item,"reconstructed",str);
jaddi(logarray,item);
} else printf("scriptlen mismatch.%d vs %d or miscompare\n",scriptlen,V[vini].spendlen);
} else printf(" scriptlen mismatch.%d vs %d or miscompare\n",scriptlen,activescriptlen);
errs++;
}
memcpy(V[vini].spendscript,savescript,savelen);
V[vini].spendlen = savelen;
}
if ( errs != 0 )
return(-errs);

68
iguana/iguana_unspents.c

@ -839,7 +839,7 @@ int32_t iguana_staker_sort(struct iguana_info *coin,bits256 *hash2p,uint8_t *ref
int32_t iguana_markedunspents_find(struct iguana_info *coin,int32_t *firstslotp,bits256 txid,int32_t vout)
{
int32_t i; //char str[65];
int32_t i;
*firstslotp = -1;
if ( bits256_nonz(txid) != 0 && vout >= 0 )
{
@ -872,7 +872,7 @@ int32_t iguana_markedunspents_find(struct iguana_info *coin,int32_t *firstslotp,
void iguana_unspents_mark(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins)
{
int32_t i,n,firstslot; int16_t vout; cJSON *item; bits256 txid; char str[65];
int32_t i,n,firstslot; int16_t vout; cJSON *item; bits256 txid; char str[65],fname[1024];
if ( (n= cJSON_GetArraySize(vins)) > 0 )
{
for (i=0; i<n; i++)
@ -889,6 +889,19 @@ void iguana_unspents_mark(struct supernet_info *myinfo,struct iguana_info *coin,
printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,txid),vout);
coin->markedunspents[firstslot] = txid;
coin->markedunspents[firstslot].ushorts[15] = vout;
if ( coin->utxofp == 0 )
{
sprintf(fname,"%s/%s/utxo.dat",GLOBAL_DBDIR,coin->symbol), OS_compatible_path(fname);
if ( (coin->utxofp= fopen(fname,"rb+")) == 0 )
coin->utxofp = fopen(fname,"wb");
else fseek(coin->utxofp,0,SEEK_END);
if ( coin->utxofp != 0 )
{
fwrite(txid.bytes,1,sizeof(txid),coin->utxofp);
fwrite(&vout,1,sizeof(vout),coin->utxofp);
fflush(coin->utxofp);
}
}
}
} else printf("error firstslot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,txid),vout);
}
@ -896,6 +909,57 @@ void iguana_unspents_mark(struct supernet_info *myinfo,struct iguana_info *coin,
}
}
void iguana_unspents_markinit(struct supernet_info *myinfo,struct iguana_info *coin)
{
char *filestr,fname[1024]; FILE *fp; long filesize; bits256 filetxid; cJSON *array,*item; int32_t i,filevout,n,firstslot;
sprintf(fname,"%s/%s/utxo.dat",GLOBAL_DBDIR,coin->symbol), OS_compatible_path(fname);
if ( (fp= fopen(fname,"rb")) != 0 )
{
while ( fread(&filetxid,1,sizeof(filetxid),fp) == sizeof(filetxid) && fread(&filevout,1,sizeof(filevout),fp) == sizeof(filevout) )
{
if ( iguana_markedunspents_find(coin,&firstslot,filetxid,filevout) < 0 )
{
if ( firstslot >= 0 )
{
char str[65]; printf("%s slot.[%d] <- %s/v%d\n",fname,firstslot,bits256_str(str,filetxid),filevout);
coin->markedunspents[firstslot] = filetxid;
coin->markedunspents[firstslot].ushorts[15] = filevout;
}
}
}
fclose(fp);
}
sprintf(fname,"%s/%s/utxo.json",GLOBAL_DBDIR,coin->symbol), OS_compatible_path(fname);
if ( (filestr= OS_filestr(&filesize,fname)) != 0 )
{
if ( (array= cJSON_Parse(filestr)) != 0 )
{
printf("iguana_unspents_markinit.(%s)\n",fname);
if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
filetxid = jbits256i(item,0);
filevout = jinti(item,1);
char str[65]; printf("[%d] %s %d\n",i,bits256_str(str,filetxid),filevout);
if ( iguana_markedunspents_find(coin,&firstslot,filetxid,filevout) < 0 )
{
if ( firstslot >= 0 )
{
char str[65]; printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,filetxid),filevout);
coin->markedunspents[firstslot] = filetxid;
coin->markedunspents[firstslot].ushorts[15] = filevout;
}
}
}
}
free_json(array);
} else printf("parse error.(%s)\n",filestr);
free(filestr);
} else printf("couldnt open.(%s)\n",fname);
}
int32_t iguana_RTunspent_check(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_outpoint outpt)
{
int32_t firstslot;

4
iguana/iguana_wallet.c

@ -39,9 +39,9 @@ struct iguana_waddress *iguana_waddressfind(struct supernet_info *myinfo,struct
{
HASH_ITER(hh,wacct->waddr,waddr,tmp)
{
printf("%s ",waddr->coinaddr);
//printf("%s ",waddr->coinaddr);
}
printf("not in %s\n",wacct->account);
//printf("not in %s\n",wacct->account);
}
//if ( waddr != 0 && coin != 0 && strcmp(coin->symbol,waddr->symbol) != 0 )
// return(0);

4
iguana/swaps/iguana_BTCswap.c

@ -90,7 +90,7 @@ int32_t instantdex_bobscript(uint8_t *script,int32_t n,uint32_t *locktimep,int32
script[n++] = SCRIPT_OP_ELSE;
if ( secretstartp != 0 )
*secretstartp = n + 2;
n = bitcoin_revealsecret160(script,n,secret160);
n = bitcoin_secret160verify(script,n,secret160);
n = bitcoin_pubkeyspend(script,n,pubkeyB);
script[n++] = SCRIPT_OP_ENDIF;
return(n);
@ -1227,7 +1227,7 @@ char *instantdex_bailintx(struct iguana_info *coin,bits256 *txidp,struct bitcoin
bitcoin_txoutput(coin,txobj,scriptv0,scriptv0len,spend->satoshis);
if ( isbob != 0 )
{
scriptv1len = bitcoin_revealsecret160(scriptv1,0,x);
scriptv1len = bitcoin_secret160verify(scriptv1,0,x);
scriptv1len = bitcoin_pubkeyspend(scriptv1,scriptv1len,pubkey);
} else scriptv1len = bitcoin_p2shspend(scriptv1,0,x);
bitcoin_txoutput(coin,txobj,scriptv1,scriptv1len,spend->txfee);

2
iguana/tests/decoderawtransaction

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"decoderawtransaction\",\"params\":[\"010000000169c8bb9e30e3bfc57056198f74ebc2caed7381cba1055e21317ffe28e0c784b40100000069463043022078b5d3634221c1df0ef1f1e5f3eada08e0a16a75aaddfab58a1055debfe9b82f021f644253c88cdabb52c4cf926689828687c2773064491be6565b40a7fd02d72b012103b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828ffffffff028da300000000000017a914d9289297b235c7171c9f56d9d3f1d83c6c73619c87e36d0000000000001976a9148ee61a3161993f4f7b7081259bf5f3322d65d3f888ac5907e857\", 1]}"
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"decoderawtransaction\",\"params\":[\"01000000bee8eb57015ede795f68e677621de3e1155134bad2364caef364de1afea707fee0d663bf11010000001976a9142ad8809cca3878b0f97433b65a0e49799982ccd888acffffffff0210270000000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88ace092f505000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000\", 1]}"

9
includes/iguana_funcs.h

@ -418,7 +418,12 @@ int32_t iguana_unspentindfind(struct supernet_info *myinfo,struct iguana_info *c
int32_t iguana_RTunspentindfind(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_outpoint *outpt,char *coinaddr,uint8_t *spendscript,int32_t *scriptlenp,uint64_t *valuep,int32_t *heightp,bits256 txid,int32_t vout,int32_t lasthdrsi,int32_t mempool);
int32_t iguana_addressvalidate(struct iguana_info *coin,uint8_t *addrtypep,char *address);
int32_t bitcoin_sign(void *ctx,char *symbol,uint8_t *sig,bits256 txhash2,bits256 privkey,int32_t recoverflag);
void revcalc_rmd160_sha256(uint8_t rmd160[20],bits256 revhash);
struct iguana_utxo iguana_utxofind(struct iguana_info *coin,struct iguana_outpoint spentpt,int32_t *RTspendflagp,int32_t lockflag);
int32_t iguana_vinifind(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *spentfrom,bits256 txid,int32_t vout);
int32_t iguana_scriptsigextract(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *script,int32_t maxsize,bits256 txid,int32_t vini);
void iguana_unspents_markinit(struct supernet_info *myinfo,struct iguana_info *coin);
bits256 iguana_str2priv(struct supernet_info *myinfo,struct iguana_info *coin,char *str);
int32_t iguana_RTspentflag(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *RTspendp,int32_t *spentheightp,struct iguana_ramchain *ramchain,struct iguana_outpoint spentpt,int32_t height,int32_t minconf,int32_t maxconf,uint64_t amount);
int32_t iguana_voutscript(struct iguana_info *coin,struct iguana_bundle *bp,uint8_t *scriptspace,char *asmstr,struct iguana_unspent *u,struct iguana_pkhash *p,int32_t txi);
@ -523,6 +528,8 @@ void *iguana_blockzcopyRO(uint8_t zcash,struct iguana_blockRO *dest,int32_t dest
void iguana_blockzcopy(uint8_t zcash,struct iguana_block *dest,struct iguana_block *src);
int32_t iguana_blocksizecheck(char *debugstr,uint8_t zcash,struct iguana_block *block);
void basilisk_miner(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,int32_t maxmillis,char *mineraddr);
int32_t bitcoin_secret160verify(uint8_t *script,int32_t n,uint8_t secret160[20]);
int32_t bitcoin_secret256spend(uint8_t *script,int32_t n,bits256 secret);
int32_t bitcoin_pubkeyspend(uint8_t *script,int32_t n,uint8_t pubkey[66]);
int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,struct iguana_peer *addr,char *blockstr,bits256 hash2,int32_t height);
struct supernet_info *SuperNET_MYINFO(char *passphrase);
@ -578,7 +585,7 @@ void iguana_update_balances(struct supernet_info *myinfo,struct iguana_info *coi
void iguana_RTspendvectors(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp);
int64_t iguana_RTbalance(struct iguana_info *coin,char *coinaddr);
double instantdex_avehbla(struct supernet_info *myinfo,double retvals[4],char *base,char *rel,double basevolume);
int32_t bitcoin_revealsecret160(uint8_t *script,int32_t n,uint8_t secret160[20]);
int32_t bitcoin_secret160verify(uint8_t *script,int32_t n,uint8_t secret160[20]);
int64_t iguana_lockval(int32_t finalized,int64_t locktime);
uint64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_pkhash **Ptrp,uint64_t *supplyp,int32_t *numacctsp,int32_t *nonzp,int32_t *errsp,int32_t lastheight);
int32_t iguana_staker_sort(struct iguana_info *coin,bits256 *hash2p,uint8_t *refrmd160,struct iguana_pkhash *refP,uint64_t *weights,int32_t numweights,bits256 *sortbuf);

3
includes/iguana_structs.h

@ -506,6 +506,7 @@ struct iguana_info
uint64_t histbalance,RTcredits,RTdebits;
void *utxoaddrfileptr; long utxoaddrfilesize;
uint32_t utxoaddrlastcount,*utxoaddroffsets,lastunspentsupdate; uint8_t *utxoaddrtable; bits256 utxoaddrhash;
FILE *utxofp;
bits256 markedunspents[1024];
struct iguana_block *RTblocks[65536]; uint8_t *RTrawdata[65536]; int32_t RTrecvlens[65536],RTnumtx[65536];
struct iguana_RTtxid *RTdataset; struct iguana_RTaddr *RTaddrs;
@ -516,7 +517,7 @@ struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],r
struct vin_info
{
struct iguana_msgvin vin; uint64_t amount; cJSON *extras; bits256 sigtxid;
int32_t M,N,validmask,spendlen,type,p2shlen,numpubkeys,numsigs,height,hashtype,userdatalen,suppress_pubkeys;
int32_t M,N,validmask,spendlen,type,p2shlen,numpubkeys,numsigs,height,hashtype,userdatalen,suppress_pubkeys,ignore_cltverr;
uint32_t sequence,unspentind; struct vin_signer signers[16]; char coinaddr[65];
uint8_t rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE],p2shscript[IGUANA_MAXSCRIPTSIZE],userdata[IGUANA_MAXSCRIPTSIZE];
};

Loading…
Cancel
Save