Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
fb74f7a0ec
  1. 2
      iguana/exchanges777.h
  2. 6
      iguana/iguana_instantdex.c
  3. 6
      iguana/main.c
  4. 22
      iguana/swaps/iguana_BTCswap.c

2
iguana/exchanges777.h

@ -19,7 +19,7 @@
#include <curl/curl.h> #include <curl/curl.h>
#include <curl/easy.h> #include <curl/easy.h>
#define INSTANTDEX_OFFERDURATION 3600 #define INSTANTDEX_OFFERDURATION 300
#define EXCHANGES777_MINPOLLGAP 3 #define EXCHANGES777_MINPOLLGAP 3
#define EXCHANGES777_MAXDEPTH 200 #define EXCHANGES777_MAXDEPTH 200

6
iguana/iguana_instantdex.c

@ -334,6 +334,9 @@ int32_t instantdex_acceptextract(struct instantdex_accept *ap,cJSON *argjson)
ap->orderid = j64bits(argjson,"i"); ap->orderid = j64bits(argjson,"i");
if ( hash.txid != ap->orderid ) if ( hash.txid != ap->orderid )
{ {
int32_t i;
for (i=0; i<sizeof(*ap); i++)
printf("%02x ",((uint8_t *)ap)[i]);
printf("instantdex_acceptset warning %llu != %llu\n",(long long)hash.txid,(long long)ap->orderid); printf("instantdex_acceptset warning %llu != %llu\n",(long long)hash.txid,(long long)ap->orderid);
return(-1); return(-1);
} }
@ -369,6 +372,7 @@ cJSON *instantdex_acceptsendjson(struct instantdex_accept *ap)
jaddnum(json,"d",ap->A.acceptdir); jaddnum(json,"d",ap->A.acceptdir);
jadd64bits(json,"p",ap->A.price64); jadd64bits(json,"p",ap->A.price64);
jadd64bits(json,"v",ap->A.basevolume64); jadd64bits(json,"v",ap->A.basevolume64);
jadd64bits(json,"o",ap->A.offer64);
jadd64bits(json,"i",ap->orderid); jadd64bits(json,"i",ap->orderid);
return(json); return(json);
} }
@ -390,6 +394,8 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms
if ( (traderip= jstr(argjson,"traderip")) != 0 && strcmp(traderip,myinfo->ipaddr) == 0 ) if ( (traderip= jstr(argjson,"traderip")) != 0 && strcmp(traderip,myinfo->ipaddr) == 0 )
{ {
printf("got my own request\n"); printf("got my own request\n");
if ( instantdex_acceptextract(&A,argjson) < 0 )
return(clonestr("{\"error\":\"hash txid mismatches orderid\"}"));
return(clonestr("{\"result\":\"got my own request\"}")); return(clonestr("{\"result\":\"got my own request\"}"));
} }
if ( (orderidstr= jstr(argjson,"id")) != 0 ) if ( (orderidstr= jstr(argjson,"id")) != 0 )

6
iguana/main.c

@ -1099,10 +1099,10 @@ void iguana_main(void *arg)
#ifdef __APPLE__ #ifdef __APPLE__
sleep(1); sleep(1);
char *str; char *str;
strcpy(MYINFO.rpcsymbol,"BTC"); strcpy(MYINFO.rpcsymbol,"BTCD");
iguana_launchcoin(MYINFO.rpcsymbol,cJSON_Parse("{}")); iguana_launchcoin(MYINFO.rpcsymbol,cJSON_Parse("{}"));
if ( 0 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"wallet\":\"password\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":3,\"newcoin\":\"BTC\",\"active\":0}"),0)) != 0 ) if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"wallet\":\"password\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":3,\"newcoin\":\"BTCD\",\"active\":0}"),0)) != 0 )
{ {
printf("got.(%s)\n",str); printf("got.(%s)\n",str);
free(str); free(str);
@ -1110,7 +1110,7 @@ void iguana_main(void *arg)
sleep(1); sleep(1);
static bits256 txid; static bits256 txid;
bitcoin_txtest(iguana_coinfind(MYINFO.rpcsymbol),"000",txid); bitcoin_txtest(iguana_coinfind(MYINFO.rpcsymbol),"000",txid);
getchar(); //getchar();
#endif #endif
} }
if ( arg != 0 ) if ( arg != 0 )

22
iguana/swaps/iguana_BTCswap.c

@ -113,7 +113,7 @@ struct bitcoin_unspent *instantdex_bestfit(struct iguana_info *coin,struct bitco
struct bitcoin_unspent *iguana_unspentsget(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numunspentsp) struct bitcoin_unspent *iguana_unspentsget(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numunspentsp)
{ {
struct bitcoin_unspent *ups = calloc(1,sizeof(*ups)); //uint8_t addrtype; struct bitcoin_unspent *ups = calloc(1,sizeof(*ups)); uint8_t addrtype;
// struct bitcoin_unspent { bits256 txid,privkey; uint64_t value; int32_t vout; }; // struct bitcoin_unspent { bits256 txid,privkey; uint64_t value; int32_t vout; };
*numunspentsp = 0; *numunspentsp = 0;
return(ups); return(ups);
@ -302,11 +302,18 @@ int32_t instantdex_calcx20(char hexstr[41],uint8_t *p2shscript,uint8_t firstbyte
char *instantdex_btcoffer(struct supernet_info *myinfo,struct exchange_info *exchange,char *othercoin,double othervolume,double maxprice) // Bob sending to network (Alice) char *instantdex_btcoffer(struct supernet_info *myinfo,struct exchange_info *exchange,char *othercoin,double othervolume,double maxprice) // Bob sending to network (Alice)
{ {
char *str,coinaddr[64],xstr[41]; uint8_t xscript[64]; struct iguana_info *other; int32_t isbob = 1; char *str,coinaddr[64],xstr[41]; uint8_t xscript[64]; struct iguana_info *other; int32_t isbob = 1;
struct instantdex_accept A; cJSON *newjson; bits256 hash,pub3,sharedprivs[4]; struct instantdex_accept checkA,A; cJSON *newjson; bits256 hash,pub3,sharedprivs[4];
if ( othercoin == 0 || (other= iguana_coinfind(othercoin)) == 0 ) if ( othercoin == 0 || (other= iguana_coinfind(othercoin)) == 0 )
return(clonestr("{\"error\":\"invalid othercoin\"}")); return(clonestr("{\"error\":\"invalid othercoin\"}"));
hash = instantdex_acceptset(&A,othercoin,"BTC",INSTANTDEX_OFFERDURATION,1,-1,maxprice,othervolume,myinfo->myaddr.nxt64bits); hash = instantdex_acceptset(&A,othercoin,"BTC",INSTANTDEX_OFFERDURATION,1,-1,maxprice,othervolume,myinfo->myaddr.nxt64bits);
newjson = instantdex_acceptsendjson(&A); newjson = instantdex_acceptsendjson(&A);
if ( instantdex_acceptextract(&checkA,newjson) < 0 )
{
int32_t i;
for (i=0; i<sizeof(A); i++)
printf("%02x ",((uint8_t *)&A)[i]);
printf("instantdex_btcoffer checkA error\n");
}
if ( instantdex_pubkeyargs(sharedprivs,newjson,4,myinfo->persistent_priv,hash,0x02+isbob) != 4 ) if ( instantdex_pubkeyargs(sharedprivs,newjson,4,myinfo->persistent_priv,hash,0x02+isbob) != 4 )
return(clonestr("{\"error\":\"highly unlikely run of 02 pubkeys\"}")); return(clonestr("{\"error\":\"highly unlikely run of 02 pubkeys\"}"));
pub3 = jbits256(newjson,"B3"); pub3 = jbits256(newjson,"B3");
@ -329,9 +336,10 @@ void instantdex_pendingnotice(struct supernet_info *myinfo,struct exchange_info
ap->pendingvolume64 -= A->A.basevolume64; ap->pendingvolume64 -= A->A.basevolume64;
} }
cJSON *instantdex_newjson(struct supernet_info *myinfo,bits256 *A0p,bits256 *B0p,bits256 *sharedprivs,uint8_t secret160[20],int32_t isbob,cJSON *argjson,bits256 hash) cJSON *instantdex_newjson(struct supernet_info *myinfo,bits256 *A0p,bits256 *B0p,bits256 *sharedprivs,uint8_t secret160[20],int32_t isbob,cJSON *argjson,bits256 hash,struct instantdex_accept *A)
{ {
cJSON *newjson = cJSON_CreateObject(); char *xstr; cJSON *newjson; char *xstr;
newjson = instantdex_acceptsendjson(A);
if ( instantdex_pubkeyargs(sharedprivs,newjson,3+isbob,myinfo->persistent_priv,hash,0x02+isbob) != 3 ) if ( instantdex_pubkeyargs(sharedprivs,newjson,3+isbob,myinfo->persistent_priv,hash,0x02+isbob) != 3 )
return(0); return(0);
if ( isbob == 0 ) if ( isbob == 0 )
@ -370,7 +378,7 @@ char *instantdex_bailinrefund(struct supernet_info *myinfo,struct iguana_info *c
cJSON *instantdex_payout(struct supernet_info *myinfo,struct iguana_info *coin,struct exchange_info *exchange,struct instantdex_accept *A,uint8_t secret160[20],int32_t isbob,bits256 *A0p,bits256 *B0p,bits256 *sharedprivs,bits256 hash,uint64_t satoshis[2],cJSON *argjson) cJSON *instantdex_payout(struct supernet_info *myinfo,struct iguana_info *coin,struct exchange_info *exchange,struct instantdex_accept *A,uint8_t secret160[20],int32_t isbob,bits256 *A0p,bits256 *B0p,bits256 *sharedprivs,bits256 hash,uint64_t satoshis[2],cJSON *argjson)
{ {
cJSON *newjson; char field[32],payoutsigstr[256],*signedpayout; int32_t payoutsiglen; bits256 payouttxid,bailintxid; cJSON *newjson; char field[32],payoutsigstr[256],*signedpayout; int32_t payoutsiglen; bits256 payouttxid,bailintxid;
if ( (newjson= instantdex_newjson(myinfo,A0p,B0p,sharedprivs,secret160,isbob,argjson,hash)) == 0 ) if ( (newjson= instantdex_newjson(myinfo,A0p,B0p,sharedprivs,secret160,isbob,argjson,hash,A)) == 0 )
return(0); return(0);
sprintf(field,"bailintxid%c",'A' + (isbob^1)), bailintxid = jbits256(argjson,field); sprintf(field,"bailintxid%c",'A' + (isbob^1)), bailintxid = jbits256(argjson,field);
sprintf(field,"payoutsig%c",'A' + (isbob^1)); sprintf(field,"payoutsig%c",'A' + (isbob^1));
@ -388,7 +396,7 @@ cJSON *instantdex_payout(struct supernet_info *myinfo,struct iguana_info *coin,s
char *instantdex_advance(struct supernet_info *myinfo,bits256 *sharedprivs,int32_t isbob,cJSON *argjson,bits256 hash,char *addfield,char *nextstate,struct instantdex_accept *A) char *instantdex_advance(struct supernet_info *myinfo,bits256 *sharedprivs,int32_t isbob,cJSON *argjson,bits256 hash,char *addfield,char *nextstate,struct instantdex_accept *A)
{ {
cJSON *newjson; bits256 A0,B0; uint8_t secret160[20]; cJSON *newjson; bits256 A0,B0; uint8_t secret160[20];
if ( (newjson= instantdex_newjson(myinfo,&A0,&B0,sharedprivs,secret160,isbob,argjson,hash)) == 0 ) if ( (newjson= instantdex_newjson(myinfo,&A0,&B0,sharedprivs,secret160,isbob,argjson,hash,A)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap offer null newjson\"}")); return(clonestr("{\"error\":\"instantdex_BTCswap offer null newjson\"}"));
if ( A->statusjson != 0 && jstr(A->statusjson,addfield) != 0 ) if ( A->statusjson != 0 && jstr(A->statusjson,addfield) != 0 )
{ {
@ -425,7 +433,7 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
if ( (ap= instantdex_acceptable(exchange,A,myinfo->myaddr.nxt64bits)) != 0 ) if ( (ap= instantdex_acceptable(exchange,A,myinfo->myaddr.nxt64bits)) != 0 )
{ {
isbob = 0; isbob = 0;
if ( (newjson= instantdex_newjson(myinfo,&A0,&B0,sharedprivs,secret160,isbob,argjson,hash)) == 0 ) if ( (newjson= instantdex_newjson(myinfo,&A0,&B0,sharedprivs,secret160,isbob,argjson,hash,A)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap offer null newjson\"}")); return(clonestr("{\"error\":\"instantdex_BTCswap offer null newjson\"}"));
else else
{ {

Loading…
Cancel
Save