test
This commit is contained in:
30
src/komodo.h
30
src/komodo.h
@@ -23,7 +23,7 @@
|
||||
#include <pthread.h>
|
||||
#include <ctype.h>
|
||||
|
||||
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight);
|
||||
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint8_t *opretbuf,uint16_t opretlen);
|
||||
void komodo_init();
|
||||
int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp);
|
||||
char *komodo_issuemethod(char *method,char *params,uint16_t port);
|
||||
@@ -41,7 +41,7 @@ char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771;
|
||||
#include "komodo_notary.h"
|
||||
#include "komodo_gateway.h"
|
||||
|
||||
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight)
|
||||
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint8_t *opretbuf,uint16_t opretlen)
|
||||
{
|
||||
static FILE *fp; static int32_t errs; char fname[512]; int32_t ht,func; uint8_t num,pubkeys[64][33];
|
||||
#ifdef WIN32
|
||||
@@ -106,6 +106,15 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
|
||||
printf("KMDHEIGHT <- %d\n",kheight);
|
||||
}
|
||||
}
|
||||
else if ( func == 'O' )
|
||||
{
|
||||
uint16_t olen; uint8_t opret[10000];
|
||||
if ( fread(&olen,1,sizeof(olen),fp) != sizeof(olen) )
|
||||
errs++;
|
||||
if ( fread(opret,1,olen,fp) != olen )
|
||||
errs++;
|
||||
komodo_opreturn(ht,opret,olen);
|
||||
}
|
||||
else if ( func == 'D' )
|
||||
{
|
||||
//printf("D[%d]\n",ht);
|
||||
@@ -145,6 +154,15 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
|
||||
if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) )
|
||||
errs++;
|
||||
}
|
||||
else if ( opretbuf != 0 && opretlen > 0 )
|
||||
{
|
||||
fputc('K',fp);
|
||||
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
|
||||
errs++;
|
||||
if ( fwrite(opretbuf,1,opretlen,fp) != opretlen )
|
||||
errs++;
|
||||
komodo_opreturn(height,opretbuf,opretlen);
|
||||
}
|
||||
else if ( notarypubs != 0 && numnotaries > 0 )
|
||||
{
|
||||
//printf("func P[%d] errs.%d\n",numnotaries,errs);
|
||||
@@ -261,7 +279,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,
|
||||
NOTARIZED_HEIGHT = *notarizedheightp;
|
||||
NOTARIZED_HASH = kmdtxid;
|
||||
NOTARIZED_DESTTXID = desttxid;
|
||||
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0);
|
||||
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0);
|
||||
} else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,KOMODO_SOURCE,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]);
|
||||
}
|
||||
#ifdef KOMODO_PAX
|
||||
@@ -269,7 +287,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,
|
||||
{
|
||||
double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128];
|
||||
numpvals = dpow_readprices(&scriptbuf[++len],×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals);
|
||||
komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0);
|
||||
komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0,0,0);
|
||||
printf("vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen);
|
||||
}
|
||||
#endif
|
||||
@@ -332,7 +350,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
}
|
||||
if ( i != 0 && notaryid >= 0 && notaryid < 64 && voutmask != 0 )
|
||||
{
|
||||
komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0);
|
||||
komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0,0,0);
|
||||
//komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts);
|
||||
}
|
||||
signedmask = 0;
|
||||
@@ -373,7 +391,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
if ( komodo_isratify(1,numvalid) > 13 )
|
||||
{
|
||||
memset(&txhash,0,sizeof(txhash));
|
||||
komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0);
|
||||
komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0);
|
||||
}
|
||||
printf("new notaries.%d newheight.%d from height.%d\n",numvouts-1,KOMODO_PUBKEYS_HEIGHT(height),height);
|
||||
}
|
||||
|
||||
@@ -367,7 +367,7 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
|
||||
//uint256 zero;
|
||||
//printf("disconnect ht.%d\n",pindex->nHeight);
|
||||
//memset(&zero,0,sizeof(zero));
|
||||
//komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0,0,0);
|
||||
//komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0,0,0,0,0);
|
||||
}
|
||||
|
||||
int32_t komodo_block2height(CBlock *block)
|
||||
|
||||
@@ -17,33 +17,47 @@
|
||||
// paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse
|
||||
// need to save most processed block in other chain(s)
|
||||
|
||||
const char *komodo_opreturn(int32_t height,uint8_t *opretbuf,int32_t opretlen)
|
||||
{
|
||||
uint8_t rmd160[20],addrtype,shortflag; char base[4],coinaddr[64]; int64_t fiatoshis; const char *typestr = "unknown";
|
||||
if ( opretbuf[0] == 'D' )
|
||||
{
|
||||
if ( opretlen == 34 )
|
||||
{
|
||||
PAX_pubkey(0,&opretbuf[1],&addrtype,rmd160,base,&shortflag,&fiatoshis);
|
||||
if ( fiatoshis < 0 )
|
||||
fiatoshis = -fiatoshis;
|
||||
bitcoin_address(coinaddr,addrtype,rmd160,20);
|
||||
printf("DEPOSIT %.8f %c%s -> %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr);
|
||||
// verify price value for fiatoshis of base
|
||||
typestr = "deposit";
|
||||
}
|
||||
}
|
||||
return(typestr);
|
||||
}
|
||||
|
||||
void komodo_gateway_voutupdate(char *symbol,int32_t height,int32_t txi,int32_t vout,int32_t numvouts,uint64_t value,uint8_t *script,int32_t len)
|
||||
{
|
||||
uint8_t rmd160[20],addrtype,shortflag; char base[4],coinaddr[64]; int64_t fiatoshis; const char *typestr;
|
||||
int32_t i,opretlen,offset = 0; const char *typestr;
|
||||
typestr = "unknown";
|
||||
if ( script[0] == 0x6a )
|
||||
if ( script[offset++] == 0x6a )
|
||||
{
|
||||
if ( len >= 32*2+4 && strcmp((char *)&script[2+32*2+4],"KMD") == 0 )
|
||||
if ( len >= 32*2+4 && strcmp((char *)&script[1+32*2+4],"KMD") == 0 )
|
||||
typestr = "notarized";
|
||||
if ( script[2] == 'P' )
|
||||
typestr = "pricefeed";
|
||||
else if ( script[2] == 'D' )
|
||||
else
|
||||
{
|
||||
if ( len == 36 )
|
||||
{
|
||||
PAX_pubkey(0,&script[3],&addrtype,rmd160,base,&shortflag,&fiatoshis);
|
||||
if ( fiatoshis < 0 )
|
||||
fiatoshis = -fiatoshis;
|
||||
bitcoin_address(coinaddr,addrtype,rmd160,20);
|
||||
printf("DEPOSIT %.8f %c%s -> %s\n",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr);
|
||||
// verify price value for fiatoshis of base
|
||||
typestr = "deposit";
|
||||
}
|
||||
offset += komodo_scriptitemlen(&opretlen,&script[offset]);
|
||||
printf("offset.%d opretlen.%d\n",offset,opretlen);
|
||||
typestr = komodo_opreturn(height,&script[offset],opretlen);
|
||||
}
|
||||
}
|
||||
else if ( numvouts > 13 )
|
||||
typestr = "ratify";
|
||||
printf("%s VOUTUPDATE.%d txi.%d vout.%d %.8f scriptlen.%d OP_RETURN.%d (%s)\n",symbol,height,txi,vout,dstr(value),len,script[0] == 0x6a,typestr);
|
||||
for (i=0; i<len; i++)
|
||||
printf("%02x",script[i]);
|
||||
printf(" <- %s VOUTUPDATE.%d txi.%d vout.%d %.8f scriptlen.%d OP_RETURN.%d (%s)\n",symbol,height,txi,vout,dstr(value),len,script[0] == 0x6a,typestr);
|
||||
}
|
||||
|
||||
int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr,uint32_t port)
|
||||
@@ -139,7 +153,7 @@ void komodo_gateway_iteration(char *symbol)
|
||||
{
|
||||
fprintf(stderr,"%s.%d ",symbol,KMDHEIGHT);
|
||||
memset(&zero,0,sizeof(zero));
|
||||
komodo_stateupdate(0,0,0,0,zero,0,0,0,0,KMDHEIGHT);
|
||||
komodo_stateupdate(0,0,0,0,zero,0,0,0,0,KMDHEIGHT,0,0);
|
||||
}
|
||||
if ( komodo_gateway_block(symbol,KMDHEIGHT,port) < 0 )
|
||||
break;
|
||||
|
||||
@@ -85,8 +85,6 @@ void komodo_nutxoadd(int32_t height,int32_t notaryid,uint256 txhash,uint64_t vou
|
||||
np->notaryid = notaryid;
|
||||
HASH_ADD_KEYPTR(hh,NUTXOS,&np->txhash,sizeof(np->txhash),np);
|
||||
printf("Add NUTXO[%d] <- %s notaryid.%d t%u %s %llx\n",Num_nutxos,Notaries[notaryid][0],notaryid,komodo_txtime(txhash),txhash.ToString().c_str(),(long long)voutmask);
|
||||
//if ( addflag != 0 )
|
||||
// komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0);
|
||||
Num_nutxos++;
|
||||
pthread_mutex_unlock(&komodo_mutex);
|
||||
}
|
||||
@@ -211,6 +209,6 @@ void komodo_init()
|
||||
}
|
||||
komodo_notarysinit(0,pubkeys,k);
|
||||
memset(&zero,0,sizeof(zero));
|
||||
komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0);
|
||||
komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -921,6 +921,23 @@ int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *
|
||||
return(len);
|
||||
}
|
||||
|
||||
int32_t komodo_scriptitemlen(int32_t *opretlenp,uint8_t *script)
|
||||
{
|
||||
int32_t opretlen,len = 0;
|
||||
if ( (opretlen= script[len++]) >= 0x4c )
|
||||
{
|
||||
if ( opretlen == 0x4c )
|
||||
opretlen = script[len++];
|
||||
else if ( opretlen == 0x4d )
|
||||
{
|
||||
opretlen = script[len++];
|
||||
opretlen = (opretlen << 8) | script[len++];
|
||||
}
|
||||
}
|
||||
*opretlenp = opretlen;
|
||||
return(len);
|
||||
}
|
||||
|
||||
int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen)
|
||||
{
|
||||
int32_t offset = 0;
|
||||
|
||||
Reference in New Issue
Block a user