Browse Source

test

blackjok3r
blackjok3r 6 years ago
parent
commit
35cb09de9c
  1. 43
      iguana/dpow/dpow_fsm.c
  2. 17
      iguana/dpow/dpow_rpc.c

43
iguana/dpow/dpow_fsm.c

@ -616,32 +616,49 @@ void dpow_statemachinestart(void *ptr)
// We need to wait for notarized confirm here. If the notarization is reorged for any reason we need to rebroadcast it,
// becasue the mempool is stupid after the sapling update!
int8_t dest_confs = 0, src_confs = 0;
bool destnotarized = false, srcnotarized = false;
while ( 1 )
{
// If the round was sucessful and both notarizations were created successfully we will make sure they are in the chain.
if ( bits256_cmp(bp->desttxid,zero) == 0 )
{
fprintf(stderr, "dest tx was never sent!\n");
break;
}
else
fprintf(stderr, "desttxid.%s\n", bits256_str(str,bp->desttxid));
if ( bits256_cmp(bp->srctxid,zero) == 0 )
{
fprintf(stderr, "src tx was never sent!\n");
break;
}
else
fprintf(stderr, "srctxid.%s\n", bits256_str(str,bp->srctxid));
// dpow_gettransaction will return confirms, unless its not confirmed.
// check here for confirms exists in return JSON, if no confirms, keep rebroadcasting every 60s
// get the confirms for desttxid
if ( !destnotarized && (dest_confs= dpow_txconfirms(myinfo, bp->destcoin, bp->desttxid)) != -1 )
{
if ( dest_confs > 2 )
{
// tx is notarized. or it has 100+ raw confirms.
fprintf(stderr, "[%s] txid.%s is notarized or has 100 confirms \n",bp->dest, bits256_str(str,bp->desttxid));
destnotarized = true;
}
else if ( dest_confs = 0 )
{
// not confirmed, rebroadcast it.
fprintf(stderr, "[%s] txid.%s is not confirmed at all rebroadcasting.... \n",bp->dest, bits256_str(str,bp->desttxid));
}
} else fprintf(stderr, "[%s] txid.%s returned error for txconfirms",bp->dest, bits256_str(str,bp->desttxid));
// get the confirms for srctxid
/*if ( (src_confs= dpow_txconfirms(myinfo, bp->srccoin, bp->srctxid)) != -1 )
{
if ( dest_confs > 2 )
{
// tx is notarized. or it has 100+ raw confirms.
fprintf(stderr, "[%s] txid.%s is notarized or has 100 confirms \n",bp->symbol, bits256_str(str,bp->srctxid));
}
} */
// check here for confirms exists in return JSON, if no confirms, keep rebroadcasting.
// if confirms > 2 exit loop.
// as a safety, if rawconfirmations > 100 exit this loop.
// wait for approx one block before checking again.
sleep(60);
break; // remove this later!
if ( destnotarized == true ) break;
}
// unlock the dest utxo on KMD.

17
iguana/dpow/dpow_rpc.c

@ -541,6 +541,23 @@ char *dpow_decoderawtransaction(struct supernet_info *myinfo,struct iguana_info
return(retstr);
}
int32_t dpow_txconfirms(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid)
{
cJSON *txobj; int32_t confirms = 0;
if ( (txobj= dpow_gettransaction(myinfo, coin, txid)) != 0 )
{
if ( (confirms= juint(txobj, "confirmations")) != 0 )
{
return(confirms);
}
else if ( confirms == 1 && juint(txobj, "rawconfirmations") > 100 )
return(100);
else
return(0);
}
return(-1);
}
cJSON *dpow_gettransaction(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid)
{
char buf[128],str[65],*retstr=0; cJSON *json = 0;

Loading…
Cancel
Save