Skip to content

Commit

Permalink
Made changes to remove redundant logs in the backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
sg777 committed Oct 22, 2019
1 parent b38c4ca commit bcc864f
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 90 deletions.
1 change: 1 addition & 0 deletions privatebet/bet.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ int main(int argc, char **argv)
uint32_t i,range,numplayers; int32_t pubsock=-1,subsock=-1,pullsock=-1,pushsock=-1;
pthread_t dcv_t,bvv_t,player_t,dcv_backend,bvv_backend,player_backend;

BET_listaddressgroupings();
#if 1
if(argc>=2)
strcpy(hostip,argv[2]);
Expand Down
55 changes: 17 additions & 38 deletions privatebet/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ Below code is aimed to implement p2p Pangea

int32_t BET_p2p_bvv_init(cJSON *argjson,struct privatebet_info *bet,struct privatebet_vars *vars)
{
int32_t bytes,retval=1;
int32_t bytes,retval=0;
char *rendered,str[65],enc_str[177];
cJSON *cjsondcvblindcards,*cjsonpeerpubkeys,*bvv_init_info,*cjsonbvvblindcards,*cjsonshamirshards;
bits256 dcvblindcards[CARDS777_MAXPLAYERS][CARDS777_MAXCARDS],peerpubkeys[CARDS777_MAXPLAYERS];
Expand Down Expand Up @@ -317,7 +317,6 @@ int32_t BET_p2p_bvv_init(cJSON *argjson,struct privatebet_info *bet,struct priva
{
p2p_bvv_init(peerpubkeys,bvv_info.bvv_key,bvvblindingvalues[playerid],bvvblindcards[playerid],
dcvblindcards[playerid],bet->range,bvv_info.numplayers,playerid,bvv_info.deckid);
//sleep(5);

}

Expand Down Expand Up @@ -348,20 +347,16 @@ int32_t BET_p2p_bvv_init(cJSON *argjson,struct privatebet_info *bet,struct priva
bytes=nn_send(bet->pushsock,rendered,strlen(rendered),0);

if(bytes<0)
{
retval=-1;
printf("\n%s:%d: Failed to send data",__FUNCTION__,__LINE__);
goto end;
}
end:
return retval;

return retval;

}

int32_t BET_p2p_bvv_join_init(cJSON *argjson,struct privatebet_info *bet,struct privatebet_vars *vars)
{
cJSON *channelInfo=NULL,*addresses,*address,*bvvResponseInfo=NULL;
int argc,bytes,retval=1;
int argc,bytes,retval=0;
char **argv=NULL,*uri=NULL,*rendered=NULL;
argc=3;
argv=(char**)malloc(argc*sizeof(char*));
Expand All @@ -387,6 +382,7 @@ int32_t BET_p2p_bvv_join_init(cJSON *argjson,struct privatebet_info *bet,struct
uri=(char*)malloc(sizeof(char)*100);
if(!uri)
{
retval=-1;
printf("%s::%d::malloc failed\n",__FUNCTION__,__LINE__);
goto end;
}
Expand All @@ -401,16 +397,14 @@ int32_t BET_p2p_bvv_join_init(cJSON *argjson,struct privatebet_info *bet,struct
cJSON_AddStringToObject(bvvResponseInfo,"uri",uri);
printf("%s::%d::uri::%s\n",__FUNCTION__,__LINE__,uri);
rendered=cJSON_Print(bvvResponseInfo);
bytes=nn_send(bet->pushsock,rendered,strlen(rendered),0);

bytes=nn_send(bet->pushsock,rendered,strlen(rendered),0);


if(bytes<0)
{
retval=-1;
printf("\n%s:%d: Failed to send data",__FUNCTION__,__LINE__);
goto end;
}
end:

end:
if(uri)
free(uri);
if(argv)
Expand Down Expand Up @@ -488,7 +482,7 @@ cJSON* BET_p2p_fundchannel(char *channel_id)

int32_t BET_p2P_check_bvv_ready(cJSON *argjson,struct privatebet_info *bet,struct privatebet_vars *vars)
{
int retval,channel_state,bytes;
int retval=0,channel_state,bytes;
cJSON *uriInfo=NULL,*fundChannelInfo=NULL,*bvvReady=NULL;
char uri[100],channel_id[100],*rendered=NULL;

Expand Down Expand Up @@ -543,6 +537,7 @@ int32_t BET_p2P_check_bvv_ready(cJSON *argjson,struct privatebet_info *bet,struc
bytes=nn_send(bet->pushsock,rendered,strlen(rendered),0);
if(bytes<0)
retval=-1;

end:
return retval;
}
Expand Down Expand Up @@ -577,7 +572,7 @@ void BET_BVV_reset(struct privatebet_info *bet,struct privatebet_vars *vars)
int32_t BET_bvv_frontend(struct lws *wsi, cJSON *argjson)
{
char *method;
int32_t retval=1;
int32_t retval=0;
struct privatebet_info *bet=NULL;
struct privatebet_vars *vars=NULL;
if ( (method= jstr(argjson,"method")) != 0 )
Expand Down Expand Up @@ -609,12 +604,6 @@ int32_t BET_bvv_frontend(struct lws *wsi, cJSON *argjson)
BET_BVV_reset(bet,vars);

}
else if(strcmp(method,"seats") == 0)
{
printf("\n%s:%d::%s",__FUNCTION__,__LINE__,cJSON_Print(argjson));
}
else
retval=-1;
}
return retval;
}
Expand Down Expand Up @@ -646,7 +635,7 @@ void BET_bvv_backend_loop(void *_ptr)
bvvJoinInfo=cJSON_CreateObject();

cJSON_AddStringToObject(bvvJoinInfo,"method","bvv_join");
if ( BET_bvv_backend(bvvJoinInfo,bet,VARS) < 0 )
if ( BET_bvv_backend(bvvJoinInfo,bet,VARS) != 0 )
{
printf("\n%s:%d:BVV joining the table failed",__FUNCTION__,__LINE__);
}
Expand All @@ -665,7 +654,7 @@ void BET_bvv_backend_loop(void *_ptr)
{
if ( BET_bvv_backend(argjson,bet,BVV_VARS) != 0 ) // usually just relay to players
{
// do soemthing incase any command or logic failures
printf("%s::%d::Failed to send data\n",__FUNCTION__,__LINE__);
}
free_json(argjson);
}
Expand All @@ -683,7 +672,7 @@ void BET_bvv_backend_loop(void *_ptr)

int32_t BET_bvv_backend(cJSON *argjson,struct privatebet_info *bet,struct privatebet_vars *vars)
{
char *method; int32_t retval=1;
char *method; int32_t retval=0;

if ( (method= jstr(argjson,"method")) != 0 )
{
Expand All @@ -706,24 +695,16 @@ int32_t BET_bvv_backend(cJSON *argjson,struct privatebet_info *bet,struct privat
{
retval=BET_p2P_check_bvv_ready(argjson,bet,vars);
}
else if(strcmp(method,"dealer") == 0)
{
//retval=BET_p2p_dealer_info(argjson,bet,vars);
}
else if(strcmp(method,"reset") == 0)
{
printf("%s::%d::method::%s\n",__FUNCTION__,__LINE__,method);
BET_BVV_reset(bet,vars);
retval=BET_p2p_bvv_join_init(argjson,BET_bvv,vars);
}
else if(strcmp(method,"seats") == 0)
{
printf("\n%s:%d::%s",__FUNCTION__,__LINE__,cJSON_Print(argjson));
retval=BET_p2p_bvv_join_init(argjson,bet,vars);
}
else
retval=-1;
}
}
return retval;
}

Expand Down Expand Up @@ -1959,8 +1940,7 @@ int lws_callback_http_bvv(struct lws *wsi, enum lws_callback_reasons reason,
if (!lws_is_final_fragment(wsi))
break;
argjson=cJSON_Parse(lws_buf_bvv);
printf("%s::%d::%s\n",__FUNCTION__,__LINE__,cJSON_Print(argjson));
if( BET_bvv_frontend(wsi,argjson) != 1 )
if( BET_bvv_frontend(wsi,argjson) != 0 )
{
printf("\n%s:%d:Failed to process the host command",__FUNCTION__,__LINE__);
}
Expand All @@ -1969,7 +1949,6 @@ int lws_callback_http_bvv(struct lws *wsi, enum lws_callback_reasons reason,
break;
case LWS_CALLBACK_ESTABLISHED:
wsi_global_bvv=wsi;
printf("\n%s:%d::LWS_CALLBACK_ESTABLISHED\n",__FUNCTION__,__LINE__);
break;
}
return 0;
Expand Down
61 changes: 61 additions & 0 deletions privatebet/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,67 @@ char BET_ORACLEURL[64] = "127.0.0.1:7797";
int32_t IAMORACLE;
char *multisigAddress="bGmKoyJEz4ESuJCTjhVkgEb2Qkt8QuiQzQ";

int BET_validateaddress(char* address)
{
int argc,maxsize=1000;
char **argv=NULL;
cJSON *addressInfo=NULL;
argc=3;

argv=(char**)malloc(argc*sizeof(char*));
for(int i=0;i<argc;i++)
{
argv[i]=(char*)malloc(maxsize*sizeof(char));
}
strcpy(argv[0],"chips-cli");
strcpy(argv[1],"validateaddress");
strcpy(argv[2],address);
make_command(argc,argv,&addressInfo);

cJSON *temp=cJSON_GetObjectItem(addressInfo,"ismine");
if(strcmp(cJSON_Print(temp),"true")==0)
{
return 1;
}
else
return 0;
}


void BET_listaddressgroupings()
{
int argc,maxsize=1000;
char **argv=NULL;
cJSON *listaddressgroupingsInfo=NULL;

argc=3;
argv=(char**)malloc(argc*sizeof(char*));
for(int i=0;i<argc;i++)
{
argv[i]=(char*)malloc(maxsize*sizeof(char));
}
argc=2;
strcpy(argv[0],"chips-cli");
strcpy(argv[1],"listaddressgroupings");
make_command(argc,argv,&listaddressgroupingsInfo);

for(int i=0;i<cJSON_GetArraySize(listaddressgroupingsInfo);i++)
{
cJSON *addressInfo=cJSON_GetArrayItem(listaddressgroupingsInfo,i);
for(int j=0;j<cJSON_GetArraySize(addressInfo);j++)
{
cJSON *temp=NULL;
temp=cJSON_GetArrayItem(addressInfo,j);
cJSON *address=cJSON_GetArrayItem(temp,0);
if(BET_validateaddress(cJSON_Print(address))==1)
{

printf("%s::%f\n",cJSON_Print(address),atof(cJSON_Print(cJSON_GetArrayItem(temp,1))));
}
}
}

}
cJSON* BET_transferfunds(double amount)
{
cJSON *txInfo=NULL;
Expand Down
2 changes: 2 additions & 0 deletions privatebet/commands.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

int BET_validateaddress(char* address);
void BET_listaddressgroupings();
cJSON* BET_transferfunds(double amount);
cJSON* BET_sendrawtransaction(cJSON *signedTransaction);
cJSON* BET_signrawtransactionwithwallet(char *rawtransaction);
Expand Down
65 changes: 21 additions & 44 deletions privatebet/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -1685,15 +1685,8 @@ int32_t BET_create_invoice(cJSON *argjson,struct privatebet_info *bet,struct pri
invoice=cJSON_CreateObject();
make_command(argc,argv,&invoice);

//ln_bet(argc,argv,buf);
//invoice=cJSON_CreateObject();
//invoice=cJSON_Parse(buf);
if(jint(invoice,"code") != 0)
{
retval=-1;
printf("\n%s:%d: Message:%s",__FUNCTION__,__LINE__,jstr(invoice,"message"));
goto end;
}
else
{
invoiceInfo=cJSON_CreateObject();
Expand All @@ -1702,30 +1695,25 @@ int32_t BET_create_invoice(cJSON *argjson,struct privatebet_info *bet,struct pri
cJSON_AddNumberToObject(invoiceInfo,"round",jint(argjson,"round"));
cJSON_AddStringToObject(invoiceInfo,"label",argv[3]);
cJSON_AddStringToObject(invoiceInfo,"invoice",cJSON_Print(invoice));
printf("\n%s::%d::%s\n",__FUNCTION__,__LINE__,cJSON_Print(invoiceInfo));

rendered=cJSON_Print(invoiceInfo);
bytes=nn_send(bet->pubsock,rendered,strlen(rendered),0);

if(bytes<0)
{
retval=-1;
printf("\n%s :%d Failed to send data",__FUNCTION__,__LINE__);
goto end;
}

}

end:
if(argv)
if(argv)
{
for(int i=0;i<6;i++)
{
for(int i=0;i<6;i++)
{
if(argv[i])
free(argv[i]);
}
free(argv);
if(argv[i])
free(argv[i]);
}
return retval;
free(argv);
}

return retval;
}


Expand Down Expand Up @@ -1757,12 +1745,8 @@ int32_t BET_create_betting_invoice(cJSON *argjson,struct privatebet_info *bet,st
make_command(argc,argv,&invoice);

if(jint(invoice,"code") != 0)
{
retval=-1;
printf("\n%s:%d: Message:%s",__FUNCTION__,__LINE__,jstr(invoice,"message"));
goto end;
}
else
retval=-1;
else
{
invoiceInfo=cJSON_CreateObject();
cJSON_AddStringToObject(invoiceInfo,"method","bettingInvoice");
Expand All @@ -1772,30 +1756,23 @@ int32_t BET_create_betting_invoice(cJSON *argjson,struct privatebet_info *bet,st
cJSON_AddStringToObject(invoiceInfo,"invoice",cJSON_Print(invoice));
cJSON_AddItemToObject(invoiceInfo,"actionResponse",cJSON_GetObjectItem(argjson,"actionResponse"));

printf("\n%s::%d::%s\n",__FUNCTION__,__LINE__,cJSON_Print(invoiceInfo));
rendered=cJSON_Print(invoiceInfo);
bytes=nn_send(bet->pubsock,rendered,strlen(rendered),0);

if(bytes<0)
{
retval=-1;
printf("\n%s :%d Failed to send data",__FUNCTION__,__LINE__);
goto end;
}

}

end:
if(argv)

if(argv)
{
for(int i=0;i<6;i++)
{
for(int i=0;i<6;i++)
{
if(argv[i])
free(argv[i]);
}
free(argv);
if(argv[i])
free(argv[i]);
}
return retval;
free(argv);
}
return retval;
}


Expand Down
Loading

0 comments on commit bcc864f

Please sign in to comment.