Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 65cddb3

Browse files
authored
Merge pull request jl777#503 from jl777/dPoW
DPoW
2 parents 0f8433c + 96fbdd0 commit 65cddb3

34 files changed

Lines changed: 571 additions & 65 deletions

src/assetchains

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ komodo_asset BET 999999
3636
komodo_asset CRYPTO 999999
3737
komodo_asset HODL 9999999
3838
komodo_asset SHARK 1401
39+
komodo_asset MSHARK 1400000
3940
komodo_asset BOTS 999999
4041
komodo_asset MGW 999999
4142
#komodo_asset MVP 1000000

src/assetchains.old

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ echo $pubkey
1313
./komodod -pubkey=$pubkey -ac_name=CRYPTO -ac_supply=999999 -addnode=78.47.196.146 $1 &
1414
./komodod -pubkey=$pubkey -ac_name=HODL -ac_supply=9999999 -addnode=78.47.196.146 $1 &
1515
./komodod -pubkey=$pubkey -ac_name=SHARK -ac_supply=1401 -addnode=78.47.196.146 $1 &
16+
./komodod -pubkey=$pubkey -ac_name=MSHARK -ac_supply=1400000 -addnode=78.47.196.146 $1 &
1617
./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=78.47.196.146 $1 &
1718
./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=78.47.196.146 $1 &
1819
#./komodod -pubkey=$pubkey -ac_name=MVP -ac_supply=1000000 -addnode=78.47.196.146 $1 &

src/bitcoind.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
*/
4343

4444
static bool fDaemon;
45-
extern char ASSETCHAINS_SYMBOL[16];
45+
#define KOMODO_ASSETCHAIN_MAXLEN 65
46+
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
4647
void komodo_passport_iteration();
4748

4849
void WaitForShutdown(boost::thread_group* threadGroup)

src/chainparams.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ using namespace std;
3030
* + Contains no strange transactions
3131
*/
3232
void *chainparams_commandline(void *ptr);
33-
extern char ASSETCHAINS_SYMBOL[16];
33+
#include "komodo_defs.h"
34+
35+
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
3436
extern uint16_t ASSETCHAINS_PORT;
3537
extern uint32_t ASSETCHAIN_INIT;
3638
extern uint32_t ASSETCHAINS_MAGIC;

src/coins.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "random.h"
99
#include "version.h"
1010
#include "policy/fees.h"
11+
#include "komodo_defs.h"
1112

1213
#include <assert.h>
1314

@@ -387,7 +388,7 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const
387388

388389
//uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime);
389390
uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue);
390-
extern char ASSETCHAINS_SYMBOL[16];
391+
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
391392

392393
CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const
393394
{

src/dpowassets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp
1414
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CRYPTO\",\"pubkey\":\"$pubkey\"}"
1515
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HODL\",\"pubkey\":\"$pubkey\"}"
1616
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SHARK\",\"pubkey\":\"$pubkey\"}"
17+
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MSHARK\",\"pubkey\":\"$pubkey\"}"
1718
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BOTS\",\"pubkey\":\"$pubkey\"}"
1819
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}"
1920
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MVP\",\"pubkey\":\"$pubkey\"}"
@@ -23,6 +24,7 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp
2324
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CEAL\",\"pubkey\":\"$pubkey\"}"
2425
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MESH\",\"pubkey\":\"$pubkey\"}"
2526
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MNZ\",\"pubkey\":\"$pubkey\"}"
27+
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}"
2628

2729

2830
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}"

src/fiat-cli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ echo bet; fiat/bet $1 $2 $3 $4
4141
echo crypto; fiat/crypto $1 $2 $3 $4
4242
echo hodl; fiat/hodl $1 $2 $3 $4
4343
echo shark; fiat/shark $1 $2 $3 $4
44+
echo mshark; fiat/mshark $1 $2 $3 $4
4445
echo bots; fiat/bots $1 $2 $3 $4
4546
echo mgw; fiat/mgw $1 $2 $3 $4
4647
#echo mvp; fiat/mvp $1 $2 $3 $4

src/fiat/mshark

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
./komodo-cli -ac_name=MSHARK $1 $2 $3 $4 $5 $6

src/komodo-tx.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ using namespace std;
2727
#include "arith_uint256.h"
2828
#include "komodo_structs.h"
2929
#include "komodo_globals.h"
30+
#include "komodo_defs.h"
3031

3132
#include "komodo_interest.h"
3233

src/komodo.h

Lines changed: 148 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#ifndef H_KOMODO_H
1717
#define H_KOMODO_H
18+
#include "komodo_defs.h"
1819

1920
#ifdef _WIN32
2021
#define printf(...)
@@ -56,14 +57,14 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
5657

5758
void komodo_currentheight_set(int32_t height)
5859
{
59-
char symbol[16],dest[16]; struct komodo_state *sp;
60+
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
6061
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
6162
sp->CURRENT_HEIGHT = height;
6263
}
6364

6465
int32_t komodo_currentheight()
6566
{
66-
char symbol[16],dest[16]; struct komodo_state *sp;
67+
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
6768
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
6869
return(sp->CURRENT_HEIGHT);
6970
else return(0);
@@ -192,11 +193,143 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
192193
return(func);
193194
} else return(-1);
194195
}
195-
196+
197+
int32_t memread(void *dest,int32_t size,uint8_t *filedata,long *fposp,long datalen)
198+
{
199+
if ( *fposp+size <= datalen )
200+
{
201+
memcpy(dest,&filedata[*fposp],size);
202+
(*fposp) += size;
203+
return(size);
204+
}
205+
return(-1);
206+
}
207+
208+
int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest)
209+
{
210+
static int32_t errs;
211+
int32_t func= -1,ht,notarized_height,num,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; long fpos = *fposp;
212+
if ( fpos < datalen )
213+
{
214+
func = filedata[fpos++];
215+
if ( ASSETCHAINS_SYMBOL[0] == 0 && strcmp(symbol,"KMD") == 0 )
216+
matched = 1;
217+
else matched = (strcmp(symbol,ASSETCHAINS_SYMBOL) == 0);
218+
if ( memread(&ht,sizeof(ht),filedata,&fpos,datalen) != sizeof(ht) )
219+
errs++;
220+
if ( func == 'P' )
221+
{
222+
if ( (num= filedata[fpos++]) <= 64 )
223+
{
224+
if ( memread(pubkeys,33*num,filedata,&fpos,datalen) != 33*num )
225+
errs++;
226+
else
227+
{
228+
//printf("updated %d pubkeys at %s ht.%d\n",num,symbol,ht);
229+
if ( (KOMODO_EXTERNAL_NOTARIES != 0 && matched != 0) || (strcmp(symbol,"KMD") == 0 && KOMODO_EXTERNAL_NOTARIES == 0) )
230+
komodo_eventadd_pubkeys(sp,symbol,ht,num,pubkeys);
231+
}
232+
} else printf("illegal num.%d\n",num);
233+
}
234+
else if ( func == 'N' )
235+
{
236+
if ( memread(&notarized_height,sizeof(notarized_height),filedata,&fpos,datalen) != sizeof(notarized_height) )
237+
errs++;
238+
if ( memread(&notarized_hash,sizeof(notarized_hash),filedata,&fpos,datalen) != sizeof(notarized_hash) )
239+
errs++;
240+
if ( memread(&notarized_desttxid,sizeof(notarized_desttxid),filedata,&fpos,datalen) != sizeof(notarized_desttxid) )
241+
errs++;
242+
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 )
243+
printf("%s load[%s.%d -> %s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str());
244+
//if ( matched != 0 ) global independent states -> inside *sp
245+
komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height);
246+
}
247+
else if ( func == 'U' ) // deprecated
248+
{
249+
uint8_t n,nid; uint256 hash; uint64_t mask;
250+
n = filedata[fpos++];
251+
nid = filedata[fpos++];
252+
//printf("U %d %d\n",n,nid);
253+
if ( memread(&mask,sizeof(mask),filedata,&fpos,datalen) != sizeof(mask) )
254+
errs++;
255+
if ( memread(&hash,sizeof(hash),filedata,&fpos,datalen) != sizeof(hash) )
256+
errs++;
257+
}
258+
else if ( func == 'K' )
259+
{
260+
int32_t kheight;
261+
if ( memread(&kheight,sizeof(kheight),filedata,&fpos,datalen) != sizeof(kheight) )
262+
errs++;
263+
komodo_eventadd_kmdheight(sp,symbol,ht,kheight,0);
264+
}
265+
else if ( func == 'T' )
266+
{
267+
int32_t kheight,ktimestamp;
268+
if ( memread(&kheight,sizeof(kheight),filedata,&fpos,datalen) != sizeof(kheight) )
269+
errs++;
270+
if ( memread(&ktimestamp,sizeof(ktimestamp),filedata,&fpos,datalen) != sizeof(ktimestamp) )
271+
errs++;
272+
//if ( matched != 0 ) global independent states -> inside *sp
273+
//printf("%s.%d load[%s] ht.%d t.%u\n",ASSETCHAINS_SYMBOL,ht,symbol,kheight,ktimestamp);
274+
komodo_eventadd_kmdheight(sp,symbol,ht,kheight,ktimestamp);
275+
}
276+
else if ( func == 'R' )
277+
{
278+
uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[16384];
279+
if ( memread(&txid,sizeof(txid),filedata,&fpos,datalen) != sizeof(txid) )
280+
errs++;
281+
if ( memread(&v,sizeof(v),filedata,&fpos,datalen) != sizeof(v) )
282+
errs++;
283+
if ( memread(&ovalue,sizeof(ovalue),filedata,&fpos,datalen) != sizeof(ovalue) )
284+
errs++;
285+
if ( memread(&olen,sizeof(olen),filedata,&fpos,datalen) != sizeof(olen) )
286+
errs++;
287+
if ( olen < sizeof(opret) )
288+
{
289+
if ( memread(opret,olen,filedata,&fpos,datalen) != olen )
290+
errs++;
291+
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 )
292+
{
293+
int32_t i; for (i=0; i<olen; i++)
294+
printf("%02x",opret[i]);
295+
printf(" %s.%d load[%s] opret[%c] len.%d %.8f\n",ASSETCHAINS_SYMBOL,ht,symbol,opret[0],olen,(double)ovalue/COIN);
296+
}
297+
komodo_eventadd_opreturn(sp,symbol,ht,txid,ovalue,v,opret,olen); // global shared state -> global PAX
298+
} else
299+
{
300+
int32_t i;
301+
for (i=0; i<olen; i++)
302+
filedata[fpos++];
303+
//printf("illegal olen.%u\n",olen);
304+
}
305+
}
306+
else if ( func == 'D' )
307+
{
308+
printf("unexpected function D[%d]\n",ht);
309+
}
310+
else if ( func == 'V' )
311+
{
312+
int32_t numpvals; uint32_t pvals[128];
313+
numpvals = filedata[fpos++];
314+
if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && memread(pvals,(int32_t)(sizeof(uint32_t)*numpvals),filedata,&fpos,datalen) == numpvals*sizeof(uint32_t) )
315+
{
316+
//if ( matched != 0 ) global shared state -> global PVALS
317+
//printf("%s load[%s] prices %d\n",ASSETCHAINS_SYMBOL,symbol,ht);
318+
komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals);
319+
//printf("load pvals ht.%d numpvals.%d\n",ht,numpvals);
320+
} else printf("error loading pvals[%d]\n",numpvals);
321+
}
322+
else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func);
323+
*fposp = fpos;
324+
return(func);
325+
}
326+
return(-1);
327+
}
328+
196329
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,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout)
197330
{
198331
static FILE *fp; static int32_t errs,didinit;
199-
struct komodo_state *sp; char fname[512],symbol[16],dest[16]; int32_t ht,func; uint8_t num,pubkeys[64][33];
332+
struct komodo_state *sp; char fname[512],symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; int32_t retval,ht,func; uint8_t num,pubkeys[64][33];
200333
if ( didinit == 0 )
201334
{
202335
portable_mutex_init(&KOMODO_KV_mutex);
@@ -214,10 +347,15 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
214347
komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate");
215348
if ( (fp= fopen(fname,"rb+")) != 0 )
216349
{
217-
while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 )
218-
;
350+
if ( (retval= komodo_faststateinit(sp,fname,symbol,dest)) > 0 )
351+
fseek(fp,0,SEEK_END);
352+
else
353+
{
354+
fprintf(stderr,"komodo_faststateinit retval.%d\n",retval);
355+
while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 )
356+
;
357+
}
219358
} else fp = fopen(fname,"wb+");
220-
printf("fname.(%s) fpos.%ld\n",fname,ftell(fp));
221359
KOMODO_INITDONE = (uint32_t)time(NULL);
222360
}
223361
if ( height <= 0 )
@@ -338,7 +476,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
338476
int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask)
339477
{
340478
static uint256 zero; static FILE *signedfp;
341-
int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[16],dest[16];
479+
int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN];
342480
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
343481
return(-1);
344482
if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
@@ -407,7 +545,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
407545
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0);
408546
len += 4;
409547
if ( ASSETCHAINS_SYMBOL[0] != 0 )
410-
printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len);
548+
printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len);
411549
if ( ASSETCHAINS_SYMBOL[0] == 0 )
412550
{
413551
if ( signedfp == 0 )
@@ -496,7 +634,7 @@ int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys
496634
void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
497635
{
498636
static int32_t hwmheight;
499-
uint64_t signedmask,voutmask; char symbol[16],dest[16]; struct komodo_state *sp;
637+
uint64_t signedmask,voutmask; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
500638
uint8_t scriptbuf[4096],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 kmdtxid,zero,btctxid,txhash;
501639
int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
502640
memset(&zero,0,sizeof(zero));

0 commit comments

Comments
 (0)