test
This commit is contained in:
@@ -23,6 +23,8 @@
|
|||||||
#include <curl/easy.h>
|
#include <curl/easy.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define issue_curl(cmdstr) bitcoind_RPC(0,"curl","http://127.0.0.1:7771",0,cmdstr,0)
|
||||||
|
|
||||||
struct MemoryStruct { char *memory; size_t size; };
|
struct MemoryStruct { char *memory; size_t size; };
|
||||||
struct return_string { char *ptr; size_t len; };
|
struct return_string { char *ptr; size_t len; };
|
||||||
|
|
||||||
@@ -137,7 +139,6 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char *
|
|||||||
*
|
*
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params)
|
char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params)
|
||||||
{
|
{
|
||||||
static int didinit,count,count2; static double elapsedsum,elapsedsum2;
|
static int didinit,count,count2; static double elapsedsum,elapsedsum2;
|
||||||
@@ -344,7 +345,6 @@ char *komodo_issuemethod(char *method,char *params,uint16_t port)
|
|||||||
}
|
}
|
||||||
return(retstr2);
|
return(retstr2);
|
||||||
}
|
}
|
||||||
//curl --url "http://127.0.0.1:13033" --user "user1557335368:pass111720054" --data "{\"method\":\"getinfo\",\"params\":[]}"
|
|
||||||
|
|
||||||
uint32_t komodo_txtime(uint256 hash)
|
uint32_t komodo_txtime(uint256 hash)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ struct pax_transaction
|
|||||||
return(total);
|
return(total);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
uint64_t dpow_paxtotal(struct dpow_info *dp)
|
uint64_t komodo_paxtotal()
|
||||||
{
|
{
|
||||||
struct pax_transaction *pax,*tmp; uint64_t total = 0;
|
struct pax_transaction *pax,*tmp; uint64_t total = 0;
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
@@ -147,9 +147,11 @@ int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uin
|
|||||||
|
|
||||||
void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *symbol)
|
void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *symbol)
|
||||||
{
|
{
|
||||||
struct pax_transaction *pax,*tmp; uint8_t *script,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1;
|
struct pax_transaction *pax,*tmp; uint8_t *script,opcode,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1;
|
||||||
PENDING_KOMODO_TX = 0;
|
PENDING_KOMODO_TX = 0;
|
||||||
//HASH_ITER(hh,PAX,pax,tmp)
|
if ( strcmp(symbol,"KMD") != 0 )
|
||||||
|
opcode = 'I';
|
||||||
|
else opcode = 'X';
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
while ( (pax= PAX->hh.next) != 0 && pax != tmp )
|
while ( (pax= PAX->hh.next) != 0 && pax != tmp )
|
||||||
{
|
{
|
||||||
@@ -172,9 +174,10 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *
|
|||||||
}
|
}
|
||||||
data[len++] = pax->vout & 0xff;
|
data[len++] = pax->vout & 0xff;
|
||||||
data[len++] = (pax->vout >> 8) & 0xff;
|
data[len++] = (pax->vout >> 8) & 0xff;
|
||||||
printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,ASSETCHAINS_SYMBOL);
|
printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol);
|
||||||
if ( shortflag == 0 && strcmp(symbol,"KMD") == 0 )
|
if ( strcmp(symbol,"KMD") != 0 )
|
||||||
PENDING_KOMODO_TX += pax->fiatoshis;
|
PENDING_KOMODO_TX += pax->fiatoshis;
|
||||||
|
else PENDING_KOMODO_TX += pax->komodoshis;
|
||||||
if ( numvouts++ >= 64 )
|
if ( numvouts++ >= 64 )
|
||||||
break;
|
break;
|
||||||
tmp = pax;
|
tmp = pax;
|
||||||
@@ -187,7 +190,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *
|
|||||||
for (i=0; symbol[i]!=0; i++)
|
for (i=0; symbol[i]!=0; i++)
|
||||||
data[len++] = symbol[i];
|
data[len++] = symbol[i];
|
||||||
data[len++] = 0;
|
data[len++] = 0;
|
||||||
opretlen = komodo_opreturnscript(opret,'I',data,len);
|
opretlen = komodo_opreturnscript(opret,opcode,data,len);
|
||||||
txNew->vout.resize(numvouts+1);
|
txNew->vout.resize(numvouts+1);
|
||||||
txNew->vout[numvouts].nValue = 0;
|
txNew->vout[numvouts].nValue = 0;
|
||||||
txNew->vout[numvouts].scriptPubKey.resize(opretlen);
|
txNew->vout[numvouts].scriptPubKey.resize(opretlen);
|
||||||
@@ -199,20 +202,30 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *
|
|||||||
|
|
||||||
int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing
|
int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing
|
||||||
{
|
{
|
||||||
int32_t i,j,n,num,opretlen,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; struct pax_transaction *pax,space;
|
int32_t i,j,n,num,opretlen,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char symbol[16],base[16]; uint16_t vouts[64]; uint8_t *script,opcode; struct pax_transaction *pax,space;
|
||||||
n = block.vtx[0].vout.size();
|
n = block.vtx[0].vout.size();
|
||||||
script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data();
|
script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data();
|
||||||
if ( n <= 2 || script[0] != 0x6a )
|
if ( n <= 2 || script[0] != 0x6a )
|
||||||
return(0);
|
return(0);
|
||||||
offset += komodo_scriptitemlen(&opretlen,&script[offset]);
|
offset += komodo_scriptitemlen(&opretlen,&script[offset]);
|
||||||
//printf("checkdeposit n.%d [%02x] [%c] %d vs %d\n",n,script[0],script[offset],script[offset],'I');
|
//printf("checkdeposit n.%d [%02x] [%c] %d vs %d\n",n,script[0],script[offset],script[offset],'I');
|
||||||
if ( script[offset] == 'I' && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() )
|
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||||
|
{
|
||||||
|
opcode = 'X';
|
||||||
|
strcpy(symbol,"KMD");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcpy(symbol,ASSETCHAINS_SYMBOL);
|
||||||
|
opcode = 'I';
|
||||||
|
}
|
||||||
|
if ( script[offset] == opcode && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() )
|
||||||
{
|
{
|
||||||
if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,&script[offset],opretlen)) > 0 )
|
if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,&script[offset],opretlen)) > 0 )
|
||||||
{
|
{
|
||||||
for (i=1; i<n-1; i++)
|
for (i=1; i<n-1; i++)
|
||||||
{
|
{
|
||||||
if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) != 0 && pax->fiatoshis == block.vtx[0].vout[i].nValue )
|
if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) != 0 && ((opcode == 'I' && pax->fiatoshis == block.vtx[0].vout[i].nValue) || (opcode == 'X' && pax->komodoshis == block.vtx[0].vout[i].nValue)) )
|
||||||
{
|
{
|
||||||
//printf("i.%d match %.8f == %.8f\n",i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue));
|
//printf("i.%d match %.8f == %.8f\n",i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue));
|
||||||
komodo_paxmark(&space,txids[i-1],vouts[i-1],height);
|
komodo_paxmark(&space,txids[i-1],vouts[i-1],height);
|
||||||
@@ -229,14 +242,6 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
|
|||||||
}
|
}
|
||||||
//printf("opretlen.%d num.%d\n",opretlen,num);
|
//printf("opretlen.%d num.%d\n",opretlen,num);
|
||||||
}
|
}
|
||||||
else if ( script[offset] == 'X' && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() )
|
|
||||||
{
|
|
||||||
if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,&script[offset],opretlen)) > 0 )
|
|
||||||
{
|
|
||||||
// return(-1) if invalid withdraw redeem
|
|
||||||
// check txid in assetchain, verify fiatoshis and conversion rate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,4 +466,38 @@ void komodo_gateway_iteration(char *symbol)
|
|||||||
sleep(30);
|
sleep(30);
|
||||||
}
|
}
|
||||||
KOMODO_DEPOSIT = komodo_paxtotal();
|
KOMODO_DEPOSIT = komodo_paxtotal();
|
||||||
|
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||||
|
{
|
||||||
|
//[{"prev_hash":"5d5c9a49489b558de9e84f991f996dedaae6b9d0f157f82b2fec64662476d5cf","prev_vout":2,"EUR":0.78329000,"fiat":"EUR","height":57930,"KMD":0.10000000,"address":"RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5"}]
|
||||||
|
char *retstr,*base,*coinaddr,*txidstr; uint64_t value; cJSON *array; int32_t n,vout,shortflag,height; uint256 txid; uint8_t rmd160[20],addrtype;
|
||||||
|
if ( (retstr= issue_curl("{\"agent\":\"dpow\",\"method\":\"pending\",\"fiat\":\"EUR\"}")) != 0 )
|
||||||
|
{
|
||||||
|
if ( (array= cJSON_Parse(retstr)) != 0 )
|
||||||
|
{
|
||||||
|
if ( (n= cJSON_GetArraySize(array)) > 0 )
|
||||||
|
{
|
||||||
|
for (i=0; i<n; i++)
|
||||||
|
{
|
||||||
|
item = jitem(array,i);
|
||||||
|
coinaddr = jstr(item,"address");
|
||||||
|
value = jdouble(item,"KMD") * COIN;
|
||||||
|
shortflag = juint(item,"short");
|
||||||
|
vout = jint(item,"prev_vout");
|
||||||
|
height = jint(item,"height");
|
||||||
|
base = jstr(item,"fiat");
|
||||||
|
txidstr = jstr(item,"prev_hash");
|
||||||
|
if ( coinaddr != 0 && base != 0 && value > 0 && height > 0 )
|
||||||
|
{
|
||||||
|
fiatoshis = jdouble(item,base) * COIN;
|
||||||
|
decode_hex((uint8_t *)&txid,sizeof(txid),txidstr);
|
||||||
|
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
|
||||||
|
komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("retstr.(%s)\n",retstr);
|
||||||
|
free(retstr);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
if(!pblocktemplate.get())
|
if(!pblocktemplate.get())
|
||||||
return NULL;
|
return NULL;
|
||||||
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
||||||
while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 )
|
while ( chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 )
|
||||||
{
|
{
|
||||||
sleep(10);
|
sleep(10);
|
||||||
if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 )
|
if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 )
|
||||||
@@ -372,6 +372,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
txNew.vout[1].nValue = 0;
|
txNew.vout[1].nValue = 0;
|
||||||
//fprintf(stderr,"opretlen.%d\n",opretlen);
|
//fprintf(stderr,"opretlen.%d\n",opretlen);
|
||||||
}
|
}
|
||||||
|
komodo_gateway_deposits(&txNew,0,(char *)"EUR");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user