Skip to content

Commit

Permalink
Merge pull request jl777#503 from jl777/dPoW
Browse files Browse the repository at this point in the history
DPoW
  • Loading branch information
jl777 authored Dec 7, 2017
2 parents 0f8433c + 96fbdd0 commit 65cddb3
Show file tree
Hide file tree
Showing 34 changed files with 571 additions and 65 deletions.
1 change: 1 addition & 0 deletions src/assetchains
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ komodo_asset BET 999999
komodo_asset CRYPTO 999999
komodo_asset HODL 9999999
komodo_asset SHARK 1401
komodo_asset MSHARK 1400000
komodo_asset BOTS 999999
komodo_asset MGW 999999
#komodo_asset MVP 1000000
Expand Down
1 change: 1 addition & 0 deletions src/assetchains.old
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ echo $pubkey
./komodod -pubkey=$pubkey -ac_name=CRYPTO -ac_supply=999999 -addnode=78.47.196.146 $1 &
./komodod -pubkey=$pubkey -ac_name=HODL -ac_supply=9999999 -addnode=78.47.196.146 $1 &
./komodod -pubkey=$pubkey -ac_name=SHARK -ac_supply=1401 -addnode=78.47.196.146 $1 &
./komodod -pubkey=$pubkey -ac_name=MSHARK -ac_supply=1400000 -addnode=78.47.196.146 $1 &
./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=78.47.196.146 $1 &
./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=78.47.196.146 $1 &
#./komodod -pubkey=$pubkey -ac_name=MVP -ac_supply=1000000 -addnode=78.47.196.146 $1 &
Expand Down
3 changes: 2 additions & 1 deletion src/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
*/

static bool fDaemon;
extern char ASSETCHAINS_SYMBOL[16];
#define KOMODO_ASSETCHAIN_MAXLEN 65
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
void komodo_passport_iteration();

void WaitForShutdown(boost::thread_group* threadGroup)
Expand Down
4 changes: 3 additions & 1 deletion src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ using namespace std;
* + Contains no strange transactions
*/
void *chainparams_commandline(void *ptr);
extern char ASSETCHAINS_SYMBOL[16];
#include "komodo_defs.h"

extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
extern uint16_t ASSETCHAINS_PORT;
extern uint32_t ASSETCHAIN_INIT;
extern uint32_t ASSETCHAINS_MAGIC;
Expand Down
3 changes: 2 additions & 1 deletion src/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "random.h"
#include "version.h"
#include "policy/fees.h"
#include "komodo_defs.h"

#include <assert.h>

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

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

CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const
{
Expand Down
2 changes: 2 additions & 0 deletions src/dpowassets
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CRYPTO\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HODL\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SHARK\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MSHARK\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BOTS\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}"
#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MVP\",\"pubkey\":\"$pubkey\"}"
Expand All @@ -23,6 +24,7 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CEAL\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MESH\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MNZ\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}"


#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}"
Expand Down
1 change: 1 addition & 0 deletions src/fiat-cli
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ echo bet; fiat/bet $1 $2 $3 $4
echo crypto; fiat/crypto $1 $2 $3 $4
echo hodl; fiat/hodl $1 $2 $3 $4
echo shark; fiat/shark $1 $2 $3 $4
echo mshark; fiat/mshark $1 $2 $3 $4
echo bots; fiat/bots $1 $2 $3 $4
echo mgw; fiat/mgw $1 $2 $3 $4
#echo mvp; fiat/mvp $1 $2 $3 $4
Expand Down
2 changes: 2 additions & 0 deletions src/fiat/mshark
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=MSHARK $1 $2 $3 $4 $5 $6
1 change: 1 addition & 0 deletions src/komodo-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ using namespace std;
#include "arith_uint256.h"
#include "komodo_structs.h"
#include "komodo_globals.h"
#include "komodo_defs.h"

#include "komodo_interest.h"

Expand Down
158 changes: 148 additions & 10 deletions src/komodo.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#ifndef H_KOMODO_H
#define H_KOMODO_H
#include "komodo_defs.h"

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

void komodo_currentheight_set(int32_t height)
{
char symbol[16],dest[16]; struct komodo_state *sp;
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
sp->CURRENT_HEIGHT = height;
}

int32_t komodo_currentheight()
{
char symbol[16],dest[16]; struct komodo_state *sp;
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
return(sp->CURRENT_HEIGHT);
else return(0);
Expand Down Expand Up @@ -192,11 +193,143 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
return(func);
} else return(-1);
}


int32_t memread(void *dest,int32_t size,uint8_t *filedata,long *fposp,long datalen)
{
if ( *fposp+size <= datalen )
{
memcpy(dest,&filedata[*fposp],size);
(*fposp) += size;
return(size);
}
return(-1);
}

int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest)
{
static int32_t errs;
int32_t func= -1,ht,notarized_height,num,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; long fpos = *fposp;
if ( fpos < datalen )
{
func = filedata[fpos++];
if ( ASSETCHAINS_SYMBOL[0] == 0 && strcmp(symbol,"KMD") == 0 )
matched = 1;
else matched = (strcmp(symbol,ASSETCHAINS_SYMBOL) == 0);
if ( memread(&ht,sizeof(ht),filedata,&fpos,datalen) != sizeof(ht) )
errs++;
if ( func == 'P' )
{
if ( (num= filedata[fpos++]) <= 64 )
{
if ( memread(pubkeys,33*num,filedata,&fpos,datalen) != 33*num )
errs++;
else
{
//printf("updated %d pubkeys at %s ht.%d\n",num,symbol,ht);
if ( (KOMODO_EXTERNAL_NOTARIES != 0 && matched != 0) || (strcmp(symbol,"KMD") == 0 && KOMODO_EXTERNAL_NOTARIES == 0) )
komodo_eventadd_pubkeys(sp,symbol,ht,num,pubkeys);
}
} else printf("illegal num.%d\n",num);
}
else if ( func == 'N' )
{
if ( memread(&notarized_height,sizeof(notarized_height),filedata,&fpos,datalen) != sizeof(notarized_height) )
errs++;
if ( memread(&notarized_hash,sizeof(notarized_hash),filedata,&fpos,datalen) != sizeof(notarized_hash) )
errs++;
if ( memread(&notarized_desttxid,sizeof(notarized_desttxid),filedata,&fpos,datalen) != sizeof(notarized_desttxid) )
errs++;
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 )
printf("%s load[%s.%d -> %s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str());
//if ( matched != 0 ) global independent states -> inside *sp
komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height);
}
else if ( func == 'U' ) // deprecated
{
uint8_t n,nid; uint256 hash; uint64_t mask;
n = filedata[fpos++];
nid = filedata[fpos++];
//printf("U %d %d\n",n,nid);
if ( memread(&mask,sizeof(mask),filedata,&fpos,datalen) != sizeof(mask) )
errs++;
if ( memread(&hash,sizeof(hash),filedata,&fpos,datalen) != sizeof(hash) )
errs++;
}
else if ( func == 'K' )
{
int32_t kheight;
if ( memread(&kheight,sizeof(kheight),filedata,&fpos,datalen) != sizeof(kheight) )
errs++;
komodo_eventadd_kmdheight(sp,symbol,ht,kheight,0);
}
else if ( func == 'T' )
{
int32_t kheight,ktimestamp;
if ( memread(&kheight,sizeof(kheight),filedata,&fpos,datalen) != sizeof(kheight) )
errs++;
if ( memread(&ktimestamp,sizeof(ktimestamp),filedata,&fpos,datalen) != sizeof(ktimestamp) )
errs++;
//if ( matched != 0 ) global independent states -> inside *sp
//printf("%s.%d load[%s] ht.%d t.%u\n",ASSETCHAINS_SYMBOL,ht,symbol,kheight,ktimestamp);
komodo_eventadd_kmdheight(sp,symbol,ht,kheight,ktimestamp);
}
else if ( func == 'R' )
{
uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[16384];
if ( memread(&txid,sizeof(txid),filedata,&fpos,datalen) != sizeof(txid) )
errs++;
if ( memread(&v,sizeof(v),filedata,&fpos,datalen) != sizeof(v) )
errs++;
if ( memread(&ovalue,sizeof(ovalue),filedata,&fpos,datalen) != sizeof(ovalue) )
errs++;
if ( memread(&olen,sizeof(olen),filedata,&fpos,datalen) != sizeof(olen) )
errs++;
if ( olen < sizeof(opret) )
{
if ( memread(opret,olen,filedata,&fpos,datalen) != olen )
errs++;
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 )
{
int32_t i; for (i=0; i<olen; i++)
printf("%02x",opret[i]);
printf(" %s.%d load[%s] opret[%c] len.%d %.8f\n",ASSETCHAINS_SYMBOL,ht,symbol,opret[0],olen,(double)ovalue/COIN);
}
komodo_eventadd_opreturn(sp,symbol,ht,txid,ovalue,v,opret,olen); // global shared state -> global PAX
} else
{
int32_t i;
for (i=0; i<olen; i++)
filedata[fpos++];
//printf("illegal olen.%u\n",olen);
}
}
else if ( func == 'D' )
{
printf("unexpected function D[%d]\n",ht);
}
else if ( func == 'V' )
{
int32_t numpvals; uint32_t pvals[128];
numpvals = filedata[fpos++];
if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && memread(pvals,(int32_t)(sizeof(uint32_t)*numpvals),filedata,&fpos,datalen) == numpvals*sizeof(uint32_t) )
{
//if ( matched != 0 ) global shared state -> global PVALS
//printf("%s load[%s] prices %d\n",ASSETCHAINS_SYMBOL,symbol,ht);
komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals);
//printf("load pvals ht.%d numpvals.%d\n",ht,numpvals);
} else printf("error loading pvals[%d]\n",numpvals);
}
else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func);
*fposp = fpos;
return(func);
}
return(-1);
}

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)
{
static FILE *fp; static int32_t errs,didinit;
struct komodo_state *sp; char fname[512],symbol[16],dest[16]; int32_t ht,func; uint8_t num,pubkeys[64][33];
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];
if ( didinit == 0 )
{
portable_mutex_init(&KOMODO_KV_mutex);
Expand All @@ -214,10 +347,15 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate");
if ( (fp= fopen(fname,"rb+")) != 0 )
{
while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 )
;
if ( (retval= komodo_faststateinit(sp,fname,symbol,dest)) > 0 )
fseek(fp,0,SEEK_END);
else
{
fprintf(stderr,"komodo_faststateinit retval.%d\n",retval);
while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 )
;
}
} else fp = fopen(fname,"wb+");
printf("fname.(%s) fpos.%ld\n",fname,ftell(fp));
KOMODO_INITDONE = (uint32_t)time(NULL);
}
if ( height <= 0 )
Expand Down Expand Up @@ -338,7 +476,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
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)
{
static uint256 zero; static FILE *signedfp;
int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[16],dest[16];
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];
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
return(-1);
if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
Expand Down Expand Up @@ -407,7 +545,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0);
len += 4;
if ( ASSETCHAINS_SYMBOL[0] != 0 )
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);
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);
if ( ASSETCHAINS_SYMBOL[0] == 0 )
{
if ( signedfp == 0 )
Expand Down Expand Up @@ -496,7 +634,7 @@ int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys
void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
{
static int32_t hwmheight;
uint64_t signedmask,voutmask; char symbol[16],dest[16]; struct komodo_state *sp;
uint64_t signedmask,voutmask; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
uint8_t scriptbuf[4096],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 kmdtxid,zero,btctxid,txhash;
int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
memset(&zero,0,sizeof(zero));
Expand Down
4 changes: 3 additions & 1 deletion src/komodo_bitcoind.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <curl/easy.h>
#endif

#include "komodo_defs.h"

//#define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"curl",(char *)"http://127.0.0.1:7776",0,0,(char *)(cmdstr))

struct MemoryStruct { char *memory; size_t size; };
Expand Down Expand Up @@ -559,7 +561,7 @@ uint32_t komodo_txtime(uint256 hash)

void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
{
char symbol[16],dest[16]; struct komodo_state *sp;
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
//fprintf(stderr,"disconnect ht.%d\n",pindex->nHeight);
komodo_init(pindex->nHeight);
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
Expand Down
9 changes: 9 additions & 0 deletions src/komodo_defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef KOMODO_DEFS_H
#define KOMODO_DEFS_H

#define ASSETCHAINS_MINHEIGHT 128
#define KOMODO_ELECTION_GAP 2000
#define ROUNDROBIN_DELAY 61
#define KOMODO_ASSETCHAIN_MAXLEN 65

#endif
1 change: 1 addition & 0 deletions src/komodo_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#ifndef H_KOMODOEVENTS_H
#define H_KOMODOEVENTS_H
#include "komodo_defs.h"

struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen)
{
Expand Down
Loading

0 comments on commit 65cddb3

Please sign in to comment.