|
@ -16,33 +16,33 @@ |
|
|
#include "../exchanges/bitcoin.h" |
|
|
#include "../exchanges/bitcoin.h" |
|
|
/* https://bitcointalk.org/index.php?topic=1340621.msg13828271#msg13828271
|
|
|
/* https://bitcointalk.org/index.php?topic=1340621.msg13828271#msg13828271
|
|
|
https://bitcointalk.org/index.php?topic=1364951
|
|
|
https://bitcointalk.org/index.php?topic=1364951
|
|
|
Tier Nolan's approach is followed with the following changes: |
|
|
Tier Nolan's approach is followed with the following changes: |
|
|
a) instead of cutting 1000 keypairs, only INSTANTDEX_DECKSIZE are a |
|
|
a) instead of cutting 1000 keypairs, only INSTANTDEX_DECKSIZE are a |
|
|
b) instead of sending the entire 256 bits, it is truncated to 64 bits. With odds of collision being so low, it is dwarfed by the ~0.1% insurance factor. |
|
|
b) instead of sending the entire 256 bits, it is truncated to 64 bits. With odds of collision being so low, it is dwarfed by the ~0.1% insurance factor. |
|
|
c) D is set to 100x the insurance rate of 1/777 12.87% + BTC amount |
|
|
c) D is set to 100x the insurance rate of 1/777 12.87% + BTC amount |
|
|
d) insurance is added to Bob's payment, which is after the deposit and bailin |
|
|
d) insurance is added to Bob's payment, which is after the deposit and bailin |
|
|
e) BEFORE Bob broadcasts deposit, Alice broadcasts BTC denominated fee in cltv so if trade isnt done fee is reclaimed |
|
|
e) BEFORE Bob broadcasts deposit, Alice broadcasts BTC denominated fee in cltv so if trade isnt done fee is reclaimed |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
both fees are standard payments: OP_DUP OP_HASH160 FEE_RMD160 OP_EQUALVERIFY OP_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 |
|
|
Alice altpayment: OP_2 <alice_pubM> <bob_pubN> OP_2 OP_CHECKMULTISIG |
|
|
|
|
|
|
|
|
Bob deposit: if ( (swap->deposit= instantdex_bobtx(myinfo,coinbtc,&swap->deposittxid,swap->otherpubs[0],swap->mypubs[0],swap->privkeys[swap->choosei],reftime,swap->satoshis[1],1)) != 0 ) |
|
|
Bob deposit: if ( (swap->deposit= instantdex_bobtx(myinfo,coinbtc,&swap->deposittxid,swap->otherpubs[0],swap->mypubs[0],swap->privkeys[swap->choosei],reftime,swap->satoshis[1],1)) != 0 ) |
|
|
OP_IF |
|
|
OP_IF |
|
|
<now + INSTANTDEX_LOCKTIME*2> OP_CLTV OP_DROP <alice_pubA0> OP_CHECKSIG |
|
|
<now + INSTANTDEX_LOCKTIME*2> OP_CLTV OP_DROP <alice_pubA0> OP_CHECKSIG |
|
|
OP_ELSE |
|
|
OP_ELSE |
|
|
OP_HASH160 <hash(bob_privN)> OP_EQUALVERIFY <bob_pubB0> OP_CHECKSIG |
|
|
OP_HASH160 <hash(bob_privN)> OP_EQUALVERIFY <bob_pubB0> OP_CHECKSIG |
|
|
OP_ENDIF |
|
|
OP_ENDIF |
|
|
|
|
|
|
|
|
Bob paytx: if ( (swap->payment= instantdex_bobtx(myinfo,coinbtc,&swap->deposittxid,swap->mypubs[1],swap->otherpubs[0],swap->privkeys[swap->otherschoosei],reftime,swap->satoshis[1],0)) != 0 ) |
|
|
Bob paytx: if ( (swap->payment= instantdex_bobtx(myinfo,coinbtc,&swap->deposittxid,swap->mypubs[1],swap->otherpubs[0],swap->privkeys[swap->otherschoosei],reftime,swap->satoshis[1],0)) != 0 ) |
|
|
OP_IF |
|
|
OP_IF |
|
|
<now + INSTANTDEX_LOCKTIME> OP_CLTV OP_DROP <bob_pubB1> OP_CHECKSIG |
|
|
<now + INSTANTDEX_LOCKTIME> OP_CLTV OP_DROP <bob_pubB1> OP_CHECKSIG |
|
|
OP_ELSE |
|
|
OP_ELSE |
|
|
OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG |
|
|
OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG |
|
|
OP_ENDIF |
|
|
OP_ENDIF |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
int32_t instantdex_bobscript(uint8_t *script,int32_t n,int32_t *secretstartp,uint32_t locktime,bits256 cltvpub,uint8_t secret160[20],bits256 destpub) |
|
|
int32_t instantdex_bobscript(uint8_t *script,int32_t n,int32_t *secretstartp,uint32_t locktime,bits256 cltvpub,uint8_t secret160[20],bits256 destpub) |
|
|
{ |
|
|
{ |
|
@ -670,6 +670,7 @@ cJSON *BOB_waitfeefunc(struct supernet_info *myinfo,struct exchange_info *exchan |
|
|
coinbtc = iguana_coinfind("BTC"); |
|
|
coinbtc = iguana_coinfind("BTC"); |
|
|
*serdatap = 0, *serdatalenp = 0; |
|
|
*serdatap = 0, *serdatalenp = 0; |
|
|
strcpy(swap->waitfortx,"fee"); |
|
|
strcpy(swap->waitfortx,"fee"); |
|
|
|
|
|
printf("BOB wait other.%p\n",swap->otherfee); |
|
|
if ( coinbtc != 0 && swap->otherfee != 0 )//swap->deposit == 0 && (retstr= BTC_txconfirmed(myinfo,coinbtc,swap,newjson,swap->otherfee->txid,&swap->otherfee->numconfirms,"feefound",0)) != 0 )
|
|
|
if ( coinbtc != 0 && swap->otherfee != 0 )//swap->deposit == 0 && (retstr= BTC_txconfirmed(myinfo,coinbtc,swap,newjson,swap->otherfee->txid,&swap->otherfee->numconfirms,"feefound",0)) != 0 )
|
|
|
{ |
|
|
{ |
|
|
retstr = swap->otherfee->txbytes; |
|
|
retstr = swap->otherfee->txbytes; |
|
@ -745,6 +746,7 @@ cJSON *ALICE_waitfeefunc(struct supernet_info *myinfo,struct exchange_info *exch |
|
|
coinbtc = iguana_coinfind("BTC"); |
|
|
coinbtc = iguana_coinfind("BTC"); |
|
|
*serdatap = 0, *serdatalenp = 0; |
|
|
*serdatap = 0, *serdatalenp = 0; |
|
|
strcpy(swap->waitfortx,"fee"); |
|
|
strcpy(swap->waitfortx,"fee"); |
|
|
|
|
|
printf("ALICE wait other.%p\n",swap->otherfee); |
|
|
if ( coinbtc != 0 && swap->otherfee != 0 )//&& (retstr= BTC_txconfirmed(myinfo,coinbtc,swap,newjson,swap->otherfee->txid,&swap->otherfee->numconfirms,"feefound",0)) != 0 )
|
|
|
if ( coinbtc != 0 && swap->otherfee != 0 )//&& (retstr= BTC_txconfirmed(myinfo,coinbtc,swap,newjson,swap->otherfee->txid,&swap->otherfee->numconfirms,"feefound",0)) != 0 )
|
|
|
{ |
|
|
{ |
|
|
retstr = swap->otherfee->txbytes; |
|
|
retstr = swap->otherfee->txbytes; |
|
@ -1017,6 +1019,21 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n) |
|
|
return(s); |
|
|
return(s); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct bitcoin_eventitem *instantdex_event(char *cmdstr,cJSON *argjson,cJSON *newjson,uint8_t *serdata,int32_t serdatalen) |
|
|
|
|
|
{ |
|
|
|
|
|
struct bitcoin_eventitem *ptr; |
|
|
|
|
|
ptr = calloc(1,sizeof(*ptr) + serdatalen); |
|
|
|
|
|
strcpy(ptr->cmd,cmdstr); |
|
|
|
|
|
ptr->newjson = jduplicate(newjson); |
|
|
|
|
|
ptr->argjson = jduplicate(argjson); |
|
|
|
|
|
if ( serdatalen != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
memcpy(ptr->serdata,serdata,serdatalen); |
|
|
|
|
|
ptr->serdatalen = serdatalen; |
|
|
|
|
|
} |
|
|
|
|
|
return(ptr); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void instantdex_eventfree(struct bitcoin_eventitem *ptr) |
|
|
void instantdex_eventfree(struct bitcoin_eventitem *ptr) |
|
|
{ |
|
|
{ |
|
|
if ( ptr != 0 ) |
|
|
if ( ptr != 0 ) |
|
|