@ -280,7 +280,7 @@ struct peggy *peggy_createpair(struct peggy_info *PEGS,int64_t quorum,int64_t de
return ( PEG ) ;
}
struct peggy_info * peggy_init ( char * path , int32_t maxdays , char * maincurrency , uint64_t maincurrencyunitsize , uint64_t quorum , uint64_t decisionthreshold , struct price_resolution spread , uint32_t dailyrate , int32_t interesttenths , int32_t posboost , int32_t negpenalty , int32_t feediv , int32_t feemult , uint32_t firsttimestamp , uint32_t BTCD_price0 )
struct peggy_info * peggy_init ( int32_t maxdays , char * maincurrency , uint64_t maincurrencyunitsize , uint64_t quorum , uint64_t decisionthreshold , struct price_resolution spread , uint32_t dailyrate , int32_t interesttenths , int32_t posboost , int32_t negpenalty , int32_t feediv , int32_t feemult , uint32_t firsttimestamp , uint32_t BTCD_price0 )
{
//struct peggy_limits limits = { { PERCENTAGE(10), PERCENTAGE(25), PERCENTAGE(33), PERCENTAGE(50) }, SATOSHIDEN * 10000, SATOSHIDEN * 1000, { 0, 30, 90, 180 }, 4 };
struct peggy_lock default_lockparms = { 7 , 365 , 7 , 0 , 180 , 0 , - 1 } ;
@ -288,7 +288,7 @@ struct peggy_info *peggy_init(char *path,int32_t maxdays,char *maincurrency,uint
//if ( default_limits != 0 )
// limits = *default_limits;
spread . Pval = PERCENTAGE ( 1 ) ;
OS_ensure_directory ( path ) ;
//OS_ensure_directory(path);
strcpy ( PEGS - > maincurrency , maincurrency ) ;
PEGS - > mainbits = stringbits ( maincurrency ) , PEGS - > mainunitsize = maincurrencyunitsize , PEGS - > quorum = quorum , PEGS - > decisionthreshold = decisionthreshold ;
PEGS - > default_lockparms = default_lockparms , PEGS - > default_lockparms . maxlockdays = maxdays ;
@ -324,48 +324,11 @@ long hdecode_varint(uint64_t *valp,uint8_t *ptr,long offset,long mappedsize)
return ( offset ) ;
}
struct peggy_info * peggy_genesis ( int32_t lookbacks [ OPRETURNS_CONTEXTS ] , struct peggy_info * PEGS , char * path , uint32_t firsttimestamp , char * opreturnstr )
void peggy_priceinits ( struct peggy_info * PEGS , uint32_t firsttimestamp , uint32_t * allprices )
{
//struct peggy_limits limits = { { PERCENTAGE(10), PERCENTAGE(25), PERCENTAGE(33), PERCENTAGE(50) }, SATOSHIDEN * 10000, SATOSHIDEN * 1000, { 0, 30, 90, 180 }, 4 };
char name [ 64 ] , base [ 64 ] , rel [ 64 ] ; uint8_t opret [ 1024 ] ; struct peggy_tx Ptx ; struct peggy * PEG ;
struct price_resolution mindenom , spread , price ; uint64_t len ; long offset ; uint64_t maxsupply = 0 , maxnetbalance = 0 ;
int32_t i , c , baseid , relid , peggymils = 0 , signedcount , datalen , n = 0 , maxmargin = 0 , numprices , err = - 1 ; uint32_t pval = 0 ;
numprices = 1 ;
datalen = ( int32_t ) strlen ( opreturnstr ) / 2 ;
decode_hex ( opret , datalen , opreturnstr ) ;
printf ( " peggy_genesis(%s) \n " , opreturnstr ) ;
if ( opret [ 0 ] = = OP_RETURN_OPCODE )
{
offset = hdecode_varint ( & len , opret , 1 , sizeof ( opret ) ) ;
if ( opret [ offset ] = = ' P ' & & opret [ offset + 1 ] = = ' A ' & & opret [ offset + 2 ] = = ' X ' )
{
printf ( " deser \n " ) ;
if ( ( n = serdes777_deserialize ( & signedcount , & Ptx , firsttimestamp , opret + offset + 3 , ( int32_t ) len - 3 ) ) > 0 )
{
err = 0 ;
for ( i = 0 ; i < Ptx . details . price . num ; i + + )
if ( Ptx . details . price . feed [ i ] = = 0 )
break ;
if ( i = = Ptx . details . price . num )
{
printf ( " GENESIS.(%s) \n " , opreturnstr ) ;
for ( i = 0 ; i < Ptx . details . price . num ; i + + )
printf ( " %u " , Ptx . details . price . feed [ i ] ) ;
printf ( " prices \n " ) ;
lookbacks [ 0 ] = 0 , lookbacks [ 1 ] = 1000 ;
if ( PEGS = = 0 )
{
spread . Pval = PERCENTAGE ( 1 ) ;
PEGS = peggy_init ( path , PEGGY_MAXLOCKDAYS , " BTCD " , SATOSHIDEN / 100 , 1 , 1 , spread , PEGGY_RATE_777 , 40 , 10 , 2 , 5 , 2 , Ptx . timestamp , Ptx . details . price . feed [ 0 ] ) ;
//EGS->accts = accts777_init(path,0);
PEGS - > genesis = opreturnstr , opreturnstr = 0 ;
}
} else printf ( " i.%d vs %d \n " , i , Ptx . details . price . num ) ;
} else printf ( " deser got n.%d \n " , n ) ;
} else printf ( " illegal opret.(%c%c%c) \n " , opret [ offset ] , opret [ offset + 1 ] , opret [ offset + 2 ] ) ;
} else printf ( " opret[0] %d \n " , opret [ 0 ] ) ;
if ( err < 0 | | PEGS = = 0 )
return ( 0 ) ;
char name [ 64 ] , base [ 64 ] , rel [ 64 ] ; struct peggy * PEG ;
struct price_resolution mindenom , spread , price ; uint64_t maxsupply = 0 , maxnetbalance = 0 ;
int32_t i , c , baseid , relid , peggymils = 0 , n = 0 , maxmargin = 0 ; uint32_t pval = 0 ;
mindenom . Pval = PRICE_RESOLUTION ;
spread . Pval = PERCENTAGE ( 1 ) ;
for ( i = 1 ; i < sizeof ( peggy_bases ) / sizeof ( * peggy_bases ) + 28 ; i + + )
@ -376,7 +339,7 @@ struct peggy_info *peggy_genesis(int32_t lookbacks[OPRETURNS_CONTEXTS],struct pe
if ( peggy_bases [ i ] = = 0 )
continue ;
peggy_mapname ( base , rel , i ) ;
price . Pval = Ptx . details . price . feed [ i ] ;
price . Pval = all prices [ i ] ;
if ( i < = 8 )
maxmargin = 25 ;
else if ( i < 16 )
@ -391,9 +354,9 @@ struct peggy_info *peggy_genesis(int32_t lookbacks[OPRETURNS_CONTEXTS],struct pe
maxsupply = SATOSHIDEN * 10000 , maxnetbalance = SATOSHIDEN * 1000 ;
if ( strcmp ( base , " BTC " ) = = 0 | | strcmp ( base , " NXT " ) = = 0 | | strcmp ( base , " USD " ) = = 0 | | strcmp ( base , " CNY " ) = = 0 )
maxsupply * = 10 , maxnetbalance * = 10 ;
price . Pval = Ptx . details . price . feed [ i ] ;
price . Pval = all prices [ i ] ;
peggy_mapname ( base , rel , i ) ;
pval = Ptx . details . price . feed [ i ] ;
pval = all prices [ i ] ;
}
else if ( i - sizeof ( peggy_bases ) / sizeof ( * peggy_bases ) < PEGGY_MAXPAIREDPEGS )
{
@ -406,11 +369,11 @@ struct peggy_info *peggy_genesis(int32_t lookbacks[OPRETURNS_CONTEXTS],struct pe
baseid = Contract_base [ c ] + 1 , relid = Contract_rel [ c ] + 1 ;
peggymils = ( PEGS - > contracts [ baseid ] - > peggymils * 10000 ) / PEGS - > contracts [ relid ] - > peggymils ;
if ( strcmp ( PEGS - > contracts [ baseid ] - > name . base , base ) = = 0 & & strcmp ( PEGS - > contracts [ relid ] - > name . base , rel ) = = 0 )
price . Pval = ( PRICE_RESOLUTION * Ptx . details . price . feed [ baseid ] ) / Ptx . details . price . feed [ relid ] ;
price . Pval = ( PRICE_RESOLUTION * all prices [ baseid ] ) / all prices [ relid ] ;
else printf ( " mismatched %p base.(%s) baseid . % d ( % s ) or % p rel . ( % s ) relid . % d ( % s ) \ n " ,PEGS->contracts[baseid],PEGS->contracts[baseid]->name.base,baseid,base,PEGS->contracts[relid],PEGS->contracts[relid]->name.base,relid,rel) ;
pval = ( uint32_t ) price . Pval ;
} else printf ( " peggy_genesis RAN out of space \n " ) ;
if ( ( PEG = peggy_createpair ( PEGS , 0 , 0 , name , base , rel , maxsupply , maxnetbalance , 0 , SATOSHIDEN * 10 , PEGGY_RATE_777 , firsttimestamp , & price , numprices , spread , maxmargin , mindenom , i , i < sizeof ( peggy_bases ) / sizeof ( * peggy_bases ) , peggymils ) ) ! = 0 )
if ( ( PEG = peggy_createpair ( PEGS , 0 , 0 , name , base , rel , maxsupply , maxnetbalance , 0 , SATOSHIDEN * 10 , PEGGY_RATE_777 , firsttimestamp , & price , 1 , spread , maxmargin , mindenom , i , i < sizeof ( peggy_bases ) / sizeof ( * peggy_bases ) , peggymils ) ) ! = 0 )
{
price = peggy_scaleprice ( price , peggymils ) ;
struct price_resolution x = peggy_price ( PEG , 0 ) ;
@ -418,6 +381,50 @@ struct peggy_info *peggy_genesis(int32_t lookbacks[OPRETURNS_CONTEXTS],struct pe
n + + ;
}
}
}
struct peggy_info * peggy_genesis ( int32_t lookbacks [ OPRETURNS_CONTEXTS ] , struct peggy_info * PEGS , char * path , uint32_t firsttimestamp , char * opreturnstr )
{
//struct peggy_limits limits = { { PERCENTAGE(10), PERCENTAGE(25), PERCENTAGE(33), PERCENTAGE(50) }, SATOSHIDEN * 10000, SATOSHIDEN * 1000, { 0, 30, 90, 180 }, 4 };
uint8_t opret [ 1024 ] ; struct peggy_tx Ptx ; struct price_resolution spread ; uint64_t len ;
long offset ; int32_t i , signedcount , datalen , n = 0 , numprices , err = - 1 ;
numprices = 1 ;
datalen = ( int32_t ) strlen ( opreturnstr ) / 2 ;
decode_hex ( opret , datalen , opreturnstr ) ;
printf ( " peggy_genesis(%s) \n " , opreturnstr ) ;
if ( opret [ 0 ] = = OP_RETURN_OPCODE )
{
offset = hdecode_varint ( & len , opret , 1 , sizeof ( opret ) ) ;
if ( opret [ offset ] = = ' P ' & & opret [ offset + 1 ] = = ' A ' & & opret [ offset + 2 ] = = ' X ' )
{
printf ( " deser \n " ) ;
if ( ( n = serdes777_deserialize ( & signedcount , & Ptx , firsttimestamp , opret + offset + 3 , ( int32_t ) len - 3 ) ) > 0 )
{
err = 0 ;
for ( i = 0 ; i < Ptx . details . price . num ; i + + )
if ( Ptx . details . price . feed [ i ] = = 0 )
break ;
if ( i = = Ptx . details . price . num )
{
printf ( " GENESIS.(%s) \n " , opreturnstr ) ;
for ( i = 0 ; i < Ptx . details . price . num ; i + + )
printf ( " %u " , Ptx . details . price . feed [ i ] ) ;
printf ( " prices \n " ) ;
lookbacks [ 0 ] = 0 , lookbacks [ 1 ] = 1000 ;
if ( PEGS = = 0 )
{
spread . Pval = PERCENTAGE ( 1 ) ;
PEGS = peggy_init ( PEGGY_MAXLOCKDAYS , " BTCD " , SATOSHIDEN / 100 , 1 , 1 , spread , PEGGY_RATE_777 , 40 , 10 , 2 , 5 , 2 , Ptx . timestamp , Ptx . details . price . feed [ 0 ] ) ;
//PEGS->accts = accts777_init(path,0);
PEGS - > genesis = opreturnstr , opreturnstr = 0 ;
}
} else printf ( " i.%d vs %d \n " , i , Ptx . details . price . num ) ;
} else printf ( " deser got n.%d \n " , n ) ;
} else printf ( " illegal opret.(%c%c%c) \n " , opret [ offset ] , opret [ offset + 1 ] , opret [ offset + 2 ] ) ;
} else printf ( " opret[0] %d \n " , opret [ 0 ] ) ;
if ( err < 0 | | PEGS = = 0 )
return ( 0 ) ;
peggy_priceinits ( PEGS , firsttimestamp , Ptx . details . price . feed ) ;
printf ( " genesis prices t%u vs %u \n " , Ptx . timestamp , firsttimestamp ) ;
return ( PEGS ) ;
}
@ -662,7 +669,7 @@ struct peggy_info *peggy_lchain(struct txinds777_info *opreturns,char *path)
int32_t peggy_init_contexts ( struct txinds777_info * opreturns , uint32_t RTblocknum , uint32_t RTblocktimestamp , char * path , void * globals [ OPRETURNS_CONTEXTS ] , int32_t lookbacks [ OPRETURNS_CONTEXTS ] , int32_t maxcontexts )
{
double startmilli ; char buf [ 512 ] ; struct price_resolution spread ; struct peggy_info * PEGS = 0 , * PEGS2 = 0 ;
/* double startmilli; char buf[512]; struct price_resolution spread; struct peggy_info *PEGS=0,*PEGS2=0;
if ( maxcontexts ! = 2 )
{
printf ( " peggy needs 2 contexts \n " ) ;
@ -684,6 +691,17 @@ int32_t peggy_init_contexts(struct txinds777_info *opreturns,uint32_t RTblocknum
globals [ 1 ] = PEGS2 = peggy_init ( buf , PEGGY_MAXLOCKDAYS , " BTCD " , SATOSHIDEN / 100 , 1 , 1 , spread , PEGGY_RATE_777 , 40 , 10 , 2 , 5 , 2 , PEGS - > genesistime , PEGS - > BTCD_price0 ) ;
startmilli = OS_milliseconds ( ) ;
peggy_clone ( buf , PEGS2 , PEGS ) ;
printf ( " cloned %d in %.3f millis per opreturn \n " , PEGS - > numopreturns , ( OS_milliseconds ( ) - startmilli ) / PEGS - > numopreturns ) ; sleep ( 3 ) ;
printf ( " cloned %d in %.3f millis per opreturn \n " , PEGS - > numopreturns , ( OS_milliseconds ( ) - startmilli ) / PEGS - > numopreturns ) ; sleep ( 3 ) ; */
return ( 2 ) ;
}
void peggy_indsinit ( )
{
if ( sizeof ( Peggy_inds ) / sizeof ( * Peggy_inds ) ! = PEGGY_NUMCOEFFS )
{
peggy_geninds ( ) ;
printf ( " need to update Peggy_inds with above \n " ) ;
exit ( - 1 ) ;
}
peggy_dailyrates ( ) ;
}