Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
f66cf03851
  1. 17
      basilisk/basilisk_MSG.c
  2. 50
      basilisk/basilisk_swap.c
  3. 9
      iguana/iguana_payments.c
  4. 6
      iguana/iguana_unspents.c
  5. 1
      includes/iguana_funcs.h

17
basilisk/basilisk_MSG.c

@ -47,14 +47,23 @@ int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipb
{ {
keylen = data[len++]; keylen = data[len++];
if ( keylen != sizeof(bits256)+sizeof(uint32_t)*2 ) if ( keylen != sizeof(bits256)+sizeof(uint32_t)*2 )
{
printf("invalid keylen.%d != %d\n",keylen,(int32_t)(sizeof(bits256)+sizeof(uint32_t)*2));
return(0); return(0);
}
key = &data[len], len += keylen; key = &data[len], len += keylen;
if ( len+sizeof(msglen) > datalen ) if ( len+sizeof(msglen) > datalen )
{
printf("processMSG overflow len.%d msglen.%d %d > %d\n",len,msglen,(int32_t)(len+sizeof(msglen)),datalen);
return(0); return(0);
}
len += iguana_rwnum(0,&data[len],sizeof(msglen),&msglen); len += iguana_rwnum(0,&data[len],sizeof(msglen),&msglen);
msg = &data[len], len += msglen; msg = &data[len], len += msglen;
if ( msglen <= 0 || len > datalen ) if ( msglen <= 0 || len > datalen )
{
printf("illegal msglen.%d or len.%d > %d\n",msglen,len,datalen);
return(0); return(0);
}
//printf("i.%d: keylen.%d msglen.%d\n",i,keylen,msglen); //printf("i.%d: keylen.%d msglen.%d\n",i,keylen,msglen);
basilisk_respond_addmessage(myinfo,key,keylen,msg,msglen,0); basilisk_respond_addmessage(myinfo,key,keylen,msg,msglen,0);
} }
@ -73,7 +82,7 @@ int32_t basilisk_ping_genMSG(struct supernet_info *myinfo,uint8_t *data,int32_t
datalen += iguana_rwnum(1,&data[datalen],sizeof(msg->datalen),&msg->datalen); datalen += iguana_rwnum(1,&data[datalen],sizeof(msg->datalen),&msg->datalen);
if ( maxlen > datalen+msg->datalen ) if ( maxlen > datalen+msg->datalen )
{ {
//printf("SEND keylen.%d msglen.%d\n",msg->keylen,msg->datalen); printf("SEND keylen.%d msglen.%d\n",msg->keylen,msg->datalen);
memcpy(&data[datalen],msg->data,msg->datalen), datalen += msg->datalen; memcpy(&data[datalen],msg->data,msg->datalen), datalen += msg->datalen;
} }
else else
@ -136,7 +145,7 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha
{ {
int32_t keylen; uint8_t key[64]; int32_t keylen; uint8_t key[64];
keylen = basilisk_messagekey(key,hash,valsobj); keylen = basilisk_messagekey(key,hash,valsobj);
//char str[65]; printf("%s channel.%u msgid.%u datalen.%d\n",bits256_str(str,hash),juint(valsobj,"channel"),juint(valsobj,"msgid"),datalen); char str[65]; printf("%s channel.%u msgid.%u datalen.%d\n",bits256_str(str,hash),juint(valsobj,"channel"),juint(valsobj,"msgid"),datalen);
return(basilisk_respond_getmessage(myinfo,key,keylen)); return(basilisk_respond_getmessage(myinfo,key,keylen));
} }
@ -180,7 +189,7 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t
valsobj = cJSON_CreateObject(); valsobj = cJSON_CreateObject();
jaddnum(valsobj,"channel",channel); jaddnum(valsobj,"channel",channel);
jaddnum(valsobj,"msgid",msgid); jaddnum(valsobj,"msgid",msgid);
//char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s\n",datalen,channel,msgid,bits256_str(str,hash)); char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s\n",datalen,channel,msgid,bits256_str(str,hash));
if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,hash,valsobj,hexstr)) != 0 ) if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,hash,valsobj,hexstr)) != 0 )
{ {
retval = 0; retval = 0;
@ -221,7 +230,7 @@ int32_t basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t c
jaddnum(valsobj,"fanout",1); jaddnum(valsobj,"fanout",1);
if ( (retstr= basilisk_getmessage(myinfo,0,0,0,hash,valsobj,0)) != 0 ) if ( (retstr= basilisk_getmessage(myinfo,0,0,0,hash,valsobj,0)) != 0 )
{ {
//printf("gotmessage.(%s)\n",retstr); printf("gotmessage.(%s)\n",retstr);
if ( (retarray= cJSON_Parse(retstr)) != 0 ) if ( (retarray= cJSON_Parse(retstr)) != 0 )
{ {
if ( is_cJSON_Array(retarray) != 0 ) if ( is_cJSON_Array(retarray) != 0 )

50
basilisk/basilisk_swap.c

@ -909,20 +909,24 @@ void basilisk_swap01(struct supernet_info *myinfo,struct basilisk_swap *swap,uin
{ {
int32_t datalen; int32_t datalen;
datalen = basilisk_swapdata_deck(myinfo,swap,data,maxlen); datalen = basilisk_swapdata_deck(myinfo,swap,data,maxlen);
printf("send deck.%d\n",datalen);
swap->statebits |= basilisk_swapsend(myinfo,swap,0x02,data,datalen,0x01); swap->statebits |= basilisk_swapsend(myinfo,swap,0x02,data,datalen,0x01);
} }
void basilisk_swap02(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) void basilisk_swap02(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{ {
basilisk_swap01(myinfo,swap,data,maxlen); if ( (rand() % 100) == 0 )
basilisk_swap01(myinfo,swap,data,maxlen);
printf("check for other deck\n");
if ( basilisk_swapget(myinfo,swap,0x02,data,maxlen,basilisk_verify_otherdeck) == 0 ) if ( basilisk_swapget(myinfo,swap,0x02,data,maxlen,basilisk_verify_otherdeck) == 0 )
swap->statebits |= 0x02; swap->statebits |= 0x02;
} }
void basilisk_swap04(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) void basilisk_swap04(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{ {
int32_t i,datalen; int32_t i,datalen; char str[65];
basilisk_swap02(myinfo,swap,data,maxlen); if ( (rand() % 10) == 0 )
basilisk_swap02(myinfo,swap,data,maxlen);
datalen = iguana_rwnum(1,data,sizeof(swap->choosei),&swap->choosei); datalen = iguana_rwnum(1,data,sizeof(swap->choosei),&swap->choosei);
if ( swap->iambob != 0 ) if ( swap->iambob != 0 )
{ {
@ -930,6 +934,7 @@ void basilisk_swap04(struct supernet_info *myinfo,struct basilisk_swap *swap,uin
data[datalen++] = swap->pubB0.bytes[i]; data[datalen++] = swap->pubB0.bytes[i];
for (i=0; i<32; i++) for (i=0; i<32; i++)
data[datalen++] = swap->pubB1.bytes[i]; data[datalen++] = swap->pubB1.bytes[i];
printf("SEND pubB0/1 %s\n",bits256_str(str,swap->pubB0));
} }
else else
{ {
@ -937,33 +942,40 @@ void basilisk_swap04(struct supernet_info *myinfo,struct basilisk_swap *swap,uin
data[datalen++] = swap->pubA0.bytes[i]; data[datalen++] = swap->pubA0.bytes[i];
for (i=0; i<32; i++) for (i=0; i<32; i++)
data[datalen++] = swap->pubA1.bytes[i]; data[datalen++] = swap->pubA1.bytes[i];
char str[65]; printf("SEND pubA0/1 %s\n",bits256_str(str,swap->pubA0)); printf("SEND pubA0/1 %s\n",bits256_str(str,swap->pubA0));
} }
swap->statebits |= basilisk_swapsend(myinfo,swap,0x08,data,datalen,0x04); swap->statebits |= basilisk_swapsend(myinfo,swap,0x08,data,datalen,0x04);
} }
void basilisk_swap08(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) void basilisk_swap08(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{ {
uint8_t pubkey33[33]; uint8_t pubkey33[33]; char str[65];
basilisk_swap04(myinfo,swap,data,maxlen); if ( (rand() % 10) == 0 )
basilisk_swap04(myinfo,swap,data,maxlen);
printf("check otherchoosei\n");
if ( basilisk_swapget(myinfo,swap,0x08,data,maxlen,basilisk_verify_choosei) == 0 ) if ( basilisk_swapget(myinfo,swap,0x08,data,maxlen,basilisk_verify_choosei) == 0 )
{ {
char str[65];
if ( swap->iambob != 0 ) if ( swap->iambob != 0 )
{ {
swap->privBn = swap->privkeys[swap->otherchoosei]; if ( bits256_nonz(swap->privBn) == 0 )
memset(&swap->privkeys[swap->otherchoosei],0,sizeof(swap->privkeys[swap->otherchoosei])); {
calc_rmd160_sha256(swap->secretBn,swap->privBn.bytes,sizeof(swap->privBn)); swap->privBn = swap->privkeys[swap->otherchoosei];
swap->pubBn = bitcoin_pubkey33(myinfo->ctx,pubkey33,swap->privBn); memset(&swap->privkeys[swap->otherchoosei],0,sizeof(swap->privkeys[swap->otherchoosei]));
printf("set privBn.%s\n",bits256_str(str,swap->privBn)); calc_rmd160_sha256(swap->secretBn,swap->privBn.bytes,sizeof(swap->privBn));
swap->pubBn = bitcoin_pubkey33(myinfo->ctx,pubkey33,swap->privBn);
printf("set privBn.%s\n",bits256_str(str,swap->privBn));
}
} }
else else
{ {
swap->privAm = swap->privkeys[swap->otherchoosei]; if ( bits256_nonz(swap->privAm) == 0 )
memset(&swap->privkeys[swap->otherchoosei],0,sizeof(swap->privkeys[swap->otherchoosei])); {
calc_rmd160_sha256(swap->secretAm,swap->privAm.bytes,sizeof(swap->privAm)); swap->privAm = swap->privkeys[swap->otherchoosei];
swap->pubAm = bitcoin_pubkey33(myinfo->ctx,pubkey33,swap->privAm); memset(&swap->privkeys[swap->otherchoosei],0,sizeof(swap->privkeys[swap->otherchoosei]));
printf("set privAm.%s\n",bits256_str(str,swap->privAm)); calc_rmd160_sha256(swap->secretAm,swap->privAm.bytes,sizeof(swap->privAm));
swap->pubAm = bitcoin_pubkey33(myinfo->ctx,pubkey33,swap->privAm);
printf("set privAm.%s\n",bits256_str(str,swap->privAm));
}
} }
swap->statebits |= 0x08; swap->statebits |= 0x08;
} }
@ -972,7 +984,8 @@ void basilisk_swap08(struct supernet_info *myinfo,struct basilisk_swap *swap,uin
void basilisk_swap10(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) void basilisk_swap10(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{ {
int32_t i,j,datalen; int32_t i,j,datalen;
basilisk_swap08(myinfo,swap,data,maxlen); if ( (rand() % 10) == 0 )
basilisk_swap08(myinfo,swap,data,maxlen);
datalen = 0; datalen = 0;
for (i=0; i<sizeof(swap->privkeys)/sizeof(*swap->privkeys); i++) for (i=0; i<sizeof(swap->privkeys)/sizeof(*swap->privkeys); i++)
{ {
@ -993,6 +1006,7 @@ void basilisk_swap10(struct supernet_info *myinfo,struct basilisk_swap *swap,uin
for (i=0; i<20; i++) for (i=0; i<20; i++)
data[datalen++] = swap->secretAm[i]; data[datalen++] = swap->secretAm[i];
} }
printf("send privkeys.%d\n",datalen);
swap->statebits |= basilisk_swapsend(myinfo,swap,0x20,data,datalen,0x10); swap->statebits |= basilisk_swapsend(myinfo,swap,0x20,data,datalen,0x10);
} }

9
iguana/iguana_payments.c

@ -162,7 +162,7 @@ cJSON *iguana_scriptobj(struct iguana_info *coin,uint8_t rmd160[20],char *coinad
return(scriptobj); return(scriptobj);
} }
int32_t iguana_bestunspent(struct iguana_info *coin,int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,int64_t *unspents,int32_t numunspents,uint64_t value) int32_t iguana_bestunspent(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,int64_t *unspents,int32_t numunspents,uint64_t value)
{ {
int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; int32_t i,abovei,belowi; int64_t above,below,gap,atx_value;
abovei = belowi = -1; abovei = belowi = -1;
@ -170,6 +170,11 @@ int32_t iguana_bestunspent(struct iguana_info *coin,int32_t *aboveip,int64_t *ab
{ {
if ( (atx_value= unspents[(i << 1) + 1]) <= 0 ) if ( (atx_value= unspents[(i << 1) + 1]) <= 0 )
continue; continue;
if ( iguana_unspent_check(myinfo,coin,(uint16_t)(unspents[i << 1] >> 32),(uint32_t)unspents[i << 1]) != 0 )
{
printf("(%d u%d) %.8f already used\n",(uint16_t)(unspents[i << 1] >> 32),(uint32_t)unspents[i << 1],dstr(atx_value));
continue;
}
//printf("(%.8f vs %.8f)\n",dstr(atx_value),dstr(value)); //printf("(%.8f vs %.8f)\n",dstr(atx_value),dstr(value));
if ( atx_value == value ) if ( atx_value == value )
{ {
@ -220,7 +225,7 @@ cJSON *iguana_inputsjson(struct supernet_info *myinfo,struct iguana_info *coin,i
for (i=0; i<num; i++) for (i=0; i<num; i++)
{ {
below = above = 0; below = above = 0;
if ( iguana_bestunspent(coin,&abovei,&above,&belowi,&below,unspents,num,remains) < 0 ) if ( iguana_bestunspent(myinfo,coin,&abovei,&above,&belowi,&below,unspents,num,remains) < 0 )
{ {
printf("error finding unspent i.%d of %d, %.8f vs %.8f\n",i,num,dstr(remains),dstr(amount)); printf("error finding unspent i.%d of %d, %.8f vs %.8f\n",i,num,dstr(remains),dstr(amount));
free_json(vins); free_json(vins);

6
iguana/iguana_unspents.c

@ -544,12 +544,15 @@ int32_t iguana_unspent_check(struct supernet_info *myinfo,struct iguana_info *co
memset(&txid,0,sizeof(txid)); memset(&txid,0,sizeof(txid));
if ( iguana_unspentind2txid(myinfo,coin,&spentheight,&txid,&vout,hdrsi,unspentind) == 0 ) if ( iguana_unspentind2txid(myinfo,coin,&spentheight,&txid,&vout,hdrsi,unspentind) == 0 )
{ {
char str[65]; printf("verify %s/v%d is not already used\n",bits256_str(str,txid),vout);
if ( basilisk_addspend(myinfo,coin->symbol,txid,vout,0) != 0 ) if ( basilisk_addspend(myinfo,coin->symbol,txid,vout,0) != 0 )
{ {
char str[65]; printf("iguana_unspent_check found unspentind (%u %d) %s\n",hdrsi,unspentind,bits256_str(str,txid)); char str[65]; printf("iguana_unspent_check found unspentind (%u %d) %s\n",hdrsi,unspentind,bits256_str(str,txid));
return(1); return(1);
} else return(0); } else return(0);
} else return(-1); }
printf("iguana_unspent_check: couldnt find (%d %d)\n",hdrsi,unspentind);
return(-1);
} }
int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *totalp,int64_t *unspents,int32_t max,int64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr) int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *totalp,int64_t *unspents,int32_t max,int64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr)
@ -582,6 +585,7 @@ int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *co
unspentind = (int32_t)*unspents; unspentind = (int32_t)*unspents;
if ( iguana_unspent_check(myinfo,coin,hdrsi,unspentind) == 0 ) if ( iguana_unspent_check(myinfo,coin,hdrsi,unspentind) == 0 )
{ {
printf("(%d u%d) %.8f not in mempool\n",hdrsi,unspentind,dstr(unspents[1]));
sum += unspents[1]; sum += unspents[1];
unspents += 2; unspents += 2;
numunspents++; numunspents++;

1
includes/iguana_funcs.h

@ -473,6 +473,7 @@ int64_t datachain_update(struct supernet_info *myinfo,int32_t ordered,struct igu
void datachain_update_spend(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,int32_t height,bits256 txid,int32_t vout,uint8_t rmd160[20],int64_t value); void datachain_update_spend(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,int32_t height,bits256 txid,int32_t vout,uint8_t rmd160[20],int64_t value);
cJSON *bitcoin_data2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,uint8_t *extraspace,int32_t extralen,uint8_t *serialized,int32_t len); cJSON *bitcoin_data2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,uint8_t *extraspace,int32_t extralen,uint8_t *serialized,int32_t len);
int32_t iguana_unspentind2txid(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *spentheightp,bits256 *txidp,int32_t *voutp,int16_t hdrsi,uint32_t unspentind); int32_t iguana_unspentind2txid(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *spentheightp,bits256 *txidp,int32_t *voutp,int16_t hdrsi,uint32_t unspentind);
int32_t iguana_unspent_check(struct supernet_info *myinfo,struct iguana_info *coin,uint16_t hdrsi,uint32_t unspentind);
char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkey,struct vin_info *V); char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkey,struct vin_info *V);
bits256 scrypt_blockhash(const void *input); bits256 scrypt_blockhash(const void *input);

Loading…
Cancel
Save