Browse Source

Merge pull request #20 from KMDLabs/staked

Staked
blackjok3r
blackjok3rtt 6 years ago
committed by GitHub
parent
commit
e0570392ac
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      iguana/dpow/dpow_fsm.c
  2. 135
      iguana/dpow/dpow_rpc.c
  3. 4
      iguana/dpow/dpow_tx.c
  4. 2
      iguana/iguana_notary.c
  5. 2
      iguana/iguana_wallet.c

12
iguana/dpow/dpow_fsm.c

@ -669,8 +669,11 @@ void dpow_statemachinestart(void *ptr)
fprintf(stderr, "[%s] Cant find tx.%s rebroadcasting...\n", dp->dest, bits256_str(str,bp->desttxid));
send_dest = 1;
} else fprintf(stderr, "[%s] get raw transaction error\n", dp->dest);
if ( send_dest == 1 )
dpow_sendrawtransaction(myinfo, bp->destcoin, desttx);
if ( send_src == 1 )
{
char *tmpstr = dpow_sendrawtransaction(myinfo, bp->destcoin, desttx);
free(tmpstr);
}
}
// get the confirms for srctxid
@ -701,7 +704,10 @@ void dpow_statemachinestart(void *ptr)
send_src = 1;
} else fprintf(stderr, "[%s] get raw transaction error\n", dp->symbol);
if ( send_src == 1 )
dpow_sendrawtransaction(myinfo, bp->srccoin, srctx);
{
char *tmpstr = dpow_sendrawtransaction(myinfo, bp->srccoin, srctx);
free(tmpstr);
}
}
}
#endif

135
iguana/dpow/dpow_rpc.c

@ -111,75 +111,55 @@ int32_t Notaries_minsigs = DPOW_MIN_ASSETCHAIN_SIGS;
uint16_t Notaries_port = DPOW_SOCKPORT;
char *Notaries_seeds[65];
int32_t komodo_initjson2(char *fstr)
int32_t komodo_initjson(char *fname)
{
char *field,*hexstr; cJSON *array,*item,*argjson; uint16_t port; int32_t i,n,num,retval = -1;
static portable_mutex_t notaries_mutex; static int32_t initflag;
if ( initflag == 0 )
{
portable_mutex_init(&notaries_mutex);
initflag = 1;
}
portable_mutex_lock(&notaries_mutex);
if ( (argjson= cJSON_Parse(fstr)) != 0 )
char *fstr,*field,*hexstr; cJSON *argjson,*array,*item; long fsize; uint16_t port; int32_t i,n,num,retval = -1;
if ( (fstr= OS_filestr(&fsize,fname)) != 0 )
{
// memset arrays to 0!
memset(Notaries_seeds,0,sizeof(Notaries_seeds));
memset(Notaries_elected,0,sizeof(Notaries_elected));
if ( (port= juint(argjson,"port")) != 0 )
Notaries_port = port;
if ( (num= juint(argjson,"BTCminsigs")) > Notaries_BTCminsigs )
Notaries_BTCminsigs = num;
Notaries_minsigs = juint(argjson,"minsigs");
if ( (array= jarray(&n,argjson,"seeds")) != 0 && n <= 64 )
if ( (argjson= cJSON_Parse(fstr)) != 0 )
{
for (i=0; i<n&&i<64; i++)
if ( (port= juint(argjson,"port")) != 0 )
Notaries_port = port;
if ( (num= juint(argjson,"BTCminsigs")) > Notaries_BTCminsigs )
Notaries_BTCminsigs = num;
Notaries_minsigs = juint(argjson,"minsigs");
if ( (array= jarray(&n,argjson,"seeds")) != 0 && n <= 64 )
{
Notaries_seeds[i] = clonestr(jstri(array,i));
//printf("%s ",Notaries_seeds[i]);
for (i=0; i<n&&i<64; i++)
{
Notaries_seeds[i] = clonestr(jstri(array,i));
printf("%s ",Notaries_seeds[i]);
}
Notaries_numseeds = i;
printf("Notaries_numseeds.%d\n",Notaries_numseeds);
}
Notaries_numseeds = i;
//printf("Notaries_numseeds.%d\n",Notaries_numseeds);
}
if ( (array= jarray(&n,argjson,"notaries")) != 0 && n <= 64 )
{
for (i=0; i<n&&i<64; i++)
if ( (array= jarray(&n,argjson,"notaries")) != 0 && n <= 64 )
{
item = jitem(array,i);
field = jfieldname(item);
if ( (hexstr= jstr(item,field)) != 0 && is_hexstr(hexstr,0) == 66 )
for (i=0; i<n&&i<64; i++)
{
Notaries_elected[i][0] = clonestr(field);
Notaries_elected[i][1] = clonestr(hexstr);
//printf("%d of %d: %s %s\n",i,n,field,hexstr);
item = jitem(array,i);
field = jfieldname(item);
if ( (hexstr= jstr(item,field)) != 0 && is_hexstr(hexstr,0) == 66 )
{
Notaries_elected[i][0] = clonestr(field);
Notaries_elected[i][1] = clonestr(hexstr);
//printf("%d of %d: %s %s\n",i,n,field,hexstr);
}
else
{
printf("couldnt find (%s) in %s or non-hex (%s)\n",field,jprint(item,0),hexstr!=0?hexstr:"");
break;
}
}
else
if ( i == n )
{
printf("couldnt find (%s) in %s or non-hex (%s)\n",field,jprint(item,0),hexstr!=0?hexstr:"");
break;
Notaries_num = n;
retval = 0;
printf("numnotaries %d, port.%d minsigs.%d BTCminsigs.%d\n",Notaries_num,Notaries_port,Notaries_BTCminsigs,Notaries_minsigs);
}
}
if ( i == n )
{
Notaries_num = n;
retval = 0;
//printf("numnotaries %d, port.%d minsigs.%d BTCminsigs.%d\n",Notaries_num,Notaries_port,Notaries_BTCminsigs,Notaries_minsigs);
}
free_json(argjson);
}
free_json(argjson);
}
portable_mutex_unlock(&notaries_mutex);
return(retval);
}
int32_t komodo_initjson(char *fname)
{
char *fstr; long fsize; int32_t retval = -1;
if ( (fstr= OS_filestr(&fsize,fname)) != 0 )
{
retval = komodo_initjson2(fstr);
free(fstr);
}
return(retval);
@ -187,30 +167,57 @@ int32_t komodo_initjson(char *fname)
int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height)
{
int32_t i,num=-1, didinit=0; struct iguana_info *coin; char params[64],*retstr; cJSON *retjson;
#if STAKED
struct iguana_info *coin; char *retstr,*field,*hexstr; ; cJSON *retjson,*array,*item; int32_t i,n;
static portable_mutex_t notaries_mutex; static int32_t initflag;
if ( initflag == 0 )
{
portable_mutex_init(&notaries_mutex);
initflag = 1;
}
if ( (coin= iguana_coinfind("KMD")) != 0 )
{
if ( coin->FULLNODE < 0 )
{
if ( (retstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getiguanajson","")) != 0 )
{
//printf("NOTARIES retstr.%s\n", retstr);
if ( komodo_initjson2(retstr) < 0 )
printf("init notaries failed!\n");
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
portable_mutex_lock(&notaries_mutex);
Notaries_minsigs = juint(retjson,"minsigs");
portable_mutex_unlock(&notaries_mutex);
if ( (array= jarray(&n,retjson,"notaries")) != 0 && n <= 64 )
{
for (i=0; i<n&&i<64; i++)
{
item = jitem(array,i);
field = jfieldname(item);
if ( (hexstr= jstr(item,field)) != 0 && is_hexstr(hexstr,0) == 66 )
decode_hex(pubkeys[i],33,hexstr);
}
if ( i == n )
{
portable_mutex_lock(&notaries_mutex);
Notaries_num = n;
portable_mutex_unlock(&notaries_mutex);
}
}
free_json(retjson);
}
free(retstr);
}
}
}
#endif
return(Notaries_num);
#else
int32_t i;
if ( Notaries_num > 0 )
{
for (i=0; i<Notaries_num; i++)
decode_hex(pubkeys[i],33,Notaries_elected[i][1]);
return(Notaries_num);
} else return(-1);
//printf("staked_notaries returns.%d\n",num);
return(num);
#endif
}
bits256 dpow_getbestblockhash(struct supernet_info *myinfo,struct iguana_info *coin)

4
iguana/dpow/dpow_tx.c

@ -531,7 +531,9 @@ void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct igu
}
if ( valid != 0 )
{
printf("bestk.%d %llx %s height.%d mod.%d VINI.%d myind.%d MINE.(%s) j.%d\n",bestk,(long long)bestmask,(src_or_dest != 0) ? bp->destcoin->symbol : bp->srccoin->symbol,bp->height,DPOW_MODIND(bp,0),j,myind,jprint(item,0),j);
char *txinfo = jprint(item,0);
printf("bestk.%d %llx %s height.%d mod.%d VINI.%d myind.%d MINE.(%s) j.%d\n",bestk,(long long)bestmask,(src_or_dest != 0) ? bp->destcoin->symbol : bp->srccoin->symbol,bp->height,DPOW_MODIND(bp,0),j,myind,txinfo,j);
free(txinfo);
cp->siglens[bestk] = (int32_t)strlen(sigstr) >> 1;
if ( src_or_dest != 0 )
bp->destsigsmasks[bestk] |= (1LL << myind);

2
iguana/iguana_notary.c

@ -403,6 +403,7 @@ THREE_STRINGS_AND_DOUBLE(iguana,dpow,symbol,dest,pubkey,freq)
printf("src validation error %s %s %s\n",src->symbol,srcaddr,retstr);
}
free(retstr);
free_json(json);
retstr = 0;
} else printf("%s %s didnt return anything\n",src->symbol,srcaddr);
bitcoin_address(destaddr,destcoin->chain->pubtype,dp->minerkey33,33);
@ -417,6 +418,7 @@ THREE_STRINGS_AND_DOUBLE(iguana,dpow,symbol,dest,pubkey,freq)
printf("dest validation error %s %s %s\n",src->symbol,srcaddr,retstr);
}
free(retstr);
free_json(json);
retstr = 0;
} else printf("%s %s didnt return anything\n",destcoin->symbol,destaddr);
if ( srcvalid <= 0 || destvalid <= 0 )

2
iguana/iguana_wallet.c

@ -1405,6 +1405,7 @@ TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout)
if ( (ismine= jobj(json,"ismine")) != 0 && is_cJSON_True(ismine) != 0 )
destvalid = 1;
else destvalid = 0;
free(ismine);
free(tmpstr);
free(retjson);
tmpstr = 0;
@ -1995,4 +1996,3 @@ TWO_INTS(bitcoinrpc,listaccounts,minconf,includewatchonly)
}
#include "../includes/iguana_apiundefs.h"

Loading…
Cancel
Save