Browse Source

test

etomic
jl777 8 years ago
parent
commit
eb860744b1
  1. 1
      iguana/dPoW.h
  2. 36
      iguana/dpow/dpow_network.c
  3. 47
      iguana/iguana_init.c
  4. 8
      iguana/iguana_wallet.c
  5. 5
      iguana/tests/dexalladdresses
  6. 3
      iguana/tests/encryptwallet

1
iguana/dPoW.h

@ -148,6 +148,7 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo
int32_t dpow_nanomsg_update(struct supernet_info *myinfo);
int32_t dpow_haveutxo(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,char *coinaddr);
void komodo_assetcoins(int32_t fullnode);
int32_t iguana_isnotarychain(char *symbol);
cJSON *dpow_getinfo(struct supernet_info *myinfo,struct iguana_info *coin);
cJSON *dpow_gettransaction(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid);

36
iguana/dpow/dpow_network.c

@ -214,7 +214,7 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d
if ( strcmp(dexp->handler,"request") == 0 )
{
datalen = dex_rwrequest(0,dexp->packet,&dexreq);
printf("dex_response.%s (%c)\n",dexreq.name,dexreq.func);
//printf("dex_response.%s (%c)\n",dexreq.name,dexreq.func);
if ( (coin= iguana_coinfind(dexreq.name)) != 0 )
{
if ( dexreq.func == 'T' )
@ -290,21 +290,27 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d
char *_dex_sendrequest(struct supernet_info *myinfo,struct dex_request *dexreq)
{
uint8_t packet[sizeof(*dexreq)]; int32_t datalen;
datalen = dex_rwrequest(1,packet,dexreq);
return(dex_reqsend(myinfo,"request",packet,datalen));
if ( iguana_isnotarychain(dexreq->name) >= 0 )
{
datalen = dex_rwrequest(1,packet,dexreq);
return(dex_reqsend(myinfo,"request",packet,datalen));
} else return(clonestr("{\"error\":\"not notarychain\"}"));
}
char *_dex_sendrequeststr(struct supernet_info *myinfo,struct dex_request *dexreq,char *str)
{
uint8_t *packet; int32_t datalen,slen; char *retstr;
slen = (int32_t)strlen(str)+1;
packet = calloc(1,sizeof(*dexreq)+slen);
datalen = dex_rwrequest(1,packet,dexreq);
strcpy((char *)&packet[datalen],str);
datalen += slen;
retstr = dex_reqsend(myinfo,"request",packet,datalen);
free(packet);
return(retstr);
if ( iguana_isnotarychain(dexreq->name) >= 0 )
{
slen = (int32_t)strlen(str)+1;
packet = calloc(1,sizeof(*dexreq)+slen);
datalen = dex_rwrequest(1,packet,dexreq);
strcpy((char *)&packet[datalen],str);
datalen += slen;
retstr = dex_reqsend(myinfo,"request",packet,datalen);
free(packet);
return(retstr);
} else return(clonestr("{\"error\":\"not notarychain\"}"));
}
char *_dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid)
@ -320,7 +326,7 @@ char *_dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 t
char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout)
{
struct dex_request dexreq;
char str[65]; printf("gettxout(%s %s %d)\n",symbol,bits256_str(str,txid),vout);
//char str[65]; printf("gettxout(%s %s %d)\n",symbol,bits256_str(str,txid),vout);
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.hash = txid;
@ -1324,7 +1330,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
{
num++;
//fprintf(stderr,"%d ",size);
printf("REP got %d\n",size);
//printf("REP got %d\n",size);
if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 )
{
nn_send(myinfo->repsock,retstr,(int32_t)strlen(retstr)+1,0);
@ -1341,13 +1347,13 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
{
r = myinfo->dpowipbits[rand() % m];
nn_send(myinfo->repsock,&r,sizeof(r),0);
printf("REP.%08x <- rand ip m.%d %x\n",dexp->crc32,m,r);
//printf("REP.%08x <- rand ip m.%d %x\n",dexp->crc32,m,r);
} else printf("illegal state without dpowipbits?\n");
if ( dex_packetcheck(myinfo,dexp,size) == 0 )
{
nn_send(myinfo->dexsock,dexp,size,0);
nn_send(myinfo->pubsock,dexp,size,0);
printf("REP.%08x -> dexbus and pub, t.%d lag.%d\n",dexp->crc32,dexp->timestamp,(int32_t)(time(NULL)-dexp->timestamp));
//printf("REP.%08x -> dexbus and pub, t.%d lag.%d\n",dexp->crc32,dexp->timestamp,(int32_t)(time(NULL)-dexp->timestamp));
dex_packet(myinfo,dexp,size);
}
}

47
iguana/iguana_init.c

@ -525,9 +525,32 @@ void iguana_coinpurge(struct iguana_info *coin)
coin->active = saved;
}
int32_t iguana_isnotarychain(char *symbol)
{
int32_t i,n,notarychain = -1; char *jsonstr; cJSON *chains;
if ( (jsonstr= dpow_notarychains(0,0,0,0)) != 0 )
{
if ( (chains= cJSON_Parse(jsonstr)) != 0 )
{
if ( (n= cJSON_GetArraySize(chains)) > 0 )
{
for (i=0; i<n; i++)
if ( strcmp(symbol,jstri(chains,i)) == 0 )
{
notarychain = i;
break;
}
}
free_json(chains);
}
free(jsonstr);
}
return(notarychain);
}
struct iguana_info *iguana_coinstart(struct supernet_info *myinfo,struct iguana_info *coin,int32_t initialheight,int32_t mapflags)
{
FILE *fp; char fname[512],*symbol,*jsonstr; cJSON *chains; int32_t j,i,n,iter; long fpos; bits256 lastbundle;
FILE *fp; char fname[512],*symbol; int32_t j,iter; long fpos; bits256 lastbundle;
/*if ( coin->peers == 0 )
{
printf("cant start privatechain directly\n");
@ -575,27 +598,11 @@ struct iguana_info *iguana_coinstart(struct supernet_info *myinfo,struct iguana_
}
}
}
coin->notarychain = -1;
if ( (jsonstr= dpow_notarychains(0,0,0,0)) != 0 )
if ( (coin->notarychain= iguana_isnotarychain(coin->symbol)) >= 0 )
{
if ( (chains= cJSON_Parse(jsonstr)) != 0 )
{
if ( (n= cJSON_GetArraySize(chains)) > 0 )
{
for (i=0; i<n; i++)
if ( strcmp(coin->symbol,jstri(chains,i)) == 0 )
{
printf("SET %s NOTARYCHAIN.%d\n",coin->symbol,i);
coin->notarychain = i;
break;
}
}
free_json(chains);
}
free(jsonstr);
}
if ( coin->notarychain >= 0 )
printf("SET %s NOTARYCHAIN.%d\n",coin->symbol,coin->notarychain);
return(coin);
}
//coin->firstblock = coin->blocks.parsedblocks + 1;
iguana_genesis(myinfo,coin,coin->chain);
int32_t bundlei = -2;

8
iguana/iguana_wallet.c

@ -1367,7 +1367,7 @@ TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout)
THREE_STRINGS(bitcoinrpc,encryptwallet,passphrase,password,permanentfile)
{
char *retstr,buf[128],wifstr[128]; cJSON *retjson; int32_t need_KMD = 0,need_BTC = 0;
char *retstr,buf[128],wifstr[128],*dexstr; cJSON *retjson,*dexjson; int32_t need_KMD = 0,need_BTC = 0;
if ( remoteaddr != 0 || coin == 0 )
return(clonestr("{\"error\":\"no remote encrypt or no coin\"}"));
iguana_walletlock(myinfo,coin);
@ -1414,6 +1414,12 @@ THREE_STRINGS(bitcoinrpc,encryptwallet,passphrase,password,permanentfile)
bitcoin_priv2wif(wifstr,waddr.privkey,128);
jaddstr(retjson,"BTCwif",wifstr);
}
if ( (dexstr= _dex_importaddress(myinfo,coin->symbol,waddr.coinaddr)) != 0 )
{
if ( (dexjson= cJSON_Parse(dexstr)) != 0 )
jadd(retjson,"deximport",dexjson);
free(dexstr);
}
retstr = jprint(retjson,1);
}
//iguana_walletinitcheck(myinfo,coin);

5
iguana/tests/dexalladdresses

@ -1,4 +1,9 @@
#!/bin/bash
echo BTC
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"alladdresses\",\"symbol\":\"BTC\"}"
echo KMD
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"alladdresses\",\"symbol\":\"KMD\"}"
echo MVP
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"alladdresses\",\"symbol\":\"MVP\"}"
echo USD
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"alladdresses\",\"symbol\":\"USD\"}"

3
iguana/tests/encryptwallet

@ -1,2 +1,3 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"encryptwallet\",\"passphrase\":\"test\"}"
../coins/basilisk/kmd
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"KMD\",\"agent\":\"bitcoinrpc\",\"method\":\"encryptwallet\",\"passphrase\":\"test\"}"

Loading…
Cancel
Save