@@ -95,6 +95,8 @@ public:
|
||||
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
|
||||
vFixedSeeds.clear();
|
||||
vSeeds.clear();
|
||||
vSeeds.push_back(CDNSSeedData("komodoplatform.com", "seeds.komodoplatform.com")); // @kolo
|
||||
vSeeds.push_back(CDNSSeedData("komodo.mewhub.com", "seeds.komodo.mewhub.com")); // @kolo
|
||||
// TODO: set up bootstrapping for mainnet
|
||||
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,60);
|
||||
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,85);
|
||||
|
||||
18
src/komodo.h
18
src/komodo.h
@@ -17,13 +17,15 @@
|
||||
#define H_KOMODO_H
|
||||
|
||||
// Todo:
|
||||
// 1. net balance limiter
|
||||
// 2. verify: reorgs
|
||||
// verify: reorgs
|
||||
|
||||
// non komodod (non-hardfork) todo:
|
||||
// a. automate notarization fee payouts
|
||||
// b. automated distribution of test REVS snapshot
|
||||
|
||||
//#define KOMODO_ASSETCHAINS_WAITNOTARIZE
|
||||
#define KOMODO_PAXMAX (10000 * COIN)
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
@@ -84,7 +86,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
|
||||
errs++;
|
||||
else
|
||||
{
|
||||
printf("updated %d pubkeys at %s ht.%d\n",num,symbol,ht);
|
||||
//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);
|
||||
}
|
||||
@@ -163,7 +165,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
|
||||
int32_t i;
|
||||
for (i=0; i<olen; i++)
|
||||
fgetc(fp);
|
||||
printf("illegal olen.%u\n",olen);
|
||||
//printf("illegal olen.%u\n",olen);
|
||||
}
|
||||
}
|
||||
else if ( func == 'D' )
|
||||
@@ -510,9 +512,9 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
}
|
||||
}
|
||||
numvalid = bitweight(signedmask);
|
||||
if ( height == 79633 )
|
||||
notarized = 1;
|
||||
if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || numvalid > (numnotaries>>1)) )
|
||||
//if ( height == 79633 )
|
||||
// notarized = 1;
|
||||
if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || numvalid > (numnotaries/3)) )
|
||||
{
|
||||
printf("%s ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts);
|
||||
notarized = 1;
|
||||
@@ -563,7 +565,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries>>1) )
|
||||
if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries/3) )
|
||||
{
|
||||
memset(&txhash,0,sizeof(txhash));
|
||||
komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0,0);
|
||||
|
||||
@@ -366,7 +366,7 @@ uint256 komodo_getblockhash(int32_t height)
|
||||
}
|
||||
free_json(result);
|
||||
}
|
||||
printf("KMD hash.%d (%s) %x\n",height,jsonstr,*(uint32_t *)&hash);
|
||||
//printf("KMD hash.%d (%s) %x\n",height,jsonstr,*(uint32_t *)&hash);
|
||||
free(jsonstr);
|
||||
}
|
||||
return(hash);
|
||||
|
||||
@@ -52,7 +52,7 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig
|
||||
void komodo_eventadd_pubkeys(struct komodo_state *sp,char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33])
|
||||
{
|
||||
struct komodo_event_pubkeys P;
|
||||
printf("eventadd pubkeys ht.%d\n",height);
|
||||
//printf("eventadd pubkeys ht.%d\n",height);
|
||||
memset(&P,0,sizeof(P));
|
||||
P.num = num;
|
||||
memcpy(P.pubkeys,pubkeys,33 * num);
|
||||
|
||||
@@ -15,26 +15,70 @@
|
||||
|
||||
// paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse
|
||||
|
||||
struct pax_transaction *komodo_paxfind(uint256 txid,uint16_t vout)
|
||||
int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base)
|
||||
{
|
||||
struct pax_transaction *pax;
|
||||
int32_t baseid; struct komodo_state *sp; int64_t netliability,maxallowed;
|
||||
*available = *deposited = *issued = *withdrawn = *approved = *redeemed = 0;
|
||||
if ( (baseid= komodo_baseid(base)) >= 0 )
|
||||
{
|
||||
if ( (sp= komodo_stateptrget(base)) != 0 )
|
||||
{
|
||||
*deposited = sp->deposited;
|
||||
*issued = sp->issued;
|
||||
*withdrawn = sp->withdrawn;
|
||||
*approved = sp->approved;
|
||||
*redeemed = sp->redeemed;
|
||||
netliability = (sp->deposited - sp->withdrawn) - sp->shorted;
|
||||
maxallowed = komodo_maxallowed(baseid);
|
||||
if ( netliability < maxallowed )
|
||||
*available = (maxallowed - netliability);
|
||||
//printf("%p %s %.8f %.8f %.8f %.8f %.8f\n",sp,base,dstr(*deposited),dstr(*issued),dstr(*withdrawn),dstr(*approved),dstr(*redeemed));
|
||||
return(0);
|
||||
} else printf("pax_fiatstatus cant get basesp.%s\n",base);
|
||||
} else printf("pax_fiatstatus illegal base.%s\n",base);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
void pax_keyset(uint8_t *buf,uint256 txid,uint16_t vout,uint8_t type)
|
||||
{
|
||||
memcpy(buf,&txid,32);
|
||||
memcpy(&buf[32],&vout,2);
|
||||
buf[34] = type;
|
||||
}
|
||||
|
||||
struct pax_transaction *komodo_paxfind(uint256 txid,uint16_t vout,uint8_t type)
|
||||
{
|
||||
struct pax_transaction *pax; uint8_t buf[35];
|
||||
pthread_mutex_lock(&komodo_mutex);
|
||||
HASH_FIND(hh,PAX,&txid,sizeof(txid),pax);
|
||||
pax_keyset(buf,txid,vout,type);
|
||||
HASH_FIND(hh,PAX,buf,sizeof(buf),pax);
|
||||
pthread_mutex_unlock(&komodo_mutex);
|
||||
return(pax);
|
||||
}
|
||||
|
||||
struct pax_transaction *komodo_paxmark(int32_t height,uint256 txid,uint16_t vout,int32_t mark)
|
||||
struct pax_transaction *komodo_paxfinds(uint256 txid,uint16_t vout)
|
||||
{
|
||||
struct pax_transaction *pax;
|
||||
struct pax_transaction *pax; int32_t i; uint8_t types[] = { 'D', 'I', 'W', 'A', 'X' };
|
||||
for (i=0; i<sizeof(types)/sizeof(*types); i++)
|
||||
if ( (pax= komodo_paxfind(txid,vout,types[i])) != 0 )
|
||||
return(pax);
|
||||
return(0);
|
||||
}
|
||||
|
||||
struct pax_transaction *komodo_paxmark(int32_t height,uint256 txid,uint16_t vout,uint8_t type,int32_t mark)
|
||||
{
|
||||
struct pax_transaction *pax; uint8_t buf[35];
|
||||
pthread_mutex_lock(&komodo_mutex);
|
||||
HASH_FIND(hh,PAX,&txid,sizeof(txid),pax);
|
||||
pax_keyset(buf,txid,vout,type);
|
||||
HASH_FIND(hh,PAX,buf,sizeof(buf),pax);
|
||||
if ( pax == 0 )
|
||||
{
|
||||
pax = (struct pax_transaction *)calloc(1,sizeof(*pax));
|
||||
pax->txid = txid;
|
||||
pax->vout = vout;
|
||||
HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax);
|
||||
pax->type = type;
|
||||
memcpy(pax->buf,buf,sizeof(pax->buf));
|
||||
HASH_ADD_KEYPTR(hh,PAX,pax->buf,sizeof(pax->buf),pax);
|
||||
//printf("ht.%d create pax.%p mark.%d\n",height,pax,mark);
|
||||
}
|
||||
if ( pax != 0 )
|
||||
@@ -48,24 +92,27 @@ struct pax_transaction *komodo_paxmark(int32_t height,uint256 txid,uint16_t vout
|
||||
return(pax);
|
||||
}
|
||||
|
||||
void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,int32_t height,int32_t otherheight,char *source,int32_t approved) // assetchain context
|
||||
void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,uint8_t type,int32_t height,int32_t otherheight,char *source,int32_t approved) // assetchain context
|
||||
{
|
||||
struct pax_transaction *pax; int32_t addflag = 0; struct komodo_state *sp; char str[16],dest[16],*s;
|
||||
struct pax_transaction *pax; uint8_t buf[35]; int32_t addflag = 0; struct komodo_state *sp; char str[16],dest[16],*s;
|
||||
sp = komodo_stateptr(str,dest);
|
||||
pthread_mutex_lock(&komodo_mutex);
|
||||
HASH_FIND(hh,PAX,&txid,sizeof(txid),pax);
|
||||
pax_keyset(buf,txid,vout,type);
|
||||
HASH_FIND(hh,PAX,buf,sizeof(buf),pax);
|
||||
if ( pax == 0 )
|
||||
{
|
||||
pax = (struct pax_transaction *)calloc(1,sizeof(*pax));
|
||||
pax->txid = txid;
|
||||
pax->vout = vout;
|
||||
HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax);
|
||||
pax->type = type;
|
||||
memcpy(pax->buf,buf,sizeof(pax->buf));
|
||||
HASH_ADD_KEYPTR(hh,PAX,pax->buf,sizeof(pax->buf),pax);
|
||||
addflag = 1;
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
{
|
||||
int32_t i; for (i=0; i<32; i++)
|
||||
printf("%02x",((uint8_t *)&txid)[i]);
|
||||
printf(" v.%d [%s] kht.%d ht.%d create pax.%p\n",vout,ASSETCHAINS_SYMBOL,height,otherheight,pax);
|
||||
printf(" v.%d [%s] kht.%d ht.%d create pax.%p symbol.%s source.%s\n",vout,ASSETCHAINS_SYMBOL,height,otherheight,pax,symbol,source);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&komodo_mutex);
|
||||
@@ -88,12 +135,12 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t
|
||||
pax->otherheight = otherheight;
|
||||
if ( pax->marked == 0 )
|
||||
{
|
||||
if ( addflag != 0 )
|
||||
if ( 0 && addflag != 0 )
|
||||
{
|
||||
if ( (pax->approved= approved) != 0 )
|
||||
s = (char *)"APPROVED";
|
||||
else s = (char *)(ASSETCHAINS_SYMBOL[0]==0?"WITHDRAW":"DEPOSIT");
|
||||
printf("[%s] addflag.%d ADD %s %s %.8f -> %s TO PAX ht.%d otherht.%d total %.8f\n",ASSETCHAINS_SYMBOL,addflag,s,symbol,dstr(ASSETCHAINS_SYMBOL[0]==0?pax->komodoshis:pax->fiatoshis),pax->coinaddr,pax->height,pax->otherheight,dstr(komodo_paxtotal()));
|
||||
else s = (char *)((strcmp(pax->symbol,"KMD") == 0) ? "WITHDRAW" : "DEPOSIT");
|
||||
printf("[%s] addflag.%d ADD %s/%s %s %.8f -> %s TO PAX ht.%d otherht.%d total %.8f\n",ASSETCHAINS_SYMBOL,addflag,s,symbol,source,dstr(strcmp(pax->symbol,"KMD")==0?pax->komodoshis:pax->fiatoshis),pax->coinaddr,pax->height,pax->otherheight,dstr(komodo_paxtotal()));
|
||||
}
|
||||
}
|
||||
//else printf("%p MARKED.%d DEPOSIT %s %.8f -> %s TO PAX ht.%d otherht.%d\n",pax,pax->marked,symbol,dstr(fiatoshis),coinaddr,height,otherheight);
|
||||
@@ -101,7 +148,7 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t
|
||||
else
|
||||
{
|
||||
pax->marked = height;
|
||||
printf("pax.%p MARK DEPOSIT ht.%d other.%d\n",pax,height,otherheight);
|
||||
//printf("pax.%p MARK DEPOSIT ht.%d other.%d\n",pax,height,otherheight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,11 +166,11 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio
|
||||
{
|
||||
for (i=0; i<32; i++)
|
||||
((uint8_t *)&pax->txid)[i] = opretbuf[len++];
|
||||
for (i=0; i<32; i++)
|
||||
printf("%02x",((uint8_t *)&pax->txid)[31-i]);
|
||||
//for (i=0; i<32; i++)
|
||||
// printf("%02x",((uint8_t *)&pax->txid)[31-i]);
|
||||
pax->vout = opretbuf[len++];
|
||||
pax->vout += ((uint32_t)opretbuf[len++] << 8);
|
||||
printf(" txid v.%d\n",pax->vout);
|
||||
//printf(" txid v.%d\n",pax->vout);
|
||||
}
|
||||
len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->komodoshis),&pax->komodoshis);
|
||||
len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->fiatoshis),&pax->fiatoshis);
|
||||
@@ -146,14 +193,15 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio
|
||||
|
||||
int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int64_t *srcvalues,int32_t *kmdheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo)
|
||||
{
|
||||
struct pax_transaction p; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t type,rmd160[20]; uint64_t fiatoshis; char symbol[16];
|
||||
struct pax_transaction p,*pax; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t type,rmd160[20]; uint64_t fiatoshis; char symbol[16];
|
||||
incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4));
|
||||
for (i=0; i<4; i++)
|
||||
base[i] = opretbuf[opretlen-4+i];
|
||||
//for (i=0; i<opretlen; i++)
|
||||
// printf("%02x",opretbuf[i]);
|
||||
//printf(" opretlen.%d (%s)\n",opretlen,base);
|
||||
//printf(" opretlen.%d vs %d incr.%d\n",opretlen,(int32_t)(2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4),incr);
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 )
|
||||
//if ( ASSETCHAINS_SYMBOL[0] == 0 || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 )
|
||||
{
|
||||
type = opretbuf[0];
|
||||
opretbuf++, opretlen--;
|
||||
@@ -167,12 +215,13 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t
|
||||
{
|
||||
txids[n] = p.txid;
|
||||
vouts[n] = p.vout;
|
||||
values[n] = (ASSETCHAINS_SYMBOL[0] == 0) ? p.komodoshis : p.fiatoshis;
|
||||
srcvalues[n] = (ASSETCHAINS_SYMBOL[0] == 0) ? p.fiatoshis : p.komodoshis;
|
||||
values[n] = (strcmp("KMD",base) == 0) ? p.komodoshis : p.fiatoshis;
|
||||
srcvalues[n] = (strcmp("KMD",base) == 0) ? p.fiatoshis : p.komodoshis;
|
||||
kmdheights[n] = p.height;
|
||||
otherheights[n] = p.otherheight;
|
||||
memcpy(&rmd160s[n * 20],p.rmd160,20);
|
||||
baseids[n] = komodo_baseid(p.source);
|
||||
if ( 0 )
|
||||
{
|
||||
char coinaddr[64];
|
||||
bitcoin_address(coinaddr,60,&rmd160s[n * 20],20);
|
||||
@@ -189,6 +238,15 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t
|
||||
}
|
||||
vouts[n] = opretbuf[len++];
|
||||
vouts[n] = (opretbuf[len++] << 8) | vouts[n];
|
||||
baseids[n] = komodo_baseid(base);
|
||||
if ( (pax= komodo_paxfinds(txids[n],vouts[n])) != 0 )
|
||||
{
|
||||
values[n] = (strcmp("KMD",base) == 0) ? pax->komodoshis : pax->fiatoshis;
|
||||
srcvalues[n] = (strcmp("KMD",base) == 0) ? pax->fiatoshis : pax->komodoshis;
|
||||
kmdheights[n] = pax->height;
|
||||
otherheights[n] = pax->otherheight;
|
||||
memcpy(&rmd160s[n * 20],pax->rmd160,20);
|
||||
}
|
||||
}
|
||||
//printf(" komodo_issued_opreturn issuedtxid v%d i.%d opretlen.%d\n",vouts[n],n,opretlen);
|
||||
}
|
||||
@@ -198,9 +256,40 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t
|
||||
|
||||
uint64_t komodo_paxtotal()
|
||||
{
|
||||
struct pax_transaction *pax,*tmp; char symbol[16],dest[16]; int32_t ht; int64_t checktoshis; uint64_t seed,total = 0;
|
||||
struct pax_transaction *pax,*pax2,*tmp,*tmp2; char symbol[16],dest[16],*str; int32_t i,ht; int64_t checktoshis; uint64_t seed,total = 0; struct komodo_state *basesp;
|
||||
if ( komodo_isrealtime(&ht) == 0 )
|
||||
return(0);
|
||||
else
|
||||
{
|
||||
HASH_ITER(hh,PAX,pax,tmp)
|
||||
{
|
||||
if ( pax->type == 'A' || pax->type == 'D' || pax->type == 'X' )
|
||||
str = pax->symbol;
|
||||
else str = pax->source;
|
||||
basesp = komodo_stateptrget(str);
|
||||
if ( basesp != 0 && pax->didstats == 0 && pax->type == 'I' )
|
||||
{
|
||||
if ( (pax2= komodo_paxfind(pax->txid,pax->vout,'D')) != 0 )
|
||||
{
|
||||
if ( pax2->fiatoshis != 0 )
|
||||
{
|
||||
pax->komodoshis = pax2->komodoshis;
|
||||
pax->fiatoshis = pax2->fiatoshis;
|
||||
basesp->issued += pax->fiatoshis;
|
||||
pax->didstats = 1;
|
||||
//printf("Iset %s dstats %.8f += %.8f\n",str,dstr(basesp->issued),dstr(pax->fiatoshis));
|
||||
pax2->marked = pax->height;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*if ( strcmp(str,"HRK") == 0 || strcmp("HRK",pax->symbol) == 0 || strcmp("HRK",pax->source) == 0 )
|
||||
{
|
||||
for (i=0; i<32; i++)
|
||||
printf("%02x",((uint8_t *)&pax->txid)[i]);
|
||||
printf(" stats.%d type.%c (%s) k.%d %.8f h.%d %.8f I.%.8f X.%.8f\n",pax->didstats,pax->type,str,pax->height,dstr(pax->komodoshis),pax->otherheight,dstr(pax->fiatoshis),dstr(basesp->issued),dstr(basesp->redeemed));
|
||||
}*/
|
||||
}
|
||||
}
|
||||
komodo_stateptr(symbol,dest);
|
||||
HASH_ITER(hh,PAX,pax,tmp)
|
||||
{
|
||||
@@ -219,8 +308,8 @@ uint64_t komodo_paxtotal()
|
||||
{
|
||||
seed = 0;
|
||||
checktoshis = komodo_paxprice(&seed,pax->height,pax->source,(char *)"KMD",(uint64_t)pax->fiatoshis);
|
||||
printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",pax->height,pax->symbol,(double)pax->fiatoshis/COIN,(double)pax->komodoshis/COIN,(double)checktoshis/COIN);
|
||||
printf(" v%d %.8f k.%d ht.%d\n",pax->vout,dstr(pax->komodoshis),pax->height,pax->otherheight);
|
||||
//printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",pax->height,pax->symbol,(double)pax->fiatoshis/COIN,(double)pax->komodoshis/COIN,(double)checktoshis/COIN);
|
||||
//printf(" v%d %.8f k.%d ht.%d\n",pax->vout,dstr(pax->komodoshis),pax->height,pax->otherheight);
|
||||
if ( seed != 0 )
|
||||
{
|
||||
if ( checktoshis >= pax->komodoshis )
|
||||
@@ -252,19 +341,19 @@ int32_t komodo_pending_withdraws(char *opretstr)
|
||||
if ( len == 0 )
|
||||
opretbuf[len++] = 'A';
|
||||
len += komodo_rwapproval(1,&opretbuf[len],pax);
|
||||
printf("%s.(marked.%u approved.%d) %p\n",pax->source,pax->marked,pax->approved,pax);
|
||||
//printf("%s.(marked.%u approved.%d) %p\n",pax->source,pax->marked,pax->approved,pax);
|
||||
}
|
||||
}
|
||||
if ( len > 0 )
|
||||
init_hexbytes_noT(opretstr,opretbuf,len);
|
||||
else opretstr[0] = 0;
|
||||
printf("komodo_pending_withdraws len.%d PAXTOTAL %.8f\n",len,dstr(komodo_paxtotal()));
|
||||
fprintf(stderr,"komodo_pending_withdraws len.%d PAXTOTAL %.8f\n",len,dstr(komodo_paxtotal()));
|
||||
return(len);
|
||||
}
|
||||
|
||||
int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t tokomodo)
|
||||
{
|
||||
struct pax_transaction *pax,*tmp; char symbol[16],dest[16]; uint8_t *script,opcode,opret[16384],data[16384]; int32_t i,baseid,ht,len=0,opretlen=0,numvouts=1; struct komodo_state *sp; uint64_t mask;
|
||||
struct pax_transaction *pax,*tmp; char symbol[16],dest[16]; uint8_t *script,opcode,opret[16384],data[16384]; int32_t i,baseid,ht,len=0,opretlen=0,numvouts=1; struct komodo_state *sp; uint64_t available,deposited,issued,withdrawn,approved,redeemed,mask;
|
||||
sp = komodo_stateptr(symbol,dest);
|
||||
strcpy(symbol,base);
|
||||
PENDING_KOMODO_TX = 0;
|
||||
@@ -273,16 +362,28 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to
|
||||
opcode = 'I';
|
||||
if ( komodo_isrealtime(&ht) == 0 )
|
||||
return(0);
|
||||
}
|
||||
else opcode = 'X';
|
||||
} else opcode = 'X';
|
||||
HASH_ITER(hh,PAX,pax,tmp)
|
||||
{
|
||||
//printf("pax.%s marked.%d %.8f -> %.8f\n",pax->symbol,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis));
|
||||
if ( strcmp(symbol,"KMD") == 0 && (pax->approved == 0 || pax->validated == 0) )
|
||||
if ( strcmp(symbol,"KMD") == 0 && pax->approved == 0 )
|
||||
continue;
|
||||
if ( pax->marked != 0 || strcmp(pax->symbol,symbol) != 0 )
|
||||
//else if ( strcmp(symbol,"KMD") != 0 )
|
||||
{
|
||||
#ifdef KOMODO_ASSETCHAINS_WAITNOTARIZE
|
||||
struct komodo_state *kmdsp = komodo_stateptrget((char *)"KMD");
|
||||
if ( kmdsp != 0 && kmdsp->NOTARIZED_HEIGHT >= pax->height ) // assumes same chain as notarize
|
||||
pax->validated = kmdsp->NOTARIZED_HEIGHT;
|
||||
#endif
|
||||
}
|
||||
if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,symbol) != 0 || available < pax->fiatoshis )
|
||||
{
|
||||
printf("miner: skip %s %.8f when avail %.8f\n",symbol,dstr(pax->fiatoshis),dstr(available));
|
||||
continue;
|
||||
//if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
}
|
||||
if ( pax->marked != 0 || strcmp(pax->symbol,symbol) != 0 || pax->validated == 0 )
|
||||
continue;
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
printf("pax.%s marked.%d %.8f -> %.8f\n",ASSETCHAINS_SYMBOL,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis));
|
||||
txNew->vout.resize(numvouts+1);
|
||||
txNew->vout[numvouts].nValue = (opcode == 'I') ? pax->fiatoshis : pax->komodoshis;
|
||||
@@ -297,26 +398,16 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to
|
||||
if ( tokomodo == 0 )
|
||||
{
|
||||
for (i=0; i<32; i++)
|
||||
{
|
||||
//printf("%02x",((uint8_t *)&pax->txid)[i]);
|
||||
data[len++] = ((uint8_t *)&pax->txid)[i];
|
||||
}
|
||||
data[len++] = pax->vout & 0xff;
|
||||
data[len++] = (pax->vout >> 8) & 0xff;
|
||||
PENDING_KOMODO_TX += pax->fiatoshis;
|
||||
}
|
||||
else
|
||||
{
|
||||
//[{"prev_hash":"5d5c9a49489b558de9e84f991f996dedaae6b9d0f157f82b2fec64662476d5cf","prev_vout":2,"EUR":0.10000000,"fiat":"EUR","kmdheight":57930,"height":153,"KMD":0.78329000,"address":"RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5","rmd160":"306c507eea639e7220b3069ed9f49f3bc97eaca1"}]
|
||||
len += komodo_rwapproval(1,&data[len],pax);
|
||||
/*len += iguana_rwnum(1,&data[len],sizeof(pax->fiatoshis),&pax->fiatoshis);
|
||||
len += iguana_rwnum(1,&data[len],sizeof(pax->height),&pax->height);
|
||||
len += iguana_rwnum(1,&data[len],sizeof(pax->otherheight),&pax->otherheight);
|
||||
for (i=0; pax->symbol[i]!=0&&i<3; i++) // must be 3 letter currency
|
||||
data[len++] = pax->symbol[i];
|
||||
data[len++] = 0;*/
|
||||
PENDING_KOMODO_TX += pax->komodoshis;
|
||||
printf(" vout.%u DEPOSIT %.8f <- pax.%s pending %.8f | ",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,dstr(PENDING_KOMODO_TX));
|
||||
//printf(" vout.%u DEPOSIT %.8f <- pax.%s pending %.8f | ",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,dstr(PENDING_KOMODO_TX));
|
||||
}
|
||||
if ( numvouts++ >= 64 )
|
||||
break;
|
||||
@@ -342,7 +433,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to
|
||||
|
||||
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,errs=0,matched=0,kmdheights[64],otherheights[64]; uint256 hash,txids[64]; char symbol[16],base[16]; uint16_t vouts[64]; int8_t baseids[64]; uint8_t *script,opcode,rmd160s[64*20]; int64_t values[64],srcvalues[64]; struct pax_transaction *pax;
|
||||
int32_t i,j,n,num,opretlen,offset=1,errs=0,matched=0,kmdheights[64],otherheights[64]; uint256 hash,txids[64]; char symbol[16],base[16]; uint16_t vouts[64]; int8_t baseids[64]; uint8_t *script,opcode,rmd160s[64*20]; uint64_t available,deposited,issued,withdrawn,approved,redeemed; int64_t values[64],srcvalues[64]; struct pax_transaction *pax;
|
||||
memset(baseids,0xff,sizeof(baseids));
|
||||
memset(values,0,sizeof(values));
|
||||
memset(srcvalues,0,sizeof(srcvalues));
|
||||
@@ -373,45 +464,43 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
|
||||
{
|
||||
for (i=1; i<n-1; i++)
|
||||
{
|
||||
if ( (pax= komodo_paxfind(txids[i-1],vouts[i-1])) != 0 )
|
||||
if ( (pax= komodo_paxfinds(txids[i-1],vouts[i-1])) != 0 )
|
||||
{
|
||||
if ( ((opcode == 'I' && pax->fiatoshis == block.vtx[0].vout[i].nValue) || (opcode == 'X' && pax->komodoshis == block.vtx[0].vout[i].nValue)) )
|
||||
pax->type = opcode;
|
||||
if ( opcode == 'I' && pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,symbol) != 0 || available < pax->fiatoshis )
|
||||
{
|
||||
printf("checkdeposit: skip %s %.8f when avail %.8f\n",pax->symbol,dstr(pax->fiatoshis),dstr(available));
|
||||
continue;
|
||||
}
|
||||
if ( ((opcode == 'I' && (pax->fiatoshis == 0 || pax->fiatoshis == block.vtx[0].vout[i].nValue)) || (opcode == 'X' && (pax->komodoshis == 0 || pax->komodoshis == block.vtx[0].vout[i].nValue))) )
|
||||
{
|
||||
if ( pax->marked != 0 && height >= 80820 )
|
||||
{
|
||||
printf("%c errs.%d i.%d match %.8f vs %.8f pax.%p\n",opcode,errs,i,dstr(opcode == 'I' ? pax->fiatoshis : pax->komodoshis),dstr(block.vtx[0].vout[i].nValue),pax);
|
||||
errs++;
|
||||
else matched++;
|
||||
if ( 0 && opcode == 'X' )
|
||||
printf("errs.%d i.%d match %.8f == %.8f pax.%p\n",errs,i,dstr(pax != 0 ? pax->komodoshis:-1),dstr(block.vtx[0].vout[i].nValue),pax);
|
||||
//komodo_paxmark(height,txids[i-1],vouts[i-1],height);
|
||||
//if ( pax->marked == 0 )
|
||||
// printf("unexpected unmarked %p\n",pax);
|
||||
} else matched++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( opcode == 'X' )
|
||||
{
|
||||
for (j=0; j<32; j++)
|
||||
printf("%02x",((uint8_t *)&txids[i-1])[j]);
|
||||
printf(" cant paxfind X txid\n");
|
||||
}
|
||||
for (j=0; j<32; j++)
|
||||
printf("%02x",((uint8_t *)&txids[i-1])[j]);
|
||||
printf(" cant paxfind %c txid\n",opcode);
|
||||
printf("%c errs.%d i.%d match %.8f vs %.8f pax.%p\n",opcode,errs,i,dstr(opcode == 'I' ? pax->fiatoshis : pax->komodoshis),dstr(block.vtx[0].vout[i].nValue),pax);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( opcode == 'X' )
|
||||
{
|
||||
hash = block.GetHash();
|
||||
for (j=0; j<32; j++)
|
||||
printf("%02x",((uint8_t *)&hash)[j]);
|
||||
printf(" ht.%d blockhash X couldnt find vout.[%d]\n",height,i);
|
||||
} else if ( opcode == 'I' )
|
||||
matched++;
|
||||
hash = block.GetHash();
|
||||
for (j=0; j<32; j++)
|
||||
printf("%02x",((uint8_t *)&hash)[j]);
|
||||
printf(" ht.%d blockhash X couldnt find vout.[%d]\n",height,i);
|
||||
}
|
||||
}
|
||||
if ( matched != num )
|
||||
{
|
||||
printf("WOULD REJECT: ht.%d (%c) matched.%d vs num.%d\n",height,opcode,matched,num);
|
||||
// can easily happen depending on order of loading
|
||||
if ( height > 100000 && opcode == 'X' )
|
||||
if ( height > 100000 ) //&& opcode == 'X' )
|
||||
{
|
||||
printf("REJECT: ht.%d (%c) matched.%d vs num.%d\n",height,opcode,matched,num);
|
||||
return(-1);
|
||||
@@ -423,9 +512,27 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above
|
||||
return(0);
|
||||
}
|
||||
|
||||
int32_t komodo_paxcmp(int32_t kmdheight,uint64_t value,uint64_t checkvalue,uint64_t seed)
|
||||
{
|
||||
int32_t ratio;
|
||||
if ( seed == 0 && checkvalue != 0 )
|
||||
{
|
||||
ratio = ((value << 6) / checkvalue);
|
||||
if ( ratio >= 63 && ratio <= 65 )
|
||||
return(0);
|
||||
else
|
||||
{
|
||||
if ( kmdheight >= 86150 )
|
||||
printf("ht.%d ignore mismatched value %lld vs checkvalue %lld -> ratio.%d\n",kmdheight,(long long)value,(long long)checkvalue,ratio);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
return(value != checkvalue);
|
||||
}
|
||||
|
||||
const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source)
|
||||
{
|
||||
uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax;
|
||||
uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax; struct komodo_state *basesp; double diff;
|
||||
const char *typestr = "unknown";
|
||||
memset(baseids,0xff,sizeof(baseids));
|
||||
memset(values,0,sizeof(values));
|
||||
@@ -433,7 +540,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
|
||||
memset(rmd160s,0,sizeof(rmd160s));
|
||||
memset(kmdheights,0,sizeof(kmdheights));
|
||||
memset(otherheights,0,sizeof(otherheights));
|
||||
tokomodo = (komodo_is_issuer() == 0);
|
||||
tokomodo = (komodo_baseid(source) >= 0 && komodo_baseid(source) != 32); //(komodo_is_issuer() == 0);
|
||||
if ( opretbuf[0] == 'D' )
|
||||
{
|
||||
if ( opretlen == 38 ) // any KMD tx
|
||||
@@ -444,23 +551,43 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
|
||||
bitcoin_address(coinaddr,addrtype,rmd160,20);
|
||||
checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis);
|
||||
typestr = "deposit";
|
||||
printf("%s kmdheight.%d vs height.%d check %.8f vs %.8f tokomodo.%d %d seed.%llx\n",ASSETCHAINS_SYMBOL,kmdheight,height,dstr(checktoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0,(long long)seed);
|
||||
//printf("(%s) (%s) kmdheight.%d vs height.%d check %.8f vs %.8f tokomodo.%d %d seed.%llx\n",ASSETCHAINS_SYMBOL,base,kmdheight,height,dstr(checktoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0,(long long)seed);
|
||||
if ( kmdheight <= height )
|
||||
{
|
||||
if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 )
|
||||
/*for (i=0; i<32; i++)
|
||||
printf("%02x",((uint8_t *)&txid)[i]);
|
||||
printf(" <- txid.v%u ",vout);
|
||||
for (i=0; i<33; i++)
|
||||
printf("%02x",pubkey33[i]);
|
||||
printf(" checkpubkey check %.8f v %.8f dest.(%s) kmdheight.%d height.%d\n",dstr(checktoshis),dstr(value),destaddr,kmdheight,height);*/
|
||||
didstats = 0;
|
||||
if ( komodo_paxcmp(kmdheight,value,checktoshis,seed) == 0 )
|
||||
{
|
||||
for (i=0; i<32; i++)
|
||||
printf("%02x",((uint8_t *)&txid)[i]);
|
||||
printf(" <- txid.v%u ",vout);
|
||||
for (i=0; i<33; i++)
|
||||
printf("%02x",pubkey33[i]);
|
||||
printf(" checkpubkey check %.8f v %.8f dest.(%s) kmdheight.%d height.%d\n",dstr(checktoshis),dstr(value),destaddr,kmdheight,height);
|
||||
if ( value >= checktoshis-(checktoshis >> 10) )
|
||||
if ( (pax= komodo_paxfind(txid,vout,'D')) == 0 )
|
||||
{
|
||||
if ( komodo_paxfind(txid,vout) == 0 )
|
||||
if ( (basesp= komodo_stateptrget(base)) != 0 )
|
||||
{
|
||||
komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,kmdheight,height,(char *)"KMD",0);
|
||||
} else printf("duplicate deposit\n");
|
||||
basesp->deposited += fiatoshis;
|
||||
didstats = 1;
|
||||
if ( strcmp(base,ASSETCHAINS_SYMBOL) == 0 )
|
||||
printf("########### %p deposited %s += %.8f\n",basesp,base,dstr(fiatoshis));
|
||||
}
|
||||
komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,'D',kmdheight,height,(char *)"KMD",0);
|
||||
}
|
||||
if ( (pax= komodo_paxfind(txid,vout,'D')) != 0 )
|
||||
{
|
||||
if ( didstats == 0 && pax->didstats == 0 )
|
||||
{
|
||||
if ( (basesp= komodo_stateptrget(base)) != 0 )
|
||||
{
|
||||
basesp->deposited += fiatoshis;
|
||||
didstats = 1;
|
||||
if ( strcmp(base,ASSETCHAINS_SYMBOL) == 0 )
|
||||
printf("########### %p deposited %s += %.8f\n",basesp,base,dstr(fiatoshis));
|
||||
}
|
||||
}
|
||||
if ( didstats != 0 )
|
||||
pax->didstats = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -474,19 +601,33 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
|
||||
bitcoin_address(coinaddr,addrtype,rmd160,20);
|
||||
checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,value);
|
||||
typestr = "withdraw";
|
||||
printf("%s.height.%d vs height.%d check %.8f/%.8f vs %.8f tokomodo.%d %d seed.%llx -> (%s)\n",ASSETCHAINS_SYMBOL,kmdheight,height,dstr(checktoshis),dstr(komodoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0,(long long)seed,coinaddr);
|
||||
if ( checktoshis <= komodoshis+(komodoshis >> 10) )
|
||||
//printf("%s.height.%d vs height.%d check %.8f/%.8f vs %.8f tokomodo.%d %d seed.%llx -> (%s)\n",ASSETCHAINS_SYMBOL,kmdheight,height,dstr(checktoshis),dstr(komodoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0,(long long)seed,coinaddr);
|
||||
didstats = 0;
|
||||
if ( komodo_paxcmp(kmdheight,komodoshis,checktoshis,seed) == 0 )
|
||||
{
|
||||
if ( (pax= komodo_paxfind(txid,vout)) == 0 )
|
||||
if ( value != 0 && ((pax= komodo_paxfind(txid,vout,'W')) == 0 || pax->didstats == 0) )
|
||||
{
|
||||
printf("notarize %s %.8f -> %.8f kmd.%d other.%d\n",ASSETCHAINS_SYMBOL,dstr(value),dstr(komodoshis),kmdheight,height);
|
||||
if ( (basesp= komodo_stateptrget(base)) != 0 )
|
||||
{
|
||||
basesp->withdrawn += value;
|
||||
didstats = 1;
|
||||
if ( strcmp(base,ASSETCHAINS_SYMBOL) == 0 )
|
||||
printf("########### %p withdrawn %s += %.8f\n",basesp,base,dstr(value));
|
||||
}
|
||||
//printf("notarize %s %.8f -> %.8f kmd.%d other.%d\n",ASSETCHAINS_SYMBOL,dstr(value),dstr(komodoshis),kmdheight,height);
|
||||
}
|
||||
komodo_gateway_deposit(coinaddr,komodoshis,(char *)"KMD",value,rmd160,txid,vout,'W',kmdheight,height,source,0);
|
||||
if ( (pax= komodo_paxfind(txid,vout,'W')) != 0 )
|
||||
{
|
||||
if ( didstats != 0 )
|
||||
pax->didstats = 1;
|
||||
pax->type = opretbuf[0];
|
||||
}
|
||||
komodo_gateway_deposit(coinaddr,komodoshis,(char *)"KMD",value,rmd160,txid,vout,kmdheight,height,source,0);
|
||||
}
|
||||
}
|
||||
else if ( tokomodo != 0 && opretbuf[0] == 'A' )
|
||||
{
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
{
|
||||
for (i=0; i<opretlen; i++)
|
||||
printf("%02x",opretbuf[i]);
|
||||
@@ -498,28 +639,52 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
|
||||
{
|
||||
if ( baseids[i] < 0 )
|
||||
continue;
|
||||
didstats = 0;
|
||||
seed = 0;
|
||||
checktoshis = komodo_paxprice(&seed,kmdheights[i],CURRENCIES[baseids[i]],(char *)"KMD",(uint64_t)srcvalues[i]);
|
||||
printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",kmdheights[i],CURRENCIES[baseids[i]],(double)srcvalues[i]/COIN,(double)values[i]/COIN,(double)checktoshis/COIN);
|
||||
/*printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",kmdheights[i],CURRENCIES[baseids[i]],(double)srcvalues[i]/COIN,(double)values[i]/COIN,(double)checktoshis/COIN);
|
||||
for (j=0; j<32; j++)
|
||||
printf("%02x",((uint8_t *)&txids[i])[j]);
|
||||
printf(" v%d %.8f k.%d ht.%d base.%d\n",vouts[i],dstr(values[i]),kmdheights[i],otherheights[i],baseids[i]);
|
||||
if ( (pax= komodo_paxfind(txids[i],vouts[i])) == 0 )
|
||||
printf(" v%d %.8f k.%d ht.%d base.%d\n",vouts[i],dstr(values[i]),kmdheights[i],otherheights[i],baseids[i]);*/
|
||||
if ( (pax= komodo_paxfind(txids[i],vouts[i],'A')) == 0 )
|
||||
{
|
||||
bitcoin_address(coinaddr,60,&rmd160s[i*20],20);
|
||||
komodo_gateway_deposit(coinaddr,values[i],CURRENCIES[baseids[i]],srcvalues[i],&rmd160s[i*20],txids[i],vouts[i],kmdheights[i],otherheights[i],CURRENCIES[baseids[i]],kmdheights[i]);
|
||||
printf(" i.%d (%s) <- %.8f\n",i,coinaddr,dstr(values[i]));
|
||||
} else printf(" i.%d of n.%d pax.%p baseids[] %d\n",i,n,pax,baseids[i]);
|
||||
if ( (pax= komodo_paxfind(txids[i],vouts[i])) != 0 )
|
||||
komodo_gateway_deposit(coinaddr,values[i],CURRENCIES[baseids[i]],srcvalues[i],&rmd160s[i*20],txids[i],vouts[i],'A',kmdheights[i],otherheights[i],CURRENCIES[baseids[i]],kmdheights[i]);
|
||||
komodo_paxmark(height,txids[i],vouts[i],'W',height);
|
||||
komodo_paxmark(height,txids[i],vouts[i],'A',height);
|
||||
if ( srcvalues[i] != 0 && (basesp= komodo_stateptrget(CURRENCIES[baseids[i]])) != 0 )
|
||||
{
|
||||
basesp->approved += srcvalues[i];
|
||||
didstats = 1;
|
||||
if ( strcmp(CURRENCIES[baseids[i]],ASSETCHAINS_SYMBOL) == 0 )
|
||||
printf("########### %p approved %s += %.8f\n",basesp,CURRENCIES[baseids[i]],dstr(srcvalues[i]));
|
||||
}
|
||||
//printf(" i.%d (%s) <- %.8f ADDFLAG APPROVED\n",i,coinaddr,dstr(values[i]));
|
||||
}
|
||||
else if ( pax->didstats == 0 && srcvalues[i] != 0 )
|
||||
{
|
||||
if ( (basesp= komodo_stateptrget(CURRENCIES[baseids[i]])) != 0 )
|
||||
{
|
||||
basesp->approved += srcvalues[i];
|
||||
didstats = 1;
|
||||
if ( strcmp(CURRENCIES[baseids[i]],ASSETCHAINS_SYMBOL) == 0 )
|
||||
printf("########### %p approved %s += %.8f\n",basesp,CURRENCIES[baseids[i]],dstr(srcvalues[i]));
|
||||
}
|
||||
} //else printf(" i.%d of n.%d pax.%p baseids[] %d\n",i,n,pax,baseids[i]);
|
||||
if ( (pax= komodo_paxfind(txids[i],vouts[i],'A')) != 0 )
|
||||
{
|
||||
pax->type = opretbuf[0];
|
||||
pax->approved = kmdheights[i];
|
||||
printf(" i.%d approved.%d <<<<<<<<<<<<< APPROVED %p\n",i,kmdheights[i],pax);
|
||||
if ( didstats != 0 )
|
||||
pax->didstats = 1;
|
||||
if ( strcmp(CURRENCIES[baseids[i]],ASSETCHAINS_SYMBOL) == 0 )
|
||||
printf(" i.%d approved.%d <<<<<<<<<<<<< APPROVED %p\n",i,kmdheights[i],pax);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("extra.[%d] after %.8f\n",n,dstr(komodo_paxtotal()));
|
||||
//printf("extra.[%d] after %.8f\n",n,dstr(komodo_paxtotal()));
|
||||
}
|
||||
else if ( tokomodo == 0 && opretbuf[0] == 'I' )
|
||||
else if ( opretbuf[0] == 'I' )
|
||||
{
|
||||
if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 )
|
||||
{
|
||||
@@ -527,26 +692,50 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
|
||||
{
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
if ( baseids[i] < 0 )
|
||||
{
|
||||
printf("%d of %d illegal baseid.%d\n",i,n,baseids[i]);
|
||||
continue;
|
||||
}
|
||||
bitcoin_address(coinaddr,60,&rmd160s[i*20],20);
|
||||
if ( komodo_paxmark(height,txids[i],vouts[i],height) == 0 && baseids[i] >= 0 )
|
||||
komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],height,0,CURRENCIES[baseids[i]],0);
|
||||
komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],'I',height,0,CURRENCIES[baseids[i]],0);
|
||||
komodo_paxmark(height,txids[i],vouts[i],'D',height);
|
||||
komodo_paxmark(height,txids[i],vouts[i],'I',height);
|
||||
if ( (pax= komodo_paxfind(txids[i],vouts[i],'I')) != 0 )
|
||||
{
|
||||
pax->type = opretbuf[0];
|
||||
strcpy(pax->source,(char *)&opretbuf[opretlen-4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} //else printf("opreturn none issued?\n");
|
||||
} //else printf("opreturn matches KMD? %s\n",(char *)&opretbuf[opretlen-4]);
|
||||
}
|
||||
else if ( opretbuf[0] == 'X' )
|
||||
{
|
||||
printf("got X opreturn height.%d\n",height);
|
||||
if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,1)) > 0 )
|
||||
{
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
if ( baseids[i] < 0 )
|
||||
continue;
|
||||
bitcoin_address(coinaddr,60,&rmd160s[i*20],20);
|
||||
printf("i.%d of %d: %.8f -> %s\n",i,n,dstr(values[i]),coinaddr);
|
||||
if ( komodo_paxmark(height,txids[i],vouts[i],height) == 0 )
|
||||
komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],height,0,(char *)"KMD",0);
|
||||
komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],'X',height,0,(char *)"KMD",0);
|
||||
komodo_paxmark(height,txids[i],vouts[i],'W',height);
|
||||
komodo_paxmark(height,txids[i],vouts[i],'A',height);
|
||||
komodo_paxmark(height,txids[i],vouts[i],'X',height);
|
||||
if ( (pax= komodo_paxfind(txids[i],vouts[i],'X')) != 0 )
|
||||
{
|
||||
pax->type = opretbuf[0];
|
||||
if ( baseids[i] >= 0 && srcvalues[i] != 0 && (basesp= komodo_stateptrget(CURRENCIES[baseids[i]])) != 0 )
|
||||
{
|
||||
basesp->redeemed += srcvalues[i];
|
||||
pax->didstats = 1;
|
||||
if ( strcmp(CURRENCIES[baseids[i]],ASSETCHAINS_SYMBOL) == 0 )
|
||||
printf("########### %p redeemed %s += %.8f\n",basesp,CURRENCIES[baseids[i]],dstr(srcvalues[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else printf("komodo_issued_opreturn returned %d\n",n);
|
||||
} //else printf("komodo_issued_opreturn returned %d\n",n);
|
||||
}
|
||||
return(typestr);
|
||||
}
|
||||
@@ -565,7 +754,7 @@ void komodo_passport_iteration()
|
||||
refid = 33;
|
||||
else refid = komodo_baseid(ASSETCHAINS_SYMBOL)+1; // illegal base -> baseid.-1 -> 0
|
||||
//printf("PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,refid);
|
||||
for (baseid=0; baseid<=32; baseid++)
|
||||
for (baseid=32; baseid>=0; baseid--)
|
||||
{
|
||||
sp = 0;
|
||||
isrealtime = 0;
|
||||
@@ -574,18 +763,19 @@ void komodo_passport_iteration()
|
||||
{
|
||||
komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"komodostate");
|
||||
komodo_nameset(symbol,dest,base);
|
||||
//port = komodo_port(base,10,&magic) + 1;
|
||||
if ( (fp= fopen(fname,"rb")) != 0 && (sp= komodo_stateptrget(symbol)) != 0 )
|
||||
{
|
||||
fseek(fp,0,SEEK_END);
|
||||
if ( ftell(fp) > lastpos[baseid] )
|
||||
{
|
||||
//printf("passport refid.%d %s fname.(%s) base.%s\n",refid,symbol,fname,base);
|
||||
if ( 0 && lastpos[baseid] == 0 && strcmp(symbol,"KMD") == 0 )
|
||||
printf("passport refid.%d %s fname.(%s) base.%s\n",refid,symbol,fname,base);
|
||||
fseek(fp,lastpos[baseid],SEEK_SET);
|
||||
while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 )
|
||||
;
|
||||
lastpos[baseid] = ftell(fp);
|
||||
//printf("from.(%s) lastpos[%s] %ld\n",ASSETCHAINS_SYMBOL,CURRENCIES[baseid],lastpos[baseid]);
|
||||
if ( 0 && lastpos[baseid] == 0 && strcmp(symbol,"KMD") == 0 )
|
||||
printf("from.(%s) lastpos[%s] %ld\n",ASSETCHAINS_SYMBOL,CURRENCIES[baseid],lastpos[baseid]);
|
||||
} //else fprintf(stderr,"%s.%ld ",CURRENCIES[baseid],ftell(fp));
|
||||
fclose(fp);
|
||||
}
|
||||
@@ -603,7 +793,7 @@ void komodo_passport_iteration()
|
||||
} //else fprintf(stderr,"%s not RT\n",base);
|
||||
} //else fprintf(stderr,"%s size error RT\n",base);
|
||||
fclose(fp);
|
||||
} else fprintf(stderr,"%s open error RT\n",base);
|
||||
} //else fprintf(stderr,"%s open error RT\n",base);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -628,6 +818,7 @@ void komodo_passport_iteration()
|
||||
if ( sp != 0 && isrealtime == 0 )
|
||||
refsp->RTbufs[0][2] = 0;
|
||||
}
|
||||
komodo_paxtotal();
|
||||
refsp->RTmask = RTmask;
|
||||
KOMODO_PASSPORT_INITDONE = 1;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num)
|
||||
height /= KOMODO_ELECTION_GAP;
|
||||
height = ((height + 1) * KOMODO_ELECTION_GAP);
|
||||
htind = (height / KOMODO_ELECTION_GAP);
|
||||
printf("htind.%d activation %d from %d vs %d | hwmheight.%d\n",htind,height,origheight,(((origheight+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,hwmheight);
|
||||
printf("htind.%d activation %d from %d vs %d | hwmheight.%d %s\n",htind,height,origheight,(((origheight+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,hwmheight,ASSETCHAINS_SYMBOL);
|
||||
} else htind = 0;
|
||||
pthread_mutex_lock(&komodo_mutex);
|
||||
for (k=0; k<num; k++)
|
||||
@@ -108,7 +108,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num)
|
||||
memcpy(kp->pubkey,pubkeys[k],33);
|
||||
kp->notaryid = k;
|
||||
HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp);
|
||||
if ( height > 10000 )
|
||||
if ( 0 && height > 10000 )
|
||||
{
|
||||
for (i=0; i<33; i++)
|
||||
printf("%02x",pubkeys[k][i]);
|
||||
|
||||
194
src/komodo_pax.h
194
src/komodo_pax.h
@@ -94,6 +94,17 @@ uint64_t peggy_smooth_coeffs[sizeof(Peggy_inds)/sizeof(*Peggy_inds)] = // numpri
|
||||
1, 1, 1, 1, 1, 1, 0, 0, // isum 100000000000
|
||||
};
|
||||
|
||||
uint64_t komodo_maxallowed(int32_t baseid)
|
||||
{
|
||||
uint64_t mult,val = COIN * (uint64_t)10000;
|
||||
if ( baseid < 0 || baseid >= 32 )
|
||||
return(0);
|
||||
if ( baseid < 10 )
|
||||
val *= 4;
|
||||
mult = MINDENOMS[baseid] / MIND;
|
||||
return(mult * val);
|
||||
}
|
||||
|
||||
uint64_t komodo_paxvol(uint64_t volume,uint64_t price)
|
||||
{
|
||||
if ( volume < 10000000000 )
|
||||
@@ -297,10 +308,72 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals)
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t basevolume)
|
||||
uint64_t komodo_paxcorrelation(uint64_t *votes,int32_t numvotes,uint64_t seed)
|
||||
{
|
||||
uint32_t pvalb,pvalr,kmdbtc,btcusd; uint64_t usdvol,baseusd,usdkmd,baserel,ranked[32];
|
||||
if ( basevolume > 10000*COIN )
|
||||
int32_t i,j,k,ind,zeroes,wt,nonz; int64_t delta; uint64_t lastprice,tolerance,den,densum,sum=0;
|
||||
for (sum=i=zeroes=nonz=0; i<numvotes; i++)
|
||||
{
|
||||
if ( votes[i] == 0 )
|
||||
zeroes++;
|
||||
else sum += votes[i], nonz++;
|
||||
}
|
||||
if ( nonz < (numvotes >> 2) )
|
||||
return(0);
|
||||
sum /= nonz;
|
||||
lastprice = sum;
|
||||
for (i=0; i<numvotes; i++)
|
||||
{
|
||||
if ( votes[i] == 0 )
|
||||
votes[i] = lastprice;
|
||||
else lastprice = votes[i];
|
||||
}
|
||||
tolerance = sum / 50;
|
||||
for (k=0; k<numvotes; k++)
|
||||
{
|
||||
ind = Peggy_inds[(k + seed) % numvotes];
|
||||
i = (int32_t)(ind % numvotes);
|
||||
wt = 0;
|
||||
if ( votes[i] != 0 )
|
||||
{
|
||||
for (j=0; j<numvotes; j++)
|
||||
{
|
||||
if ( votes[j] != 0 )
|
||||
{
|
||||
if ( (delta= (votes[i] - votes[j])) < 0 )
|
||||
delta = -delta;
|
||||
if ( delta <= tolerance )
|
||||
{
|
||||
wt++;
|
||||
if ( wt > (numvotes >> 1) )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( wt > (numvotes >> 1) )
|
||||
{
|
||||
ind = i;
|
||||
for (densum=sum=j=0; j<numvotes; j++)
|
||||
{
|
||||
den = peggy_smooth_coeffs[j];
|
||||
densum += den;
|
||||
sum += (den * votes[(ind + j) % numvotes]);
|
||||
//printf("(%llu/%llu %.8f) ",(long long)sum,(long long)densum,(double)sum/densum);
|
||||
}
|
||||
if ( densum != 0 )
|
||||
sum /= densum;
|
||||
//sum = (sum * basevolume);
|
||||
//printf("paxprice seed.%llx sum %.8f densum %.8f\n",(long long)seed,dstr(sum),dstr(densum));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(sum);
|
||||
}
|
||||
|
||||
uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t basevolume,uint64_t kmdbtc,uint64_t btcusd)
|
||||
{
|
||||
uint32_t pvalb,pvalr; uint64_t usdvol,baseusd,usdkmd,baserel,ranked[32];
|
||||
if ( basevolume > KOMODO_PAXMAX )
|
||||
{
|
||||
printf("paxcalc overflow %.8f\n",dstr(basevolume));
|
||||
return(0);
|
||||
@@ -309,16 +382,20 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba
|
||||
{
|
||||
if ( relid == MAX_CURRENCIES )
|
||||
{
|
||||
kmdbtc = pvals[MAX_CURRENCIES];
|
||||
btcusd = pvals[MAX_CURRENCIES + 1];
|
||||
if ( kmdbtc == 0 )
|
||||
kmdbtc = pvals[MAX_CURRENCIES];
|
||||
if ( btcusd == 0 )
|
||||
btcusd = pvals[MAX_CURRENCIES + 1];
|
||||
if ( kmdbtc < 25000000 )
|
||||
kmdbtc = 25000000;
|
||||
if ( pvals[USD] != 0 && kmdbtc != 0 && btcusd != 0 )
|
||||
{
|
||||
baseusd = ((uint64_t)pvalb * 1000000000) / pvals[USD];
|
||||
usdvol = komodo_paxvol(basevolume,baseusd) / MINDENOMS[baseid];
|
||||
usdkmd = ((uint64_t)btcusd * 1000000000) / kmdbtc;
|
||||
//printf("base -> USD %llu, BTC %llu KMDUSD %llu\n",(long long)baseusd,(long long)btcusd,(long long)kmdusd);
|
||||
baseusd = (((uint64_t)pvalb * 1000000000) / pvals[USD]);
|
||||
usdvol = komodo_paxvol(basevolume,baseusd);
|
||||
usdkmd = ((uint64_t)kmdbtc * 1000000000) / btcusd;
|
||||
//printf("kmdbtc.%llu btcusd.%llu base -> USD %llu, usdkmd %llu usdvol %llu -> %llu\n",(long long)kmdbtc,(long long)btcusd,(long long)baseusd,(long long)usdkmd,(long long)usdvol,(long long)(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd) / (MINDENOMS[baseid]/100)));
|
||||
//printf("usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %.8f\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,dstr(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd)));
|
||||
return(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd));
|
||||
return(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd) / (MINDENOMS[baseid]/100));
|
||||
} //else printf("zero val in KMD conv %llu %llu %llu\n",(long long)pvals[USD],(long long)kmdbtc,(long long)btcusd);
|
||||
}
|
||||
else if ( baseid == relid )
|
||||
@@ -345,7 +422,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba
|
||||
return(0);
|
||||
}
|
||||
|
||||
uint64_t _komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume)
|
||||
uint64_t _komodo_paxprice(uint64_t *kmdbtcp,uint64_t *btcusdp,int32_t height,char *base,char *rel,uint64_t basevolume,uint64_t kmdbtc,uint64_t btcusd)
|
||||
{
|
||||
int32_t baseid=-1,relid=-1,i; uint32_t *ptr;
|
||||
if ( height > 10 )
|
||||
@@ -356,7 +433,16 @@ uint64_t _komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolum
|
||||
{
|
||||
ptr = &PVALS[36 * i];
|
||||
if ( *ptr < height )
|
||||
return(komodo_paxcalc(&ptr[1],baseid,relid,basevolume));
|
||||
{
|
||||
if ( kmdbtcp != 0 && btcusdp != 0 )
|
||||
{
|
||||
*kmdbtcp = ptr[MAX_CURRENCIES + 1] / 539;
|
||||
*btcusdp = ptr[MAX_CURRENCIES + 2] / 539;
|
||||
}
|
||||
if ( kmdbtc != 0 && btcusd != 0 )
|
||||
return(komodo_paxcalc(&ptr[1],baseid,relid,basevolume,kmdbtc,btcusd));
|
||||
else return(0);
|
||||
}
|
||||
}
|
||||
} else printf("paxprice invalid base.%s %d, rel.%s %d\n",base,baseid,rel,relid);
|
||||
return(0);
|
||||
@@ -364,75 +450,39 @@ uint64_t _komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolum
|
||||
|
||||
uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume)
|
||||
{
|
||||
int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,seed,tolerance,den,densum,sum=0,votes[539];
|
||||
if ( basevolume > 10000*COIN )
|
||||
int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,seed,tolerance,den,densum,sum=0,votes[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],btcusds[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtcs[sizeof(Peggy_inds)/sizeof(*Peggy_inds)],kmdbtc,btcusd;
|
||||
if ( basevolume > KOMODO_PAXMAX )
|
||||
{
|
||||
printf("komodo_paxprice overflow %.8f\n",dstr(basevolume));
|
||||
return(0);
|
||||
}
|
||||
if ( strcmp(base,"KMD") == 0 || strcmp(base,"kmd") == 0 )
|
||||
{
|
||||
printf("kmd cannot be base currency\n");
|
||||
return(0);
|
||||
}
|
||||
numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds));
|
||||
memset(votes,0,sizeof(votes));
|
||||
for (sum=i=zeroes=nonz=0; i<numvotes; i++)
|
||||
memset(btcusds,0,sizeof(btcusds));
|
||||
memset(kmdbtcs,0,sizeof(kmdbtcs));
|
||||
for (i=0; i<numvotes; i++)
|
||||
{
|
||||
if ( (votes[numvotes-1-i]= _komodo_paxprice(height-i,base,rel,100000)) == 0 )
|
||||
{
|
||||
_komodo_paxprice(&kmdbtcs[numvotes-1-i],&btcusds[numvotes-1-i],height-i,base,rel,100000,0,0);
|
||||
//printf("(%llu %llu) ",(long long)kmdbtcs[numvotes-1-i],(long long)btcusds[numvotes-1-i]);
|
||||
}
|
||||
*seedp = seed = komodo_seed(height);
|
||||
kmdbtc = komodo_paxcorrelation(kmdbtcs,numvotes,seed) * 539;
|
||||
btcusd = komodo_paxcorrelation(btcusds,numvotes,seed) * 539;
|
||||
//printf("kmdbtc %llu btcusd %llu\n",(long long)kmdbtc,(long long)btcusd);
|
||||
for (i=nonz=0; i<numvotes; i++)
|
||||
{
|
||||
if ( (votes[numvotes-1-i]= _komodo_paxprice(0,0,height-i,base,rel,100000,kmdbtc,btcusd)) == 0 )
|
||||
zeroes++;
|
||||
//printf("null price height.%d\n",height-i);
|
||||
//return(0);
|
||||
} else sum += votes[i], nonz++;
|
||||
//printf("%.8f, ",dstr(votes[i]));
|
||||
else nonz++;
|
||||
}
|
||||
if ( nonz <= (numvotes >> 1) )
|
||||
return(0);
|
||||
sum /= nonz;
|
||||
lastprice = sum;
|
||||
for (i=0; i<numvotes; i++)
|
||||
{
|
||||
if ( votes[i] == 0 )
|
||||
votes[i] = lastprice;
|
||||
else lastprice = votes[i];
|
||||
}
|
||||
//printf("\n}; // numvotes.%d\n\n",numvotes);
|
||||
*seedp = seed = komodo_seed(height);
|
||||
tolerance = sum / 50;
|
||||
for (k=0; k<numvotes; k++)
|
||||
{
|
||||
ind = Peggy_inds[(k + seed) % numvotes];
|
||||
i = (int32_t)(ind % numvotes);
|
||||
wt = 0;
|
||||
if ( votes[i] != 0 )
|
||||
{
|
||||
for (j=0; j<numvotes; j++)
|
||||
{
|
||||
if ( votes[j] != 0 )
|
||||
{
|
||||
if ( (delta= (votes[i] - votes[j])) < 0 )
|
||||
delta = -delta;
|
||||
if ( delta <= tolerance )
|
||||
{
|
||||
wt++;
|
||||
if ( wt > (numvotes >> 1) )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( wt > (numvotes >> 1) )
|
||||
{
|
||||
ind = i;
|
||||
for (densum=sum=j=0; j<numvotes; j++)
|
||||
{
|
||||
den = peggy_smooth_coeffs[j];
|
||||
densum += den;
|
||||
sum += (den * votes[(ind + j) % numvotes]);
|
||||
}
|
||||
sum /= densum;
|
||||
sum = (sum * basevolume) / 100000;
|
||||
printf("paxprice seed.%llx sum %.8f densum %.8f basevol %.8f height.%d\n",(long long)seed,dstr(sum),dstr(densum),dstr(basevolume),height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(sum);
|
||||
return(komodo_paxcorrelation(votes,numvotes,seed) * basevolume / 100000);
|
||||
}
|
||||
|
||||
int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel)
|
||||
@@ -444,7 +494,7 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas
|
||||
{
|
||||
ptr = &PVALS[36 * i];
|
||||
heights[num] = *ptr;
|
||||
prices[num] = komodo_paxcalc(&ptr[1],baseid,relid,COIN);
|
||||
prices[num] = komodo_paxcalc(&ptr[1],baseid,relid,COIN,0,0);
|
||||
num++;
|
||||
if ( num >= max )
|
||||
return(num);
|
||||
@@ -473,7 +523,7 @@ uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pu
|
||||
if ( fiatoshis < 0 )
|
||||
shortflag = 1, fiatoshis = -fiatoshis;
|
||||
komodoshis = komodo_paxprice(seedp,height,base,(char *)"KMD",(uint64_t)fiatoshis);
|
||||
printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f\n",height,base,(double)fiatoshis/COIN,(double)komodoshis/COIN);
|
||||
//printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f\n",height,base,(double)fiatoshis/COIN,(double)komodoshis/COIN);
|
||||
if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) == 20 )
|
||||
{
|
||||
PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,tokomodo != 0 ? &komodoshis : &fiatoshis);
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#endif*/
|
||||
|
||||
#define GENESIS_NBITS 0x1f00ffff
|
||||
#define KOMODO_MINRATIFY ((height < 90000) ? 7 : 13)
|
||||
#define KOMODO_MINRATIFY ((height < 90000) ? 7 : 11)
|
||||
#define KOMODO_MAXBLOCKS 5000000
|
||||
|
||||
#define KOMODO_EVENT_RATIFY 'P'
|
||||
@@ -57,12 +57,11 @@ struct pax_transaction
|
||||
UT_hash_handle hh;
|
||||
uint256 txid;
|
||||
uint64_t komodoshis,fiatoshis,validated;
|
||||
int32_t marked,height,otherheight,approved;
|
||||
int32_t marked,height,otherheight,approved,didstats;
|
||||
uint16_t vout;
|
||||
char symbol[16],source[16],coinaddr[64]; uint8_t rmd160[20],shortflag;
|
||||
char symbol[16],source[16],coinaddr[64]; uint8_t rmd160[20],type,buf[35];
|
||||
};
|
||||
|
||||
//struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; };
|
||||
struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; };
|
||||
struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; };
|
||||
struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t nHeight,notarized_height; };
|
||||
@@ -72,6 +71,7 @@ struct komodo_state
|
||||
uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID;
|
||||
int32_t SAVEDHEIGHT,CURRENT_HEIGHT,NOTARIZED_HEIGHT;
|
||||
uint32_t SAVEDTIMESTAMP;
|
||||
uint64_t deposited,issued,withdrawn,approved,redeemed,shorted;
|
||||
struct notarized_checkpoint *NPOINTS; int32_t NUM_NPOINTS;
|
||||
struct komodo_event **Komodo_events; int32_t Komodo_numevents;
|
||||
uint32_t RTbufs[64][3]; uint64_t RTmask;
|
||||
|
||||
@@ -534,7 +534,7 @@ void static BitcoinMiner(CWallet *pwallet)
|
||||
else solver = "default";
|
||||
assert(solver == "tromp" || solver == "default");
|
||||
LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k);
|
||||
fprintf(stderr,"Mining with %s\n",solver.c_str());
|
||||
//fprintf(stderr,"Mining with %s\n",solver.c_str());
|
||||
std::mutex m_cs;
|
||||
bool cancelSolver = false;
|
||||
boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
|
||||
@@ -584,7 +584,7 @@ void static BitcoinMiner(CWallet *pwallet)
|
||||
Mining_height = pindexPrev->nHeight+1;
|
||||
Mining_start = (uint32_t)time(NULL);
|
||||
}
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
fprintf(stderr,"%s create new block ht.%d\n",ASSETCHAINS_SYMBOL,Mining_height);
|
||||
|
||||
unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey));
|
||||
@@ -647,9 +647,9 @@ void static BitcoinMiner(CWallet *pwallet)
|
||||
int32_t nseconds = Mining_start+ROUNDROBIN_DELAY-time(NULL);
|
||||
if ( nseconds > 0 )
|
||||
sleep(nseconds);
|
||||
MilliSleep((rand() % 2000) + 1);
|
||||
KOMODO_CHOSEN_ONE = 1;
|
||||
MilliSleep((rand() % 5000) + 1);
|
||||
}
|
||||
KOMODO_CHOSEN_ONE = 1;
|
||||
// Found a solution
|
||||
SetThreadPriority(THREAD_PRIORITY_NORMAL);
|
||||
LogPrintf("KomodoMiner:\n");
|
||||
|
||||
@@ -481,16 +481,37 @@ Value notaries(const Array& params, bool fHelp)
|
||||
}
|
||||
|
||||
int32_t komodo_pending_withdraws(char *opretstr);
|
||||
int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base);
|
||||
extern char CURRENCIES[][8];
|
||||
|
||||
Value paxpending(const Array& params, bool fHelp)
|
||||
{
|
||||
Object ret; char opretbuf[10000*2]; int32_t opretlen;
|
||||
Object ret; Array a; char opretbuf[10000*2]; int32_t opretlen,baseid; uint64_t available,deposited,issued,withdrawn,approved,redeemed;
|
||||
if ( fHelp || params.size() != 0 )
|
||||
throw runtime_error("paxpending needs no args\n");
|
||||
LOCK(cs_main);
|
||||
if ( (opretlen= komodo_pending_withdraws(opretbuf)) > 0 )
|
||||
ret.push_back(Pair("withdraws", opretbuf));
|
||||
else ret.push_back(Pair("withdraws", (char *)""));
|
||||
for (baseid=0; baseid<32; baseid++)
|
||||
{
|
||||
Object item,obj;
|
||||
if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,CURRENCIES[baseid]) == 0 )
|
||||
{
|
||||
if ( deposited != 0 || issued != 0 || withdrawn != 0 || approved != 0 || redeemed != 0 )
|
||||
{
|
||||
item.push_back(Pair("available", ValueFromAmount(available)));
|
||||
item.push_back(Pair("deposited", ValueFromAmount(deposited)));
|
||||
item.push_back(Pair("issued", ValueFromAmount(issued)));
|
||||
item.push_back(Pair("withdrawn", ValueFromAmount(withdrawn)));
|
||||
item.push_back(Pair("approved", ValueFromAmount(approved)));
|
||||
item.push_back(Pair("redeemed", ValueFromAmount(redeemed)));
|
||||
obj.push_back(Pair(CURRENCIES[baseid],item));
|
||||
a.push_back(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
ret.push_back(Pair("fiatstatus", a));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn)
|
||||
TryCreateDirectory(pathLogDir);
|
||||
boost::filesystem::path pathErrorFile = pathIn / "db.log";
|
||||
LogPrintf("CDBEnv::Open: LogDir=%s ErrorFile=%s pathIn.(%s)\n", pathLogDir.string(), pathErrorFile.string(),pathIn.string());
|
||||
fprintf(stderr,"strPath.(%s)\n",strPath.c_str());
|
||||
//fprintf(stderr,"strPath.(%s)\n",strPath.c_str());
|
||||
|
||||
unsigned int nEnvFlags = 0;
|
||||
if (GetBoolArg("-privdb", true))
|
||||
|
||||
@@ -482,10 +482,11 @@ extern char ASSETCHAINS_SYMBOL[16];
|
||||
int32_t komodo_is_issuer();
|
||||
int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
|
||||
int32_t komodo_isrealtime(int32_t *kmdheightp);
|
||||
int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base);
|
||||
|
||||
Value paxdeposit(const Array& params, bool fHelp)
|
||||
{
|
||||
uint64_t seed,komodoshis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33];
|
||||
uint64_t available,deposited,issued,withdrawn,approved,redeemed,seed,komodoshis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33];
|
||||
bool fSubtractFeeFromAmount = false;
|
||||
if ( komodo_is_issuer() != 0 )
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KMD");
|
||||
@@ -501,6 +502,8 @@ Value paxdeposit(const Array& params, bool fHelp)
|
||||
std::string base = params[2].get_str();
|
||||
std::string dest;
|
||||
height = chainActive.Tip()->nHeight;
|
||||
if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,(char *)base.c_str()) != 0 || available < fiatoshis )
|
||||
throw runtime_error("paxdeposit not enough available inventory");
|
||||
komodoshis = PAX_fiatdest(&seed,0,destaddr,pubkey37,(char *)params[0].get_str().c_str(),height,(char *)base.c_str(),fiatoshis);
|
||||
dest.append(destaddr);
|
||||
CBitcoinAddress destaddress(CRYPTO777_KMDADDR);
|
||||
|
||||
Reference in New Issue
Block a user