@@ -1,6 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -x
|
||||||
source pubkey.txt
|
source pubkey.txt
|
||||||
echo $pubkey
|
echo $pubkey
|
||||||
|
|
||||||
|
./komodod -pubkey=$pubkey -ac_name=REVS -ac_supply=1300000 -addnode=78.47.196.146 $1 &
|
||||||
|
./komodod -pubkey=$pubkey -ac_name=SUPERNET -ac_supply=816061 -addnode=78.47.196.146 $1 &
|
||||||
|
./komodod -pubkey=$pubkey -ac_name=DEX -ac_supply=999999 -addnode=78.47.196.146 $1 &
|
||||||
|
./komodod -pubkey=$pubkey -ac_name=PANGEA -ac_supply=999999 -addnode=78.47.196.146 $1 &
|
||||||
|
./komodod -pubkey=$pubkey -ac_name=JUMBLR -ac_supply=999999 -addnode=78.47.196.146 $1 &
|
||||||
|
./komodod -pubkey=$pubkey -ac_name=BET -ac_supply=999999 -addnode=78.47.196.146 $1 &
|
||||||
|
./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=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=USD -addnode=78.47.196.146 $1 &
|
./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 &
|
||||||
./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 $1 &
|
./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 $1 &
|
||||||
./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 $1 &
|
./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 $1 &
|
||||||
@@ -33,3 +47,50 @@ echo $pubkey
|
|||||||
./komodod -pubkey=$pubkey -ac_name=BGN -addnode=78.47.196.146 $1 &
|
./komodod -pubkey=$pubkey -ac_name=BGN -addnode=78.47.196.146 $1 &
|
||||||
./komodod -pubkey=$pubkey -ac_name=IDR -addnode=78.47.196.146 $1 &
|
./komodod -pubkey=$pubkey -ac_name=IDR -addnode=78.47.196.146 $1 &
|
||||||
./komodod -pubkey=$pubkey -ac_name=HRK -addnode=78.47.196.146 $1 &
|
./komodod -pubkey=$pubkey -ac_name=HRK -addnode=78.47.196.146 $1 &
|
||||||
|
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"REVS\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SUPERNET\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DEX\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PANGEA\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"JUMBLR\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BET\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
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\":\"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\":\"USD\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EUR\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"JPY\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GBP\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AUD\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CAD\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHF\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NZD\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CNY\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RUB\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MXN\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BRL\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"INR\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HKD\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"TRY\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZAR\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PLN\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NOK\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEK\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DKK\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CZK\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HUF\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ILS\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KRW\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MYR\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PHP\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RON\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SGD\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"THB\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BGN\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"IDR\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HRK\",\"pubkey\":\"$pubkey\"}"
|
||||||
|
|
||||||
|
|||||||
34
src/assetfunds
Executable file
34
src/assetfunds
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -x
|
||||||
|
./komodo-cli paxdeposit $1 0.01 aud
|
||||||
|
./komodo-cli paxdeposit $1 0.01 bgn
|
||||||
|
./komodo-cli paxdeposit $1 0.01 cad
|
||||||
|
./komodo-cli paxdeposit $1 0.01 chf
|
||||||
|
./komodo-cli paxdeposit $1 0.01 cny
|
||||||
|
./komodo-cli paxdeposit $1 0.01 czk
|
||||||
|
./komodo-cli paxdeposit $1 0.01 dkk
|
||||||
|
./komodo-cli paxdeposit $1 0.01 eur
|
||||||
|
./komodo-cli paxdeposit $1 0.01 gbp
|
||||||
|
./komodo-cli paxdeposit $1 0.01 hkd
|
||||||
|
./komodo-cli paxdeposit $1 0.01 hrk
|
||||||
|
./komodo-cli paxdeposit $1 0.01 huf
|
||||||
|
./komodo-cli paxdeposit $1 0.01 idr
|
||||||
|
./komodo-cli paxdeposit $1 0.01 ils
|
||||||
|
./komodo-cli paxdeposit $1 0.01 inr
|
||||||
|
./komodo-cli paxdeposit $1 0.01 jpy
|
||||||
|
./komodo-cli paxdeposit $1 0.01 krw
|
||||||
|
./komodo-cli paxdeposit $1 0.01 mxn
|
||||||
|
./komodo-cli paxdeposit $1 0.01 myr
|
||||||
|
./komodo-cli paxdeposit $1 0.01 nok
|
||||||
|
./komodo-cli paxdeposit $1 0.01 nzd
|
||||||
|
./komodo-cli paxdeposit $1 0.01 php
|
||||||
|
./komodo-cli paxdeposit $1 0.01 pln
|
||||||
|
./komodo-cli paxdeposit $1 0.01 brl
|
||||||
|
./komodo-cli paxdeposit $1 0.01 ron
|
||||||
|
./komodo-cli paxdeposit $1 0.01 rub
|
||||||
|
./komodo-cli paxdeposit $1 0.01 sek
|
||||||
|
./komodo-cli paxdeposit $1 0.01 sgd
|
||||||
|
./komodo-cli paxdeposit $1 0.01 thb
|
||||||
|
./komodo-cli paxdeposit $1 0.01 try
|
||||||
|
./komodo-cli paxdeposit $1 0.01 usd
|
||||||
|
./komodo-cli paxdeposit $1 0.01 zar
|
||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
#include "cJSON.c"
|
#include "cJSON.c"
|
||||||
#include "komodo_notary.h"
|
#include "komodo_notary.h"
|
||||||
|
|
||||||
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout)
|
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)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,7 @@
|
|||||||
|
|
||||||
static bool fDaemon;
|
static bool fDaemon;
|
||||||
extern char ASSETCHAINS_SYMBOL[16];
|
extern char ASSETCHAINS_SYMBOL[16];
|
||||||
void komodo_gateway_iteration(char *symbol);
|
void komodo_passport_iteration();
|
||||||
void komodo_iteration(char *symbol);
|
|
||||||
int32_t komodo_is_issuer();
|
|
||||||
|
|
||||||
void WaitForShutdown(boost::thread_group* threadGroup)
|
void WaitForShutdown(boost::thread_group* threadGroup)
|
||||||
{
|
{
|
||||||
@@ -44,10 +42,7 @@ void WaitForShutdown(boost::thread_group* threadGroup)
|
|||||||
while (!fShutdown)
|
while (!fShutdown)
|
||||||
{
|
{
|
||||||
MilliSleep(10000);
|
MilliSleep(10000);
|
||||||
if ( komodo_is_issuer() != 0 )
|
komodo_passport_iteration();
|
||||||
komodo_gateway_iteration(ASSETCHAINS_SYMBOL);
|
|
||||||
else komodo_iteration((char *)"EUR");
|
|
||||||
|
|
||||||
fShutdown = ShutdownRequested();
|
fShutdown = ShutdownRequested();
|
||||||
}
|
}
|
||||||
if (threadGroup)
|
if (threadGroup)
|
||||||
@@ -64,6 +59,7 @@ void WaitForShutdown(boost::thread_group* threadGroup)
|
|||||||
extern int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,ASSETCHAIN_INIT;
|
extern int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,ASSETCHAIN_INIT;
|
||||||
extern std::string NOTARY_PUBKEY;
|
extern std::string NOTARY_PUBKEY;
|
||||||
int32_t komodo_is_issuer();
|
int32_t komodo_is_issuer();
|
||||||
|
void komodo_passport_iteration();
|
||||||
|
|
||||||
bool AppInit(int argc, char* argv[])
|
bool AppInit(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
@@ -106,10 +102,11 @@ bool AppInit(int argc, char* argv[])
|
|||||||
fprintf(stderr,"call komodo_args NOTARY_PUBKEY.(%s)\n",NOTARY_PUBKEY.c_str());
|
fprintf(stderr,"call komodo_args NOTARY_PUBKEY.(%s)\n",NOTARY_PUBKEY.c_str());
|
||||||
while ( ASSETCHAIN_INIT == 0 )
|
while ( ASSETCHAIN_INIT == 0 )
|
||||||
{
|
{
|
||||||
if ( komodo_is_issuer() != 0 )
|
//if ( komodo_is_issuer() != 0 )
|
||||||
komodo_gateway_iteration(ASSETCHAINS_SYMBOL);
|
// komodo_passport_iteration();
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
printf("initialized %s\n",ASSETCHAINS_SYMBOL);
|
||||||
if (!boost::filesystem::is_directory(GetDataDir(false)))
|
if (!boost::filesystem::is_directory(GetDataDir(false)))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
|
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
|
||||||
@@ -144,7 +141,6 @@ bool AppInit(int argc, char* argv[])
|
|||||||
fDaemon = GetBoolArg("-daemon", false);
|
fDaemon = GetBoolArg("-daemon", false);
|
||||||
if (fDaemon)
|
if (fDaemon)
|
||||||
{
|
{
|
||||||
extern char ASSETCHAINS_SYMBOL[16];
|
|
||||||
fprintf(stdout, "Komodo %s server starting\n",ASSETCHAINS_SYMBOL);
|
fprintf(stdout, "Komodo %s server starting\n",ASSETCHAINS_SYMBOL);
|
||||||
|
|
||||||
// Daemonize
|
// Daemonize
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ public:
|
|||||||
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
|
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
|
||||||
vFixedSeeds.clear();
|
vFixedSeeds.clear();
|
||||||
vSeeds.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
|
// TODO: set up bootstrapping for mainnet
|
||||||
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,60);
|
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,60);
|
||||||
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,85);
|
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,85);
|
||||||
|
|||||||
12
src/fiat-cli
12
src/fiat-cli
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#set -x
|
||||||
echo aud; fiat/aud $1 $2 $3 $4
|
echo aud; fiat/aud $1 $2 $3 $4
|
||||||
echo bgn; fiat/bgn $1 $2 $3 $4
|
echo bgn; fiat/bgn $1 $2 $3 $4
|
||||||
echo cad; fiat/cad $1 $2 $3 $4
|
echo cad; fiat/cad $1 $2 $3 $4
|
||||||
@@ -31,3 +32,14 @@ echo thb; fiat/thb $1 $2 $3 $4
|
|||||||
echo try; fiat/try $1 $2 $3 $4
|
echo try; fiat/try $1 $2 $3 $4
|
||||||
echo usd; fiat/usd $1 $2 $3 $4
|
echo usd; fiat/usd $1 $2 $3 $4
|
||||||
echo zar; fiat/zar $1 $2 $3 $4
|
echo zar; fiat/zar $1 $2 $3 $4
|
||||||
|
echo revs; fiat/revs $1 $2 $3 $4
|
||||||
|
echo supernet; fiat/supernet $1 $2 $3 $4
|
||||||
|
echo dex; fiat/dex $1 $2 $3 $4
|
||||||
|
echo pangea; fiat/pangea $1 $2 $3 $4
|
||||||
|
echo jumblr; fiat/jumblr $1 $2 $3 $4
|
||||||
|
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 bots; fiat/bots $1 $2 $3 $4
|
||||||
|
echo mgw; fiat/mgw $1 $2 $3 $4
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
./komodo-cli -ac_name=-USD $1 $2 $3 $4
|
|
||||||
2
src/fiat/bet
Executable file
2
src/fiat/bet
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
./komodo-cli -ac_name=BET $1 $2 $3 $4
|
||||||
2
src/fiat/bots
Executable file
2
src/fiat/bots
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
./komodo-cli -ac_name=BOTS $1 $2 $3 $4
|
||||||
2
src/fiat/crypto
Executable file
2
src/fiat/crypto
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
./komodo-cli -ac_name=CRYPTO $1 $2 $3 $4
|
||||||
2
src/fiat/dex
Executable file
2
src/fiat/dex
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
./komodo-cli -ac_name=DEX $1 $2 $3 $4
|
||||||
2
src/fiat/hodl
Executable file
2
src/fiat/hodl
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
./komodo-cli -ac_name=HODL $1 $2 $3 $4
|
||||||
2
src/fiat/jumblr
Executable file
2
src/fiat/jumblr
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
./komodo-cli -ac_name=JUMBLR $1 $2 $3 $4
|
||||||
2
src/fiat/mgw
Executable file
2
src/fiat/mgw
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
./komodo-cli -ac_name=MGW $1 $2 $3 $4
|
||||||
2
src/fiat/pangea
Executable file
2
src/fiat/pangea
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
./komodo-cli -ac_name=PANGEA $1 $2 $3 $4
|
||||||
2
src/fiat/revs
Executable file
2
src/fiat/revs
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
./komodo-cli -ac_name=REVS $1 $2 $3 $4
|
||||||
2
src/fiat/shark
Executable file
2
src/fiat/shark
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
./komodo-cli -ac_name=SHARK $1 $2 $3 $4
|
||||||
2
src/fiat/supernet
Executable file
2
src/fiat/supernet
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
./komodo-cli -ac_name=SUPERNET $1 $2 $3 $4
|
||||||
@@ -1256,7 +1256,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||||||
// first suggest a reindex
|
// first suggest a reindex
|
||||||
if (!fReset) {
|
if (!fReset) {
|
||||||
bool fRet = uiInterface.ThreadSafeMessageBox(
|
bool fRet = uiInterface.ThreadSafeMessageBox(
|
||||||
strLoadError + ".\n\n" + _("Do you want to rebuild the block database now?"),
|
strLoadError + ".\n\n" + _("error in HDD data, might just need to update to latest, if that doesnt work, then you need to resync"),
|
||||||
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
|
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
|
||||||
if (fRet) {
|
if (fRet) {
|
||||||
fReindex = true;
|
fReindex = true;
|
||||||
|
|||||||
288
src/komodo.h
288
src/komodo.h
@@ -17,15 +17,15 @@
|
|||||||
#define H_KOMODO_H
|
#define H_KOMODO_H
|
||||||
|
|
||||||
// Todo:
|
// Todo:
|
||||||
// 0. optimize assetchains
|
// verify: reorgs
|
||||||
// 1. error check fiat redeem amounts
|
|
||||||
// 2. net balance limiter
|
|
||||||
// 3. verify: reorgs
|
|
||||||
|
|
||||||
// non komodod (non-hardfork) todo:
|
// non komodod (non-hardfork) todo:
|
||||||
// a. automate notarization fee payouts
|
// a. automate notarization fee payouts
|
||||||
// b. automated distribution of test REVS snapshot
|
// b. automated distribution of test REVS snapshot
|
||||||
|
|
||||||
|
//#define KOMODO_ASSETCHAINS_WAITNOTARIZE
|
||||||
|
#define KOMODO_PAXMAX (10000 * COIN)
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@@ -41,21 +41,16 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block);
|
|||||||
#include "komodo_globals.h"
|
#include "komodo_globals.h"
|
||||||
#include "komodo_utils.h"
|
#include "komodo_utils.h"
|
||||||
|
|
||||||
void komodo_setkmdheight(int32_t kmdheight)
|
|
||||||
{
|
|
||||||
if ( kmdheight > KMDHEIGHT )
|
|
||||||
KMDHEIGHT = kmdheight;
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "cJSON.c"
|
#include "cJSON.c"
|
||||||
#include "komodo_bitcoind.h"
|
#include "komodo_bitcoind.h"
|
||||||
#include "komodo_interest.h"
|
#include "komodo_interest.h"
|
||||||
#include "komodo_pax.h"
|
#include "komodo_pax.h"
|
||||||
#include "komodo_notary.h"
|
#include "komodo_notary.h"
|
||||||
|
|
||||||
|
int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char *dest);
|
||||||
#include "komodo_gateway.h"
|
#include "komodo_gateway.h"
|
||||||
#include "komodo_events.h"
|
#include "komodo_events.h"
|
||||||
|
|
||||||
|
|
||||||
void komodo_currentheight_set(int32_t height)
|
void komodo_currentheight_set(int32_t height)
|
||||||
{
|
{
|
||||||
char symbol[16],dest[16]; struct komodo_state *sp;
|
char symbol[16],dest[16]; struct komodo_state *sp;
|
||||||
@@ -91,8 +86,8 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
|
|||||||
errs++;
|
errs++;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("updated %d pubkeys at ht.%d\n",num,ht);
|
//printf("updated %d pubkeys at %s ht.%d\n",num,symbol,ht);
|
||||||
if ( matched != 0 )
|
if ( (KOMODO_EXTERNAL_NOTARIES != 0 && matched != 0) || (strcmp(symbol,"KMD") == 0 && KOMODO_EXTERNAL_NOTARIES == 0) )
|
||||||
komodo_eventadd_pubkeys(sp,symbol,ht,num,pubkeys);
|
komodo_eventadd_pubkeys(sp,symbol,ht,num,pubkeys);
|
||||||
}
|
}
|
||||||
} else printf("illegal num.%d\n",num);
|
} else printf("illegal num.%d\n",num);
|
||||||
@@ -105,11 +100,12 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
|
|||||||
errs++;
|
errs++;
|
||||||
if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) )
|
if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) )
|
||||||
errs++;
|
errs++;
|
||||||
printf("load NOTARIZED %d %s\n",notarized_height,notarized_hash.ToString().c_str());
|
if ( 0 && sp != 0 )
|
||||||
if ( matched != 0 )
|
printf("%s load[%s.%d] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,notarized_height,notarized_hash.ToString().c_str());
|
||||||
komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height);
|
//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' )
|
else if ( func == 'U' ) // deprecated
|
||||||
{
|
{
|
||||||
uint8_t n,nid; uint256 hash; uint64_t mask;
|
uint8_t n,nid; uint256 hash; uint64_t mask;
|
||||||
n = fgetc(fp);
|
n = fgetc(fp);
|
||||||
@@ -127,12 +123,24 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
|
|||||||
int32_t kheight;
|
int32_t kheight;
|
||||||
if ( fread(&kheight,1,sizeof(kheight),fp) != sizeof(kheight) )
|
if ( fread(&kheight,1,sizeof(kheight),fp) != sizeof(kheight) )
|
||||||
errs++;
|
errs++;
|
||||||
if ( matched != 0 )
|
//if ( matched != 0 ) global independent states -> inside *sp
|
||||||
komodo_eventadd_kmdheight(sp,symbol,ht,kheight);
|
//printf("%s.%d load[%s] ht.%d\n",ASSETCHAINS_SYMBOL,ht,symbol,kheight);
|
||||||
|
komodo_eventadd_kmdheight(sp,symbol,ht,kheight,0);
|
||||||
|
}
|
||||||
|
else if ( func == 'T' )
|
||||||
|
{
|
||||||
|
int32_t kheight,ktimestamp;
|
||||||
|
if ( fread(&kheight,1,sizeof(kheight),fp) != sizeof(kheight) )
|
||||||
|
errs++;
|
||||||
|
if ( fread(&ktimestamp,1,sizeof(ktimestamp),fp) != 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' )
|
else if ( func == 'R' )
|
||||||
{
|
{
|
||||||
uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[10000];
|
uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[16384];
|
||||||
if ( fread(&txid,1,sizeof(txid),fp) != sizeof(txid) )
|
if ( fread(&txid,1,sizeof(txid),fp) != sizeof(txid) )
|
||||||
errs++;
|
errs++;
|
||||||
if ( fread(&v,1,sizeof(v),fp) != sizeof(v) )
|
if ( fread(&v,1,sizeof(v),fp) != sizeof(v) )
|
||||||
@@ -145,9 +153,20 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
|
|||||||
{
|
{
|
||||||
if ( fread(opret,1,olen,fp) != olen )
|
if ( fread(opret,1,olen,fp) != olen )
|
||||||
errs++;
|
errs++;
|
||||||
if ( matched != 0 )
|
if ( 0 && matched != 0 )
|
||||||
komodo_eventadd_opreturn(sp,symbol,ht,txid,ovalue,v,opret,olen);
|
{
|
||||||
} else printf("illegal olen.%u\n",olen);
|
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++)
|
||||||
|
fgetc(fp);
|
||||||
|
//printf("illegal olen.%u\n",olen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ( func == 'D' )
|
else if ( func == 'D' )
|
||||||
{
|
{
|
||||||
@@ -159,17 +178,18 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
|
|||||||
numpvals = fgetc(fp);
|
numpvals = fgetc(fp);
|
||||||
if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && fread(pvals,sizeof(uint32_t),numpvals,fp) == numpvals )
|
if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && fread(pvals,sizeof(uint32_t),numpvals,fp) == numpvals )
|
||||||
{
|
{
|
||||||
if ( matched != 0 )
|
//if ( matched != 0 ) global shared state -> global PVALS
|
||||||
komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals);
|
//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);
|
//printf("load pvals ht.%d numpvals.%d\n",ht,numpvals);
|
||||||
} else printf("error loading pvals[%d]\n",numpvals);
|
} else printf("error loading pvals[%d]\n",numpvals);
|
||||||
}
|
}
|
||||||
else printf("illegal func.(%d %c)\n",func,func);
|
else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func);
|
||||||
return(func);
|
return(func);
|
||||||
} else return(-1);
|
} else 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,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout)
|
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;
|
static FILE *fp; static int32_t errs;
|
||||||
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[16],dest[16]; int32_t ht,func; uint8_t num,pubkeys[64][33];
|
||||||
@@ -177,25 +197,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
|
|||||||
return;
|
return;
|
||||||
if ( fp == 0 )
|
if ( fp == 0 )
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate");
|
||||||
sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodostate");
|
|
||||||
//sprintf(fname2,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"minerids");
|
|
||||||
#else
|
|
||||||
sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),(char *)"komodostate");
|
|
||||||
//sprintf(fname2,"%s/%s",GetDataDir(false).string().c_str(),(char *)"minerids");
|
|
||||||
#endif
|
|
||||||
/*memset(Minerids,0xfe,sizeof(Minerids));
|
|
||||||
if ( (Minerfp= fopen(fname2,"rb+")) == 0 )
|
|
||||||
{
|
|
||||||
if ( (Minerfp= fopen(fname2,"wb")) != 0 )
|
|
||||||
{
|
|
||||||
fwrite(Minerids,1,sizeof(Minerids),Minerfp);
|
|
||||||
fclose(Minerfp);
|
|
||||||
}
|
|
||||||
Minerfp = fopen(fname2,"rb+");
|
|
||||||
}
|
|
||||||
if ( Minerfp != 0 && fread(Minerids,1,sizeof(Minerids),Minerfp) != sizeof(Minerids) )
|
|
||||||
printf("read error Minerids\n");*/
|
|
||||||
if ( (fp= fopen(fname,"rb+")) != 0 )
|
if ( (fp= fopen(fname,"rb+")) != 0 )
|
||||||
{
|
{
|
||||||
while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 )
|
while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 )
|
||||||
@@ -212,14 +214,27 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
|
|||||||
if ( fp != 0 ) // write out funcid, height, other fields, call side effect function
|
if ( fp != 0 ) // write out funcid, height, other fields, call side effect function
|
||||||
{
|
{
|
||||||
//printf("fpos.%ld ",ftell(fp));
|
//printf("fpos.%ld ",ftell(fp));
|
||||||
if ( KMDheight > 0 )
|
if ( KMDheight != 0 )
|
||||||
{
|
{
|
||||||
fputc('K',fp);
|
if ( KMDtimestamp != 0 )
|
||||||
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
|
{
|
||||||
errs++;
|
fputc('T',fp);
|
||||||
if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) )
|
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
|
||||||
errs++;
|
errs++;
|
||||||
komodo_eventadd_kmdheight(sp,symbol,height,KMDheight);
|
if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) )
|
||||||
|
errs++;
|
||||||
|
if ( fwrite(&KMDtimestamp,1,sizeof(KMDtimestamp),fp) != sizeof(KMDtimestamp) )
|
||||||
|
errs++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fputc('K',fp);
|
||||||
|
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
|
||||||
|
errs++;
|
||||||
|
if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) )
|
||||||
|
errs++;
|
||||||
|
}
|
||||||
|
komodo_eventadd_kmdheight(sp,symbol,height,KMDheight,KMDtimestamp);
|
||||||
}
|
}
|
||||||
else if ( opretbuf != 0 && opretlen > 0 )
|
else if ( opretbuf != 0 && opretlen > 0 )
|
||||||
{
|
{
|
||||||
@@ -290,25 +305,28 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
|
|||||||
else if ( height != 0 )
|
else if ( height != 0 )
|
||||||
{
|
{
|
||||||
//printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs);
|
//printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs);
|
||||||
fputc('N',fp);
|
if ( sp != 0 )
|
||||||
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
|
{
|
||||||
errs++;
|
fputc('N',fp);
|
||||||
if ( fwrite(&sp->NOTARIZED_HEIGHT,1,sizeof(sp->NOTARIZED_HEIGHT),fp) != sizeof(sp->NOTARIZED_HEIGHT) )
|
if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) )
|
||||||
errs++;
|
errs++;
|
||||||
if ( fwrite(&sp->NOTARIZED_HASH,1,sizeof(sp->NOTARIZED_HASH),fp) != sizeof(sp->NOTARIZED_HASH) )
|
if ( fwrite(&sp->NOTARIZED_HEIGHT,1,sizeof(sp->NOTARIZED_HEIGHT),fp) != sizeof(sp->NOTARIZED_HEIGHT) )
|
||||||
errs++;
|
errs++;
|
||||||
if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) )
|
if ( fwrite(&sp->NOTARIZED_HASH,1,sizeof(sp->NOTARIZED_HASH),fp) != sizeof(sp->NOTARIZED_HASH) )
|
||||||
errs++;
|
errs++;
|
||||||
komodo_eventadd_notarized(sp,symbol,height,dest,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID,sp->NOTARIZED_HEIGHT);
|
if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) )
|
||||||
//komodo_notarized_update(height,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_DESTTXID);
|
errs++;
|
||||||
|
komodo_eventadd_notarized(sp,symbol,height,dest,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID,sp->NOTARIZED_HEIGHT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fflush(fp);
|
fflush(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 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; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[16],dest[16];
|
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];
|
||||||
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
|
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
|
||||||
return(-1);
|
return(-1);
|
||||||
if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
|
if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
|
||||||
@@ -354,21 +372,45 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
|
|||||||
else if ( opretlen == 0x4d )
|
else if ( opretlen == 0x4d )
|
||||||
{
|
{
|
||||||
opretlen = scriptbuf[len++];
|
opretlen = scriptbuf[len++];
|
||||||
opretlen = (opretlen << 8) + scriptbuf[len++];
|
opretlen += (scriptbuf[len++] << 8);
|
||||||
}
|
}
|
||||||
if ( j == 1 && opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
|
if ( j == 1 && opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
|
||||||
{
|
{
|
||||||
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid);
|
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid);
|
||||||
len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp);
|
len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp);
|
||||||
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid);
|
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid);
|
||||||
if ( *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height )
|
if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height )
|
||||||
{
|
{
|
||||||
printf("ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s)\n",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]);
|
|
||||||
sp->NOTARIZED_HEIGHT = *notarizedheightp;
|
sp->NOTARIZED_HEIGHT = *notarizedheightp;
|
||||||
sp->NOTARIZED_HASH = kmdtxid;
|
sp->NOTARIZED_HASH = kmdtxid;
|
||||||
sp->NOTARIZED_DESTTXID = desttxid;
|
sp->NOTARIZED_DESTTXID = desttxid;
|
||||||
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0);
|
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0);
|
||||||
} else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]);
|
len += 4;
|
||||||
|
if ( 0 && 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);
|
||||||
|
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||||
|
{
|
||||||
|
if ( signedfp == 0 )
|
||||||
|
{
|
||||||
|
char fname[512];
|
||||||
|
komodo_statefname(fname,(char *)"",(char *)"signedmasks");
|
||||||
|
if ( (signedfp= fopen(fname,"rb+")) == 0 )
|
||||||
|
signedfp = fopen(fname,"wb");
|
||||||
|
else fseek(signedfp,0,SEEK_END);
|
||||||
|
}
|
||||||
|
if ( signedfp != 0 )
|
||||||
|
{
|
||||||
|
fwrite(&height,1,sizeof(height),signedfp);
|
||||||
|
fwrite(&signedmask,1,sizeof(signedmask),signedfp);
|
||||||
|
fflush(signedfp);
|
||||||
|
}
|
||||||
|
if ( opretlen > len && scriptbuf[len] == 'A' )
|
||||||
|
{
|
||||||
|
printf("Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len);
|
||||||
|
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len,j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else printf("notarized.%d %llx reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",notarized,(long long)signedmask,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]);
|
||||||
}
|
}
|
||||||
else if ( i == 0 && j == 1 && opretlen == 149 )
|
else if ( i == 0 && j == 1 && opretlen == 149 )
|
||||||
komodo_paxpricefeed(height,&scriptbuf[len],opretlen);
|
komodo_paxpricefeed(height,&scriptbuf[len],opretlen);
|
||||||
@@ -376,7 +418,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
|
|||||||
{
|
{
|
||||||
int32_t k; for (k=0; k<scriptlen; k++)
|
int32_t k; for (k=0; k<scriptlen; k++)
|
||||||
printf("%02x",scriptbuf[k]);
|
printf("%02x",scriptbuf[k]);
|
||||||
printf(" <- script ht.%d i.%d j.%d value %.8f\n",height,i,j,dstr(value));
|
printf(" <- script ht.%d i.%d j.%d value %.8f %s\n",height,i,j,dstr(value),ASSETCHAINS_SYMBOL);
|
||||||
if ( opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
|
if ( opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
|
||||||
{
|
{
|
||||||
for (k=0; k<32; k++)
|
for (k=0; k<32; k++)
|
||||||
@@ -389,25 +431,25 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( *isratificationp == 0 )
|
if ( *isratificationp == 0 )
|
||||||
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,value,&scriptbuf[len],opretlen,j);
|
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen,j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(notaryid);
|
return(notaryid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_isratify(int32_t isspecial,int32_t numvalid)
|
/*int32_t komodo_isratify(int32_t isspecial,int32_t numvalid)
|
||||||
{
|
{
|
||||||
if ( isspecial != 0 && numvalid >= KOMODO_MINRATIFY )
|
if ( isspecial != 0 && numvalid >= KOMODO_MINRATIFY )
|
||||||
return(1);
|
return(1);
|
||||||
else return(0);
|
else return(0);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Special tx have vout[0] -> CRYPTO777
|
// Special tx have vout[0] -> CRYPTO777
|
||||||
// with more than KOMODO_MINRATIFY pay2pubkey outputs -> ratify
|
// with more than KOMODO_MINRATIFY pay2pubkey outputs -> ratify
|
||||||
// if all outputs to notary -> notary utxo
|
// if all outputs to notary -> notary utxo
|
||||||
// if txi == 0 && 2 outputs and 2nd OP_RETURN, len == 32*2+4 -> notarized, 1st byte 'P' -> pricefeed
|
// if txi == 0 && 2 outputs and 2nd OP_RETURN, len == 32*2+4 -> notarized, 1st byte 'P' -> pricefeed
|
||||||
// OP_RETURN: 'D' -> deposit, 'W' -> withdraw
|
// OP_RETURN: 'D' -> deposit, 'W' -> withdraw
|
||||||
void komodo_currentheight_set(int32_t height);
|
|
||||||
int32_t gettxout_scriptPubKey(uint8_t *scriptPubKey,int32_t maxsize,uint256 txid,int32_t n);
|
int32_t gettxout_scriptPubKey(uint8_t *scriptPubKey,int32_t maxsize,uint256 txid,int32_t n);
|
||||||
|
|
||||||
int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys[64][33],int32_t numnotaries,uint8_t rmd160[20])
|
int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys[64][33],int32_t numnotaries,uint8_t rmd160[20])
|
||||||
@@ -428,30 +470,27 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
|||||||
{
|
{
|
||||||
static int32_t hwmheight;
|
static int32_t hwmheight;
|
||||||
uint64_t signedmask,voutmask; char symbol[16],dest[16]; struct komodo_state *sp;
|
uint64_t signedmask,voutmask; char symbol[16],dest[16]; struct komodo_state *sp;
|
||||||
uint8_t scriptbuf[4096],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 kmdtxid,btctxid,txhash;
|
uint8_t scriptbuf[4096],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 kmdtxid,zero,btctxid,txhash;
|
||||||
int32_t i,j,k,numnotaries,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
|
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));
|
||||||
komodo_init(pindex->nHeight);
|
komodo_init(pindex->nHeight);
|
||||||
|
KOMODO_INITDONE = (uint32_t)time(NULL);
|
||||||
|
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"unexpected null komodostateptr.[%s]\n",ASSETCHAINS_SYMBOL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
numnotaries = komodo_notaries(pubkeys,pindex->nHeight);
|
numnotaries = komodo_notaries(pubkeys,pindex->nHeight);
|
||||||
calc_rmd160_sha256(rmd160,pubkeys[0],33);
|
calc_rmd160_sha256(rmd160,pubkeys[0],33);
|
||||||
if ( pindex->nHeight > hwmheight )
|
if ( pindex->nHeight > hwmheight )
|
||||||
hwmheight = pindex->nHeight;
|
hwmheight = pindex->nHeight;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("hwmheight.%d vs pindex->nHeight.%d reorg.%d\n",hwmheight,pindex->nHeight,hwmheight-pindex->nHeight);
|
printf("%s hwmheight.%d vs pindex->nHeight.%d t.%u reorg.%d\n",ASSETCHAINS_SYMBOL,hwmheight,pindex->nHeight,(uint32_t)pindex->nTime,hwmheight-pindex->nHeight);
|
||||||
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
|
komodo_event_rewind(sp,symbol,pindex->nHeight);
|
||||||
komodo_event_rewind(sp,symbol,pindex->nHeight);
|
komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0);
|
||||||
// komodo_stateupdate();
|
|
||||||
}
|
}
|
||||||
komodo_currentheight_set(chainActive.Tip()->nHeight);
|
komodo_currentheight_set(chainActive.Tip()->nHeight);
|
||||||
if ( komodo_is_issuer() != 0 )
|
|
||||||
{
|
|
||||||
while ( KOMODO_REALTIME == 0 || time(NULL) <= KOMODO_REALTIME )
|
|
||||||
{
|
|
||||||
fprintf(stderr,"komodo_connect.(%s) waiting for realtime RT.%u now.%u\n",ASSETCHAINS_SYMBOL,KOMODO_REALTIME,(uint32_t)time(NULL));
|
|
||||||
sleep(30);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KOMODO_REALTIME = KOMODO_INITDONE = (uint32_t)time(NULL);
|
|
||||||
if ( pindex != 0 )
|
if ( pindex != 0 )
|
||||||
{
|
{
|
||||||
height = pindex->nHeight;
|
height = pindex->nHeight;
|
||||||
@@ -461,7 +500,32 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
|||||||
txhash = block.vtx[i].GetHash();
|
txhash = block.vtx[i].GetHash();
|
||||||
numvouts = block.vtx[i].vout.size();
|
numvouts = block.vtx[i].vout.size();
|
||||||
notaryid = -1;
|
notaryid = -1;
|
||||||
voutmask = specialtx = notarizedheight = isratification = 0;
|
voutmask = specialtx = notarizedheight = isratification = notarized = 0;
|
||||||
|
signedmask = (height < 91400) ? 1 : 0;
|
||||||
|
numvins = block.vtx[i].vin.size();
|
||||||
|
for (j=0; j<numvins; j++)
|
||||||
|
{
|
||||||
|
if ( i == 0 && j == 0 )
|
||||||
|
continue;
|
||||||
|
if ( (scriptlen= gettxout_scriptPubKey(scriptPubKey,sizeof(scriptPubKey),block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n)) > 0 )
|
||||||
|
{
|
||||||
|
if ( (k= komodo_notarycmp(scriptPubKey,scriptlen,pubkeys,numnotaries,rmd160)) >= 0 )
|
||||||
|
signedmask |= (1LL << k);
|
||||||
|
else if ( 0 && numvins >= 17 )
|
||||||
|
{
|
||||||
|
int32_t k;
|
||||||
|
for (k=0; k<scriptlen; k++)
|
||||||
|
printf("%02x",scriptPubKey[k]);
|
||||||
|
printf(" scriptPubKey doesnt match any notary vini.%d of %d\n",j,numvins);
|
||||||
|
}
|
||||||
|
} else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j);
|
||||||
|
}
|
||||||
|
numvalid = bitweight(signedmask);
|
||||||
|
if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || numvalid > (numnotaries/4)) )
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
for (j=0; j<numvouts; j++)
|
for (j=0; j<numvouts; j++)
|
||||||
{
|
{
|
||||||
len = block.vtx[i].vout[j].scriptPubKey.size();
|
len = block.vtx[i].vout[j].scriptPubKey.size();
|
||||||
@@ -472,7 +536,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
|||||||
#else
|
#else
|
||||||
memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
|
memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
|
||||||
#endif
|
#endif
|
||||||
notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue);
|
notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask);
|
||||||
if ( 0 && i > 0 )
|
if ( 0 && i > 0 )
|
||||||
{
|
{
|
||||||
for (k=0; k<len; k++)
|
for (k=0; k<len; k++)
|
||||||
@@ -481,30 +545,14 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( i != 0 && notaryid >= 0 && notaryid < 64 && voutmask != 0 )
|
printf("%s ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d isratification.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx,isratification);
|
||||||
|
if ( notarized != 0 && (notarizedheight != 0 || specialtx != 0) )
|
||||||
{
|
{
|
||||||
//komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0,0,0,0,0);
|
if ( isratification != 0 )
|
||||||
}
|
|
||||||
signedmask = 0;
|
|
||||||
numvins = block.vtx[i].vin.size();
|
|
||||||
for (j=0; j<numvins; j++)
|
|
||||||
{
|
|
||||||
if ( (scriptlen= gettxout_scriptPubKey(scriptPubKey,sizeof(scriptPubKey),block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n)) > 0 )
|
|
||||||
{
|
{
|
||||||
if ( (k= komodo_notarycmp(scriptPubKey,scriptlen,pubkeys,numnotaries,rmd160)) >= 0 )
|
printf("%s NOTARY SIGNED.%llx numvins.%d ht.%d txi.%d notaryht.%d specialtx.%d\n",ASSETCHAINS_SYMBOL,(long long)signedmask,numvins,height,i,notarizedheight,specialtx);
|
||||||
signedmask |= (1LL << k);
|
printf("ht.%d specialtx.%d isratification.%d numvouts.%d signed.%llx numnotaries.%d\n",height,specialtx,isratification,numvouts,(long long)signedmask,numnotaries);
|
||||||
}
|
}
|
||||||
/*if ( (k= komodo_nutxofind(height,block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n)) >= 0 )
|
|
||||||
signedmask |= (1LL << k);
|
|
||||||
else if ( signedmask != 0 )
|
|
||||||
printf("signedmask.%llx but ht.%d i.%d j.%d not found (%s %d)\n",(long long)signedmask,height,i,j,block.vtx[i].vin[j].prevout.hash.ToString().c_str(),block.vtx[i].vin[j].prevout.n);*/
|
|
||||||
}
|
|
||||||
if ( signedmask != 0 )
|
|
||||||
printf("ht.%d signedmask.%llx numvins.%d numvouts.%d\n",height,(long long)signedmask,numvins,numvouts);
|
|
||||||
if ( signedmask != 0 && (notarizedheight != 0 || specialtx != 0) )
|
|
||||||
{
|
|
||||||
printf("NOTARY SIGNED.%llx numvins.%d ht.%d txi.%d notaryht.%d specialtx.%d\n",(long long)signedmask,numvins,height,i,notarizedheight,specialtx);
|
|
||||||
printf("ht.%d specialtx.%d isratification.%d numvouts.%d signed.%llx numnotaries.%d\n",height,specialtx,isratification,numvouts,(long long)signedmask,numnotaries);
|
|
||||||
if ( specialtx != 0 && isratification != 0 && numvouts > 2 )
|
if ( specialtx != 0 && isratification != 0 && numvouts > 2 )
|
||||||
{
|
{
|
||||||
numvalid = 0;
|
numvalid = 0;
|
||||||
@@ -528,17 +576,19 @@ 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));
|
memset(&txhash,0,sizeof(txhash));
|
||||||
komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0);
|
komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0,0);
|
||||||
printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,height);
|
printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,height);
|
||||||
} else printf("signedmask.%llx numvalid.%d wt.%d numnotaries.%d\n",(long long)signedmask,numvalid,bitweight(signedmask),numnotaries);
|
} else printf("signedmask.%llx numvalid.%d wt.%d numnotaries.%d\n",(long long)signedmask,numvalid,bitweight(signedmask),numnotaries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else printf("komodo_connectblock: unexpected null pindex\n");
|
if ( pindex->nHeight == hwmheight )
|
||||||
KOMODO_INITDONE = (uint32_t)time(NULL);
|
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0);
|
||||||
|
} else fprintf(stderr,"komodo_connectblock: unexpected null pindex\n");
|
||||||
|
//KOMODO_INITDONE = (uint32_t)time(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char *
|
|||||||
return(chunk.memory);
|
return(chunk.memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *komodo_issuemethod(char *method,char *params,uint16_t port)
|
char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port)
|
||||||
{
|
{
|
||||||
//static void *cHandle;
|
//static void *cHandle;
|
||||||
char url[512],*retstr=0,*retstr2=0,postdata[8192];
|
char url[512],*retstr=0,*retstr2=0,postdata[8192];
|
||||||
@@ -340,12 +340,70 @@ char *komodo_issuemethod(char *method,char *params,uint16_t port)
|
|||||||
sprintf(url,(char *)"http://127.0.0.1:%u",port);
|
sprintf(url,(char *)"http://127.0.0.1:%u",port);
|
||||||
sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params);
|
sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params);
|
||||||
//printf("postdata.(%s) USERPASS.(%s)\n",postdata,KMDUSERPASS);
|
//printf("postdata.(%s) USERPASS.(%s)\n",postdata,KMDUSERPASS);
|
||||||
retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,KMDUSERPASS,method,params);
|
retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params);
|
||||||
//retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0);
|
//retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0);
|
||||||
}
|
}
|
||||||
return(retstr2);
|
return(retstr2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint256 komodo_getblockhash(int32_t height)
|
||||||
|
{
|
||||||
|
uint256 hash; char params[128],*hexstr,*jsonstr; cJSON *result; int32_t i; uint8_t revbuf[32];
|
||||||
|
memset(&hash,0,sizeof(hash));
|
||||||
|
sprintf(params,"[%d]",height);
|
||||||
|
if ( (jsonstr= komodo_issuemethod(KMDUSERPASS,(char *)"getblockhash",params,7771)) != 0 )
|
||||||
|
{
|
||||||
|
if ( (result= cJSON_Parse(jsonstr)) != 0 )
|
||||||
|
{
|
||||||
|
if ( (hexstr= jstr(result,(char *)"result")) != 0 )
|
||||||
|
{
|
||||||
|
if ( is_hexstr(hexstr,0) == 64 )
|
||||||
|
{
|
||||||
|
decode_hex(revbuf,32,hexstr);
|
||||||
|
for (i=0; i<32; i++)
|
||||||
|
((uint8_t *)&hash)[i] = revbuf[31-i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free_json(result);
|
||||||
|
}
|
||||||
|
printf("KMD hash.%d (%s) %x\n",height,jsonstr,*(uint32_t *)&hash);
|
||||||
|
free(jsonstr);
|
||||||
|
}
|
||||||
|
return(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint256 _komodo_getblockhash(int32_t height);
|
||||||
|
|
||||||
|
uint64_t komodo_seed(int32_t height)
|
||||||
|
{
|
||||||
|
uint64_t seed = 0;
|
||||||
|
if ( 0 ) // problem during init time, seeds are needed for loading blockindex, so null seeds...
|
||||||
|
{
|
||||||
|
uint256 hash,zero; CBlockIndex *pindex;
|
||||||
|
memset(&hash,0,sizeof(hash));
|
||||||
|
memset(&zero,0,sizeof(zero));
|
||||||
|
if ( height > 10 )
|
||||||
|
height -= 10;
|
||||||
|
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||||
|
hash = _komodo_getblockhash(height);
|
||||||
|
if ( memcmp(&hash,&zero,sizeof(hash)) == 0 )
|
||||||
|
hash = komodo_getblockhash(height);
|
||||||
|
int32_t i;
|
||||||
|
for (i=0; i<32; i++)
|
||||||
|
printf("%02x",((uint8_t *)&hash)[i]);
|
||||||
|
printf(" seed.%d\n",height);
|
||||||
|
seed = arith_uint256(hash.GetHex()).GetLow64();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
seed = (height << 13) ^ (height << 2);
|
||||||
|
seed <<= 21;
|
||||||
|
seed |= (height & 0xffffffff);
|
||||||
|
seed ^= (seed << 17) ^ (seed << 1);
|
||||||
|
}
|
||||||
|
return(seed);
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t komodo_txtime(uint256 hash)
|
uint32_t komodo_txtime(uint256 hash)
|
||||||
{
|
{
|
||||||
CTransaction tx;
|
CTransaction tx;
|
||||||
@@ -362,17 +420,6 @@ uint32_t komodo_txtime(uint256 hash)
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t komodo_seed(int32_t height)
|
|
||||||
{
|
|
||||||
uint256 hash; uint64_t seed = 0; CBlockIndex *pindex = chainActive[height];
|
|
||||||
if ( pindex != 0 )
|
|
||||||
{
|
|
||||||
hash = pindex->GetBlockHash();
|
|
||||||
seed = arith_uint256(hash.GetHex()).GetLow64();
|
|
||||||
}
|
|
||||||
return(seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
|
void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
|
||||||
{
|
{
|
||||||
char symbol[16],dest[16]; struct komodo_state *sp;
|
char symbol[16],dest[16]; struct komodo_state *sp;
|
||||||
@@ -422,7 +469,7 @@ int32_t komodo_block2height(CBlock *block)
|
|||||||
}
|
}
|
||||||
//printf(" <- coinbase.%d ht.%d\n",(int32_t)block->vtx[0].vin[0].scriptSig.size(),height);
|
//printf(" <- coinbase.%d ht.%d\n",(int32_t)block->vtx[0].vin[0].scriptSig.size(),height);
|
||||||
}
|
}
|
||||||
komodo_init(height);
|
//komodo_init(height);
|
||||||
return(height);
|
return(height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,7 +481,7 @@ void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block)
|
|||||||
#else
|
#else
|
||||||
uint8_t *ptr = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey[0];
|
uint8_t *ptr = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey[0];
|
||||||
#endif
|
#endif
|
||||||
komodo_init(0);
|
//komodo_init(0);
|
||||||
n = block.vtx[0].vout[0].scriptPubKey.size();
|
n = block.vtx[0].vout[0].scriptPubKey.size();
|
||||||
if ( n == 35 )
|
if ( n == 35 )
|
||||||
memcpy(pubkey33,ptr+1,33);
|
memcpy(pubkey33,ptr+1,33);
|
||||||
@@ -461,7 +508,7 @@ int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex)
|
|||||||
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
|
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
|
||||||
{
|
{
|
||||||
CBlock block;
|
CBlock block;
|
||||||
komodo_init(height);
|
//komodo_init(height);
|
||||||
memset(pubkey33,0,33);
|
memset(pubkey33,0,33);
|
||||||
if ( pindex != 0 )
|
if ( pindex != 0 )
|
||||||
{
|
{
|
||||||
@@ -497,21 +544,41 @@ int8_t komodo_minerid(int32_t height)
|
|||||||
return(i);
|
return(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//printf("minderid not notary ht.%d\n",height);
|
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t komodo_minerids(uint8_t *minerids,int32_t height)
|
||||||
|
{
|
||||||
|
int32_t i,n=0;
|
||||||
|
for (i=0; i<1000; i++,n++)
|
||||||
|
{
|
||||||
|
if ( height-i <= 0 )
|
||||||
|
break;
|
||||||
|
minerids[i] = komodo_minerid(height - i);
|
||||||
|
}
|
||||||
|
return(n);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33])
|
int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33])
|
||||||
{
|
{
|
||||||
int32_t i,notaryid,minerid;
|
int32_t i,notaryid,minerid,limit;
|
||||||
komodo_chosennotary(¬aryid,height,pubkey33);
|
komodo_chosennotary(¬aryid,height,pubkey33);
|
||||||
if ( height >= 34000 && notaryid >= 0 )
|
if ( height >= 34000 && notaryid >= 0 )
|
||||||
{
|
{
|
||||||
for (i=1; i<64; i++)
|
if ( height < 79693 )
|
||||||
|
limit = 64;
|
||||||
|
else if ( height < 82000 )
|
||||||
|
limit = 8;
|
||||||
|
else limit = 66;
|
||||||
|
for (i=1; i<limit; i++)
|
||||||
{
|
{
|
||||||
if ( komodo_minerid(height-i) == notaryid )
|
if ( komodo_minerid(height-i) == notaryid )
|
||||||
|
{
|
||||||
|
//fprintf(stderr,"ht.%d notaryid.%d already mined -i.%d\n",height,notaryid,i);
|
||||||
return(-1);
|
return(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
//fprintf(stderr,"special notaryid.%d ht.%d limit.%d\n",notaryid,height,limit);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
@@ -519,12 +586,14 @@ int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33])
|
|||||||
|
|
||||||
int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash)
|
int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash)
|
||||||
{
|
{
|
||||||
int32_t notarized_height; uint256 notarized_hash,notarized_desttxid; CBlockIndex *notary;
|
int32_t notarized_height; uint256 notarized_hash,notarized_desttxid; CBlockIndex *notary; CBlockIndex *pindex;
|
||||||
notarized_height = komodo_notarizeddata(chainActive.Tip()->nHeight,¬arized_hash,¬arized_desttxid);
|
if ( (pindex= chainActive.Tip()) == 0 )
|
||||||
|
return(-1);
|
||||||
|
notarized_height = komodo_notarizeddata(pindex->nHeight,¬arized_hash,¬arized_desttxid);
|
||||||
*notarized_heightp = notarized_height;
|
*notarized_heightp = notarized_height;
|
||||||
if ( notarized_height >= 0 && notarized_height <= chainActive.Tip()->nHeight && (notary= mapBlockIndex[notarized_hash]) != 0 )
|
if ( notarized_height >= 0 && notarized_height <= pindex->nHeight && (notary= mapBlockIndex[notarized_hash]) != 0 )
|
||||||
{
|
{
|
||||||
//printf("nHeight.%d -> (%d %s)\n",chainActive.Tip()->nHeight,notarized_height,notarized_hash.ToString().c_str());
|
//printf("nHeight.%d -> (%d %s)\n",pindex->Tip()->nHeight,notarized_height,notarized_hash.ToString().c_str());
|
||||||
if ( notary->nHeight == notarized_height ) // if notarized_hash not in chain, reorg
|
if ( notary->nHeight == notarized_height ) // if notarized_hash not in chain, reorg
|
||||||
{
|
{
|
||||||
if ( nHeight < notarized_height )
|
if ( nHeight < notarized_height )
|
||||||
@@ -539,7 +608,7 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has
|
|||||||
}
|
}
|
||||||
} else fprintf(stderr,"unexpected error notary_hash %s ht.%d at ht.%d\n",notarized_hash.ToString().c_str(),notarized_height,notary->nHeight);
|
} else fprintf(stderr,"unexpected error notary_hash %s ht.%d at ht.%d\n",notarized_hash.ToString().c_str(),notarized_height,notary->nHeight);
|
||||||
} else if ( notarized_height > 0 && notarized_height != 73880 )
|
} else if ( notarized_height > 0 && notarized_height != 73880 )
|
||||||
fprintf(stderr,"couldnt find notary_hash %s ht.%d\n",notarized_hash.ToString().c_str(),notarized_height);
|
fprintf(stderr,"[%s] couldnt find notarized.(%s %d) ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,pindex->nHeight);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -577,3 +646,14 @@ uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256
|
|||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t komodo_isrealtime(int32_t *kmdheightp)
|
||||||
|
{
|
||||||
|
struct komodo_state *sp; CBlockIndex *pindex;
|
||||||
|
if ( (sp= komodo_stateptrget((char *)"KMD")) != 0 )
|
||||||
|
*kmdheightp = sp->CURRENT_HEIGHT;
|
||||||
|
else *kmdheightp = 0;
|
||||||
|
if ( (pindex= chainActive.Tip()) != 0 && pindex->nHeight == (int32_t)komodo_longestchain() )
|
||||||
|
return(1);
|
||||||
|
else return(0);
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,56 +16,23 @@
|
|||||||
#ifndef H_KOMODOEVENTS_H
|
#ifndef H_KOMODOEVENTS_H
|
||||||
#define H_KOMODOEVENTS_H
|
#define H_KOMODOEVENTS_H
|
||||||
|
|
||||||
|
struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen)
|
||||||
#ifdef WIN32
|
|
||||||
#define PACKED
|
|
||||||
#else
|
|
||||||
#define PACKED __attribute__((packed))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define KOMODO_EVENT_RATIFY 'P'
|
|
||||||
#define KOMODO_EVENT_NOTARIZED 'N'
|
|
||||||
#define KOMODO_EVENT_UTXO 'U'
|
|
||||||
#define KOMODO_EVENT_KMDHEIGHT 'K'
|
|
||||||
#define KOMODO_EVENT_REWIND 'B'
|
|
||||||
//#define KOMODO_EVENT_DELETE 'D'
|
|
||||||
#define KOMODO_EVENT_PRICEFEED 'V'
|
|
||||||
#define KOMODO_EVENT_OPRETURN 'R'
|
|
||||||
#define KOMODO_OPRETURN_DEPOSIT 'D'
|
|
||||||
#define KOMODO_OPRETURN_ISSUED 'I' // assetchain
|
|
||||||
#define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain
|
|
||||||
#define KOMODO_OPRETURN_REDEEMED 'X'
|
|
||||||
|
|
||||||
struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; };
|
|
||||||
struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; };
|
|
||||||
struct komodo_event_utxo { uint256 txid; uint64_t voutmask; uint8_t numvouts; };
|
|
||||||
struct komodo_event_opreturn { uint256 txid; uint64_t value; uint16_t vout,oplen; uint8_t opret[]; };
|
|
||||||
struct komodo_event_pricefeed { uint8_t num; uint32_t prices[35]; };
|
|
||||||
|
|
||||||
struct komodo_event
|
|
||||||
{
|
{
|
||||||
struct komodo_event *related;
|
struct komodo_event *ep=0; uint16_t len = (uint16_t)(sizeof(*ep) + datalen);
|
||||||
uint16_t len;
|
if ( sp != 0 )
|
||||||
int32_t height;
|
{
|
||||||
uint8_t type,reorged;
|
portable_mutex_lock(&komodo_mutex);
|
||||||
char symbol[16];
|
ep = (struct komodo_event *)calloc(1,len);
|
||||||
uint8_t space[];
|
ep->len = len;
|
||||||
} PACKED;
|
ep->height = height;
|
||||||
|
ep->type = type;
|
||||||
struct komodo_event **Komodo_events; int32_t Komodo_numevents;
|
strcpy(ep->symbol,symbol);
|
||||||
|
if ( datalen != 0 )
|
||||||
struct komodo_event *komodo_eventadd(int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen)
|
memcpy(ep->space,data,datalen);
|
||||||
{
|
sp->Komodo_events = (struct komodo_event **)realloc(sp->Komodo_events,(1 + sp->Komodo_numevents) * sizeof(*sp->Komodo_events));
|
||||||
struct komodo_event *ep; uint16_t len = (uint16_t)(sizeof(*ep) + datalen);
|
sp->Komodo_events[sp->Komodo_numevents++] = ep;
|
||||||
ep = (struct komodo_event *)calloc(1,len);
|
portable_mutex_unlock(&komodo_mutex);
|
||||||
ep->len = len;
|
}
|
||||||
ep->height = height;
|
|
||||||
ep->type = type;
|
|
||||||
strcpy(ep->symbol,symbol);
|
|
||||||
if ( datalen != 0 )
|
|
||||||
memcpy(ep->space,data,datalen);
|
|
||||||
Komodo_events = (struct komodo_event **)realloc(Komodo_events,(1 + Komodo_numevents) * sizeof(*Komodo_events));
|
|
||||||
Komodo_events[Komodo_numevents++] = ep;
|
|
||||||
return(ep);
|
return(ep);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +44,7 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig
|
|||||||
N.desttxid = notarized_desttxid;
|
N.desttxid = notarized_desttxid;
|
||||||
N.notarizedheight = notarizedheight;
|
N.notarizedheight = notarizedheight;
|
||||||
strcpy(N.dest,dest);
|
strcpy(N.dest,dest);
|
||||||
komodo_eventadd(height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N));
|
komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N));
|
||||||
if ( sp != 0 )
|
if ( sp != 0 )
|
||||||
komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid);
|
komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid);
|
||||||
}
|
}
|
||||||
@@ -85,48 +52,29 @@ 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])
|
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;
|
struct komodo_event_pubkeys P;
|
||||||
printf("eventadd pubkeys ht.%d\n",height);
|
//printf("eventadd pubkeys ht.%d\n",height);
|
||||||
memset(&P,0,sizeof(P));
|
memset(&P,0,sizeof(P));
|
||||||
P.num = num;
|
P.num = num;
|
||||||
memcpy(P.pubkeys,pubkeys,33 * num);
|
memcpy(P.pubkeys,pubkeys,33 * num);
|
||||||
komodo_eventadd(height,symbol,KOMODO_EVENT_RATIFY,(uint8_t *)&P,(int32_t)(sizeof(P.num) + 33 * num));
|
komodo_eventadd(sp,height,symbol,KOMODO_EVENT_RATIFY,(uint8_t *)&P,(int32_t)(sizeof(P.num) + 33 * num));
|
||||||
if ( sp != 0 )
|
if ( sp != 0 )
|
||||||
komodo_notarysinit(height,pubkeys,num);
|
komodo_notarysinit(height,pubkeys,num);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void komodo_eventadd_utxo(struct komodo_state *sp,char *symbol,int32_t height,uint8_t notaryid,uint256 txid,uint64_t voutmask,uint8_t numvouts)
|
|
||||||
{
|
|
||||||
struct komodo_event_utxo U;
|
|
||||||
memset(&U,0,sizeof(U));
|
|
||||||
U.txid = txid;
|
|
||||||
U.voutmask = voutmask;
|
|
||||||
U.numvouts = numvouts;
|
|
||||||
komodo_eventadd(height,symbol,KOMODO_EVENT_UTXO,(uint8_t *)&U,sizeof(U));
|
|
||||||
if ( sp != 0 )
|
|
||||||
komodo_nutxoadd(height,notaryid,txid,voutmask,numvouts);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void komodo_eventadd_pricefeed(struct komodo_state *sp,char *symbol,int32_t height,uint32_t *prices,uint8_t num)
|
void komodo_eventadd_pricefeed(struct komodo_state *sp,char *symbol,int32_t height,uint32_t *prices,uint8_t num)
|
||||||
{
|
{
|
||||||
struct komodo_event_pricefeed F;
|
struct komodo_event_pricefeed F;
|
||||||
memset(&F,0,sizeof(F));
|
memset(&F,0,sizeof(F));
|
||||||
F.num = num;
|
F.num = num;
|
||||||
memcpy(F.prices,prices,sizeof(*F.prices) * num);
|
memcpy(F.prices,prices,sizeof(*F.prices) * num);
|
||||||
komodo_eventadd(height,symbol,KOMODO_EVENT_PRICEFEED,(uint8_t *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num));
|
komodo_eventadd(sp,height,symbol,KOMODO_EVENT_PRICEFEED,(uint8_t *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num));
|
||||||
if ( sp != 0 )
|
if ( sp != 0 )
|
||||||
komodo_pvals(height,prices,num);
|
komodo_pvals(height,prices,num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void komodo_eventadd_kmdheight(struct komodo_state *sp,char *symbol,int32_t height,int32_t kmdheight)
|
|
||||||
{
|
|
||||||
komodo_eventadd(height,symbol,KOMODO_EVENT_KMDHEIGHT,(uint8_t *)&kmdheight,sizeof(kmdheight));
|
|
||||||
if ( sp != 0 )
|
|
||||||
komodo_setkmdheight(kmdheight);
|
|
||||||
}
|
|
||||||
|
|
||||||
void komodo_eventadd_opreturn(struct komodo_state *sp,char *symbol,int32_t height,uint256 txid,uint64_t value,uint16_t vout,uint8_t *buf,uint16_t opretlen)
|
void komodo_eventadd_opreturn(struct komodo_state *sp,char *symbol,int32_t height,uint256 txid,uint64_t value,uint16_t vout,uint8_t *buf,uint16_t opretlen)
|
||||||
{
|
{
|
||||||
struct komodo_event_opreturn O; uint8_t opret[10000];
|
struct komodo_event_opreturn O; uint8_t opret[16384];
|
||||||
memset(&O,0,sizeof(O));
|
memset(&O,0,sizeof(O));
|
||||||
O.txid = txid;
|
O.txid = txid;
|
||||||
O.value = value;
|
O.value = value;
|
||||||
@@ -134,21 +82,26 @@ void komodo_eventadd_opreturn(struct komodo_state *sp,char *symbol,int32_t heigh
|
|||||||
memcpy(opret,&O,sizeof(O));
|
memcpy(opret,&O,sizeof(O));
|
||||||
memcpy(&opret[sizeof(O)],buf,opretlen);
|
memcpy(&opret[sizeof(O)],buf,opretlen);
|
||||||
O.oplen = (int32_t)(opretlen + sizeof(O));
|
O.oplen = (int32_t)(opretlen + sizeof(O));
|
||||||
komodo_eventadd(height,symbol,KOMODO_EVENT_OPRETURN,opret,O.oplen);
|
komodo_eventadd(sp,height,symbol,KOMODO_EVENT_OPRETURN,opret,O.oplen);
|
||||||
if ( sp != 0 )
|
if ( sp != 0 )
|
||||||
komodo_opreturn(height,value,buf,opretlen,txid,vout);
|
komodo_opreturn(height,value,buf,opretlen,txid,vout,symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
void komodo_event_undo(struct komodo_event *ep)
|
void komodo_event_undo(struct komodo_state *sp,struct komodo_event *ep)
|
||||||
{
|
{
|
||||||
switch ( ep->type )
|
switch ( ep->type )
|
||||||
{
|
{
|
||||||
case KOMODO_EVENT_RATIFY:
|
case KOMODO_EVENT_RATIFY: printf("rewind of ratify, needs to be coded.%d\n",ep->height); break;
|
||||||
case KOMODO_EVENT_NOTARIZED:
|
case KOMODO_EVENT_NOTARIZED: printf("unexpected rewind of notarization.%d\n",ep->height); break;
|
||||||
case KOMODO_EVENT_UTXO:
|
|
||||||
case KOMODO_EVENT_KMDHEIGHT:
|
case KOMODO_EVENT_KMDHEIGHT:
|
||||||
|
if ( ep->height <= sp->SAVEDHEIGHT )
|
||||||
|
sp->SAVEDHEIGHT = ep->height;
|
||||||
|
break;
|
||||||
case KOMODO_EVENT_PRICEFEED:
|
case KOMODO_EVENT_PRICEFEED:
|
||||||
|
// backtrack prices;
|
||||||
|
break;
|
||||||
case KOMODO_EVENT_OPRETURN:
|
case KOMODO_EVENT_OPRETURN:
|
||||||
|
// backtrack opreturns
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,23 +109,57 @@ void komodo_event_undo(struct komodo_event *ep)
|
|||||||
void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height)
|
void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height)
|
||||||
{
|
{
|
||||||
struct komodo_event *ep;
|
struct komodo_event *ep;
|
||||||
komodo_eventadd(height,symbol,KOMODO_EVENT_REWIND,(uint8_t *)&height,sizeof(height));
|
|
||||||
if ( sp != 0 )
|
if ( sp != 0 )
|
||||||
{
|
{
|
||||||
while ( Komodo_numevents > 0 )
|
while ( sp->Komodo_events != 0 && sp->Komodo_numevents > 0 )
|
||||||
{
|
{
|
||||||
if ( (ep= Komodo_events[Komodo_numevents-1]) != 0 )
|
if ( (ep= sp->Komodo_events[sp->Komodo_numevents-1]) != 0 )
|
||||||
{
|
{
|
||||||
if ( ep->height < height )
|
if ( ep->height < height )
|
||||||
break;
|
break;
|
||||||
printf("undo event.%c ht.%d for rewind.%d\n",ep->type,ep->height,height);
|
//printf("[%s] undo %s event.%c ht.%d for rewind.%d\n",ASSETCHAINS_SYMBOL,symbol,ep->type,ep->height,height);
|
||||||
komodo_event_undo(ep);
|
komodo_event_undo(sp,ep);
|
||||||
Komodo_numevents--;
|
sp->Komodo_numevents--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void komodo_setkmdheight(struct komodo_state *sp,int32_t kmdheight,uint32_t timestamp)
|
||||||
|
{
|
||||||
|
if ( sp != 0 )
|
||||||
|
{
|
||||||
|
if ( kmdheight > sp->SAVEDHEIGHT )
|
||||||
|
{
|
||||||
|
sp->SAVEDHEIGHT = kmdheight;
|
||||||
|
sp->SAVEDTIMESTAMP = timestamp;
|
||||||
|
}
|
||||||
|
if ( kmdheight > sp->CURRENT_HEIGHT )
|
||||||
|
sp->CURRENT_HEIGHT = kmdheight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void komodo_eventadd_kmdheight(struct komodo_state *sp,char *symbol,int32_t height,int32_t kmdheight,uint32_t timestamp)
|
||||||
|
{
|
||||||
|
uint32_t buf[2];
|
||||||
|
if ( kmdheight > 0 )
|
||||||
|
{
|
||||||
|
buf[0] = (uint32_t)kmdheight;
|
||||||
|
buf[1] = timestamp;
|
||||||
|
komodo_eventadd(sp,height,symbol,KOMODO_EVENT_KMDHEIGHT,(uint8_t *)buf,sizeof(buf));
|
||||||
|
if ( sp != 0 )
|
||||||
|
komodo_setkmdheight(sp,kmdheight,timestamp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
kmdheight = -kmdheight;
|
||||||
|
komodo_eventadd(sp,height,symbol,KOMODO_EVENT_REWIND,(uint8_t *)&height,sizeof(height));
|
||||||
|
if ( sp != 0 )
|
||||||
|
komodo_event_rewind(sp,symbol,height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*void komodo_eventadd_deposit(int32_t actionflag,char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 kmdtxid,uint16_t kmdvout,uint64_t price)
|
/*void komodo_eventadd_deposit(int32_t actionflag,char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 kmdtxid,uint16_t kmdvout,uint64_t price)
|
||||||
{
|
{
|
||||||
uint8_t opret[512]; uint16_t opretlen;
|
uint8_t opret[512]; uint16_t opretlen;
|
||||||
|
|||||||
1009
src/komodo_gateway.h
1009
src/komodo_gateway.h
File diff suppressed because it is too large
Load Diff
@@ -13,43 +13,39 @@
|
|||||||
* *
|
* *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout);
|
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint32_t ktime,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout);
|
||||||
void komodo_init(int32_t height);
|
void komodo_init(int32_t height);
|
||||||
int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp);
|
int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp);
|
||||||
char *komodo_issuemethod(char *method,char *params,uint16_t port);
|
char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port);
|
||||||
void komodo_init(int32_t height);
|
void komodo_init(int32_t height);
|
||||||
void komodo_assetchain_pubkeys(char *jsonstr);
|
void komodo_assetchain_pubkeys(char *jsonstr);
|
||||||
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33);
|
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33);
|
||||||
|
int32_t komodo_isrealtime(int32_t *kmdheightp);
|
||||||
|
uint64_t komodo_paxtotal();
|
||||||
|
int32_t komodo_longestchain();
|
||||||
|
|
||||||
pthread_mutex_t komodo_mutex;
|
pthread_mutex_t komodo_mutex;
|
||||||
|
|
||||||
//FILE *Minerfp;
|
#define KOMODO_ELECTION_GAP 2000 //((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100)
|
||||||
//int8_t Minerids[KOMODO_MAXBLOCKS]; // 5 million blocks
|
|
||||||
#define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100)
|
|
||||||
|
|
||||||
int32_t KMDHEIGHT = 43000;
|
|
||||||
|
|
||||||
struct pax_transaction *PAX;
|
struct pax_transaction *PAX;
|
||||||
int32_t NUM_PRICES; uint32_t *PVALS;
|
int32_t NUM_PRICES; uint32_t *PVALS;
|
||||||
struct knotaries_entry *Pubkeys;
|
struct knotaries_entry *Pubkeys;
|
||||||
//struct nutxo_entry *NUTXOS; int32_t Num_nutxos;
|
|
||||||
struct notarized_checkpoint *NPOINTS; int32_t NUM_NPOINTS;
|
|
||||||
|
|
||||||
struct komodo_state KOMODO_STATES[33];
|
struct komodo_state KOMODO_STATES[34];
|
||||||
|
|
||||||
int COINBASE_MATURITY = 100;
|
int COINBASE_MATURITY = 100;
|
||||||
|
|
||||||
int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND;
|
int32_t IS_KOMODO_NOTARY,KOMODO_REWIND,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE;
|
||||||
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES;
|
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES;
|
||||||
uint8_t NOTARY_PUBKEY33[33];
|
uint8_t NOTARY_PUBKEY33[33];
|
||||||
|
|
||||||
int32_t ASSETCHAINS_SHORTFLAG;
|
|
||||||
char ASSETCHAINS_SYMBOL[16];
|
char ASSETCHAINS_SYMBOL[16];
|
||||||
uint16_t ASSETCHAINS_PORT;
|
uint16_t ASSETCHAINS_PORT;
|
||||||
uint32_t ASSETCHAIN_INIT;
|
uint32_t ASSETCHAIN_INIT;
|
||||||
uint32_t ASSETCHAINS_MAGIC = 2387029918;
|
uint32_t ASSETCHAINS_MAGIC = 2387029918;
|
||||||
uint64_t ASSETCHAINS_SUPPLY = 10;
|
uint64_t ASSETCHAINS_SUPPLY = 10;
|
||||||
|
|
||||||
uint32_t KOMODO_INITDONE,KOMODO_REALTIME;
|
uint32_t KOMODO_INITDONE;
|
||||||
char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771;
|
char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771;
|
||||||
uint64_t PENDING_KOMODO_TX;
|
uint64_t PENDING_KOMODO_TX;
|
||||||
|
|||||||
@@ -52,46 +52,15 @@ const char *Notaries_genesis[][2] =
|
|||||||
{ "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" },
|
{ "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" },
|
||||||
};
|
};
|
||||||
|
|
||||||
/*void komodo_nutxoadd(int32_t height,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts)
|
|
||||||
{
|
|
||||||
struct nutxo_entry *np;
|
|
||||||
if ( numvouts > 1 && notaryid < 64 )
|
|
||||||
{
|
|
||||||
pthread_mutex_lock(&komodo_mutex);
|
|
||||||
np = (struct nutxo_entry *)calloc(1,sizeof(*np));
|
|
||||||
np->height = height;
|
|
||||||
np->txhash = txhash;
|
|
||||||
np->voutmask = voutmask;
|
|
||||||
np->notaryid = notaryid;
|
|
||||||
HASH_ADD_KEYPTR(hh,NUTXOS,&np->txhash,sizeof(np->txhash),np);
|
|
||||||
//printf("Add NUTXO[%d] <- %s notaryid.%d t%u %s %llx\n",Num_nutxos,Notaries[notaryid][0],notaryid,komodo_txtime(txhash),txhash.ToString().c_str(),(long long)voutmask);
|
|
||||||
Num_nutxos++;
|
|
||||||
pthread_mutex_unlock(&komodo_mutex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t komodo_nutxofind(int32_t height,uint256 txhash,int32_t vout)
|
|
||||||
{
|
|
||||||
struct nutxo_entry *np;
|
|
||||||
pthread_mutex_lock(&komodo_mutex);
|
|
||||||
HASH_FIND(hh,NUTXOS,&txhash,sizeof(txhash),np);
|
|
||||||
pthread_mutex_unlock(&komodo_mutex);
|
|
||||||
if ( np != 0 && ((1LL << vout) & np->voutmask) != 0 )
|
|
||||||
return(np->notaryid);
|
|
||||||
return(-1);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask)
|
int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask)
|
||||||
{
|
{
|
||||||
int32_t htind,numnotaries,i,wt = 0;
|
int32_t htind,numnotaries,i,wt = 0;
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
|
||||||
return(2);
|
|
||||||
htind = height / KOMODO_ELECTION_GAP;
|
htind = height / KOMODO_ELECTION_GAP;
|
||||||
numnotaries = Pubkeys[htind].numnotaries;
|
numnotaries = Pubkeys[htind].numnotaries;
|
||||||
for (i=0; i<numnotaries; i++)
|
for (i=0; i<numnotaries; i++)
|
||||||
if ( ((1LL << i) & signedmask) != 0 )
|
if ( ((1LL << i) & signedmask) != 0 )
|
||||||
wt++;
|
wt++;
|
||||||
if ( wt > (numnotaries >> 1) || (wt > 7 && (signedmask & 3) != 0) )
|
if ( wt > (numnotaries >> 1) || (wt > 7 && (signedmask & 1) != 0) )
|
||||||
return(1);
|
return(1);
|
||||||
else return(0);
|
else return(0);
|
||||||
}
|
}
|
||||||
@@ -130,7 +99,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num)
|
|||||||
height /= KOMODO_ELECTION_GAP;
|
height /= KOMODO_ELECTION_GAP;
|
||||||
height = ((height + 1) * KOMODO_ELECTION_GAP);
|
height = ((height + 1) * KOMODO_ELECTION_GAP);
|
||||||
htind = (height / 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;
|
} else htind = 0;
|
||||||
pthread_mutex_lock(&komodo_mutex);
|
pthread_mutex_lock(&komodo_mutex);
|
||||||
for (k=0; k<num; k++)
|
for (k=0; k<num; k++)
|
||||||
@@ -139,7 +108,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num)
|
|||||||
memcpy(kp->pubkey,pubkeys[k],33);
|
memcpy(kp->pubkey,pubkeys[k],33);
|
||||||
kp->notaryid = k;
|
kp->notaryid = k;
|
||||||
HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp);
|
HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp);
|
||||||
//if ( height > 0 )
|
if ( 0 && height > 10000 )
|
||||||
{
|
{
|
||||||
for (i=0; i<33; i++)
|
for (i=0; i<33; i++)
|
||||||
printf("%02x",pubkeys[k][i]);
|
printf("%02x",pubkeys[k][i]);
|
||||||
@@ -166,6 +135,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33)
|
|||||||
{
|
{
|
||||||
// -1 if not notary, 0 if notary, 1 if special notary
|
// -1 if not notary, 0 if notary, 1 if special notary
|
||||||
struct knotary_entry *kp; int32_t numnotaries=0,htind,modval = -1;
|
struct knotary_entry *kp; int32_t numnotaries=0,htind,modval = -1;
|
||||||
|
komodo_init(0);
|
||||||
*notaryidp = -1;
|
*notaryidp = -1;
|
||||||
if ( height < 0 || height >= KOMODO_MAXBLOCKS )
|
if ( height < 0 || height >= KOMODO_MAXBLOCKS )
|
||||||
{
|
{
|
||||||
@@ -199,16 +169,18 @@ void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t not
|
|||||||
printf("komodo_notarized_update REJECT notarized_height %d > %d nHeight\n",notarized_height,nHeight);
|
printf("komodo_notarized_update REJECT notarized_height %d > %d nHeight\n",notarized_height,nHeight);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NPOINTS = (struct notarized_checkpoint *)realloc(NPOINTS,(NUM_NPOINTS+1) * sizeof(*NPOINTS));
|
portable_mutex_lock(&komodo_mutex);
|
||||||
np = &NPOINTS[NUM_NPOINTS++];
|
sp->NPOINTS = (struct notarized_checkpoint *)realloc(sp->NPOINTS,(sp->NUM_NPOINTS+1) * sizeof(*sp->NPOINTS));
|
||||||
|
np = &sp->NPOINTS[sp->NUM_NPOINTS++];
|
||||||
memset(np,0,sizeof(*np));
|
memset(np,0,sizeof(*np));
|
||||||
np->nHeight = nHeight;
|
np->nHeight = nHeight;
|
||||||
sp->NOTARIZED_HEIGHT = np->notarized_height = notarized_height;
|
sp->NOTARIZED_HEIGHT = np->notarized_height = notarized_height;
|
||||||
sp->NOTARIZED_HASH = np->notarized_hash = notarized_hash;
|
sp->NOTARIZED_HASH = np->notarized_hash = notarized_hash;
|
||||||
sp->NOTARIZED_DESTTXID = np->notarized_desttxid = notarized_desttxid;
|
sp->NOTARIZED_DESTTXID = np->notarized_desttxid = notarized_desttxid;
|
||||||
|
portable_mutex_unlock(&komodo_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct komodo_state *komodo_stateptr(char *symbol,char *dest);
|
//struct komodo_state *komodo_stateptr(char *symbol,char *dest);
|
||||||
int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp)
|
int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp)
|
||||||
{
|
{
|
||||||
char symbol[16],dest[16]; struct komodo_state *sp;
|
char symbol[16],dest[16]; struct komodo_state *sp;
|
||||||
@@ -228,21 +200,24 @@ int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp)
|
|||||||
|
|
||||||
int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp)
|
int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp)
|
||||||
{
|
{
|
||||||
struct notarized_checkpoint *np = 0; int32_t i;
|
struct notarized_checkpoint *np = 0; int32_t i; char symbol[16],dest[16]; struct komodo_state *sp;
|
||||||
if ( NUM_NPOINTS > 0 )
|
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
|
||||||
{
|
{
|
||||||
for (i=0; i<NUM_NPOINTS; i++)
|
if ( sp->NUM_NPOINTS > 0 )
|
||||||
{
|
{
|
||||||
if ( NPOINTS[i].nHeight >= nHeight )
|
for (i=0; i<sp->NUM_NPOINTS; i++)
|
||||||
break;
|
{
|
||||||
np = &NPOINTS[i];
|
if ( sp->NPOINTS[i].nHeight >= nHeight )
|
||||||
|
break;
|
||||||
|
np = &sp->NPOINTS[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( np != 0 )
|
||||||
|
{
|
||||||
|
*notarized_hashp = np->notarized_hash;
|
||||||
|
*notarized_desttxidp = np->notarized_desttxid;
|
||||||
|
return(np->notarized_height);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if ( np != 0 )
|
|
||||||
{
|
|
||||||
*notarized_hashp = np->notarized_hash;
|
|
||||||
*notarized_desttxidp = np->notarized_desttxid;
|
|
||||||
return(np->notarized_height);
|
|
||||||
}
|
}
|
||||||
memset(notarized_hashp,0,sizeof(*notarized_hashp));
|
memset(notarized_hashp,0,sizeof(*notarized_hashp));
|
||||||
return(0);
|
return(0);
|
||||||
@@ -271,7 +246,7 @@ void komodo_init(int32_t height)
|
|||||||
// Minerids[i] = -2;
|
// Minerids[i] = -2;
|
||||||
didinit = 1;
|
didinit = 1;
|
||||||
}
|
}
|
||||||
komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0,0,0);
|
komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0,0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void komodo_assetchain_pubkeys(char *jsonstr)
|
void komodo_assetchain_pubkeys(char *jsonstr)
|
||||||
@@ -299,6 +274,7 @@ void komodo_assetchain_pubkeys(char *jsonstr)
|
|||||||
{
|
{
|
||||||
komodo_init(-1);
|
komodo_init(-1);
|
||||||
komodo_notarysinit(0,pubkeys,n);
|
komodo_notarysinit(0,pubkeys,n);
|
||||||
|
KOMODO_EXTERNAL_NOTARIES = 1;
|
||||||
//printf("initialize pubkeys[%d]\n",n);
|
//printf("initialize pubkeys[%d]\n",n);
|
||||||
} else fprintf(stderr,"komodo_assetchain_pubkeys i.%d vs n.%d\n",i,n);
|
} else fprintf(stderr,"komodo_assetchain_pubkeys i.%d vs n.%d\n",i,n);
|
||||||
} else fprintf(stderr,"assetchain pubkeys n.%d\n",n);
|
} else fprintf(stderr,"assetchain pubkeys n.%d\n",n);
|
||||||
|
|||||||
204
src/komodo_pax.h
204
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
|
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)
|
uint64_t komodo_paxvol(uint64_t volume,uint64_t price)
|
||||||
{
|
{
|
||||||
if ( volume < 10000000000 )
|
if ( volume < 10000000000 )
|
||||||
@@ -285,20 +296,84 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals)
|
|||||||
KMDBTC = ((double)kmdbtc / (1000000000. * 1000.));
|
KMDBTC = ((double)kmdbtc / (1000000000. * 1000.));
|
||||||
BTCUSD = ((double)btcusd / (1000000000. / 1000.));
|
BTCUSD = ((double)btcusd / (1000000000. / 1000.));
|
||||||
CNYUSD = ((double)cnyusd / 1000000000.);
|
CNYUSD = ((double)cnyusd / 1000000000.);
|
||||||
|
portable_mutex_lock(&komodo_mutex);
|
||||||
PVALS = (uint32_t *)realloc(PVALS,(NUM_PRICES+1) * sizeof(*PVALS) * 36);
|
PVALS = (uint32_t *)realloc(PVALS,(NUM_PRICES+1) * sizeof(*PVALS) * 36);
|
||||||
PVALS[36 * NUM_PRICES] = height;
|
PVALS[36 * NUM_PRICES] = height;
|
||||||
memcpy(&PVALS[36 * NUM_PRICES + 1],pvals,sizeof(*pvals) * 35);
|
memcpy(&PVALS[36 * NUM_PRICES + 1],pvals,sizeof(*pvals) * 35);
|
||||||
NUM_PRICES++;
|
NUM_PRICES++;
|
||||||
|
portable_mutex_unlock(&komodo_mutex);
|
||||||
if ( 0 )
|
if ( 0 )
|
||||||
printf("OP_RETURN.%d KMD %.8f BTC %.6f CNY %.6f NUM_PRICES.%d (%llu %llu %llu)\n",height,KMDBTC,BTCUSD,CNYUSD,NUM_PRICES,(long long)kmdbtc,(long long)btcusd,(long long)cnyusd);
|
printf("OP_RETURN.%d KMD %.8f BTC %.6f CNY %.6f NUM_PRICES.%d (%llu %llu %llu)\n",height,KMDBTC,BTCUSD,CNYUSD,NUM_PRICES,(long long)kmdbtc,(long long)btcusd,(long long)cnyusd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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];
|
int32_t i,j,k,ind,zeroes,wt,nonz; int64_t delta; uint64_t lastprice,tolerance,den,densum,sum=0;
|
||||||
if ( basevolume > 10000*COIN )
|
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));
|
printf("paxcalc overflow %.8f\n",dstr(basevolume));
|
||||||
return(0);
|
return(0);
|
||||||
@@ -307,16 +382,20 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba
|
|||||||
{
|
{
|
||||||
if ( relid == MAX_CURRENCIES )
|
if ( relid == MAX_CURRENCIES )
|
||||||
{
|
{
|
||||||
kmdbtc = pvals[MAX_CURRENCIES];
|
if ( kmdbtc == 0 )
|
||||||
btcusd = pvals[MAX_CURRENCIES + 1];
|
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 )
|
if ( pvals[USD] != 0 && kmdbtc != 0 && btcusd != 0 )
|
||||||
{
|
{
|
||||||
baseusd = ((uint64_t)pvalb * 1000000000) / pvals[USD];
|
baseusd = (((uint64_t)pvalb * 1000000000) / pvals[USD]);
|
||||||
usdvol = komodo_paxvol(basevolume,baseusd) / MINDENOMS[baseid];
|
usdvol = komodo_paxvol(basevolume,baseusd);
|
||||||
usdkmd = ((uint64_t)btcusd * 1000000000) / kmdbtc;
|
usdkmd = ((uint64_t)kmdbtc * 1000000000) / btcusd;
|
||||||
//printf("base -> USD %llu, BTC %llu KMDUSD %llu\n",(long long)baseusd,(long long)btcusd,(long long)kmdusd);
|
//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)));
|
//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 printf("zero val in KMD conv %llu %llu %llu\n",(long long)pvals[USD],(long long)kmdbtc,(long long)btcusd);
|
||||||
}
|
}
|
||||||
else if ( baseid == relid )
|
else if ( baseid == relid )
|
||||||
@@ -343,16 +422,27 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba
|
|||||||
return(0);
|
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;
|
int32_t baseid=-1,relid=-1,i; uint32_t *ptr;
|
||||||
|
if ( height > 10 )
|
||||||
|
height -= 10;
|
||||||
if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 )
|
if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 )
|
||||||
{
|
{
|
||||||
for (i=NUM_PRICES-1; i>=0; i--)
|
for (i=NUM_PRICES-1; i>=0; i--)
|
||||||
{
|
{
|
||||||
ptr = &PVALS[36 * i];
|
ptr = &PVALS[36 * i];
|
||||||
if ( *ptr < height )
|
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);
|
} else printf("paxprice invalid base.%s %d, rel.%s %d\n",base,baseid,rel,relid);
|
||||||
return(0);
|
return(0);
|
||||||
@@ -360,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)
|
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];
|
int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,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 > 10000*COIN )
|
*seedp = komodo_seed(height);
|
||||||
|
if ( basevolume > KOMODO_PAXMAX )
|
||||||
{
|
{
|
||||||
printf("komodo_paxprice overflow %.8f\n",dstr(basevolume));
|
printf("komodo_paxprice overflow %.8f\n",dstr(basevolume));
|
||||||
return(0);
|
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));
|
numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds));
|
||||||
memset(votes,0,sizeof(votes));
|
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]);
|
||||||
|
}
|
||||||
|
kmdbtc = komodo_paxcorrelation(kmdbtcs,numvotes,*seedp) * 539;
|
||||||
|
btcusd = komodo_paxcorrelation(btcusds,numvotes,*seedp) * 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++;
|
zeroes++;
|
||||||
//printf("null price height.%d\n",height-i);
|
else nonz++;
|
||||||
//return(0);
|
|
||||||
} else sum += votes[i], nonz++;
|
|
||||||
//printf("%.8f, ",dstr(votes[i]));
|
|
||||||
}
|
}
|
||||||
if ( nonz <= (numvotes >> 1) )
|
if ( nonz <= (numvotes >> 1) )
|
||||||
return(0);
|
return(0);
|
||||||
sum /= nonz;
|
return(komodo_paxcorrelation(votes,numvotes,*seedp) * basevolume / 100000);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel)
|
int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel)
|
||||||
@@ -440,7 +494,7 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas
|
|||||||
{
|
{
|
||||||
ptr = &PVALS[36 * i];
|
ptr = &PVALS[36 * i];
|
||||||
heights[num] = *ptr;
|
heights[num] = *ptr;
|
||||||
prices[num] = komodo_paxcalc(&ptr[1],baseid,relid,COIN);
|
prices[num] = komodo_paxcalc(&ptr[1],baseid,relid,COIN,0,0);
|
||||||
num++;
|
num++;
|
||||||
if ( num >= max )
|
if ( num >= max )
|
||||||
return(num);
|
return(num);
|
||||||
@@ -454,22 +508,26 @@ void komodo_paxpricefeed(int32_t height,uint8_t *pricefeed,int32_t opretlen)
|
|||||||
double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; uint256 zero;
|
double KMDBTC,BTCUSD,CNYUSD; uint32_t numpvals,timestamp,pvals[128]; uint256 zero;
|
||||||
numpvals = dpow_readprices(pricefeed,×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals);
|
numpvals = dpow_readprices(pricefeed,×tamp,&KMDBTC,&BTCUSD,&CNYUSD,pvals);
|
||||||
memset(&zero,0,sizeof(zero));
|
memset(&zero,0,sizeof(zero));
|
||||||
komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0,0,0,0,0);
|
komodo_stateupdate(height,0,0,0,zero,0,0,pvals,numpvals,0,0,0,0,0,0);
|
||||||
//printf("komodo_paxpricefeed vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen);
|
//printf("komodo_paxpricefeed vout OP_RETURN.%d prices numpvals.%d opretlen.%d\n",height,numpvals,opretlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis)
|
uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *origbase,int64_t fiatoshis)
|
||||||
{
|
{
|
||||||
uint8_t shortflag = 0; char base[4]; int32_t i,baseid; uint8_t addrtype,rmd160[20]; int64_t komodoshis = 0;
|
uint8_t shortflag = 0; char base[4]; int32_t i,baseid; uint8_t addrtype,rmd160[20]; int64_t komodoshis = 0;
|
||||||
|
*seedp = 0;
|
||||||
if ( (baseid= komodo_baseid(origbase)) < 0 || baseid == MAX_CURRENCIES )
|
if ( (baseid= komodo_baseid(origbase)) < 0 || baseid == MAX_CURRENCIES )
|
||||||
|
{
|
||||||
|
printf("PAX_fiatdest illegal base.(%s)\n",origbase);
|
||||||
return(0);
|
return(0);
|
||||||
|
}
|
||||||
for (i=0; i<3; i++)
|
for (i=0; i<3; i++)
|
||||||
base[i] = toupper(origbase[i]);
|
base[i] = toupper(origbase[i]);
|
||||||
base[i] = 0;
|
base[i] = 0;
|
||||||
if ( fiatoshis < 0 )
|
if ( fiatoshis < 0 )
|
||||||
shortflag = 1, fiatoshis = -fiatoshis;
|
shortflag = 1, fiatoshis = -fiatoshis;
|
||||||
komodoshis = komodo_paxprice(seedp,height,base,(char *)"KMD",(uint64_t)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 seed.%llx\n",height,base,(double)fiatoshis/COIN,(double)komodoshis/COIN,(long long)*seedp);
|
||||||
if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) == 20 )
|
if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) == 20 )
|
||||||
{
|
{
|
||||||
PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,tokomodo != 0 ? &komodoshis : &fiatoshis);
|
PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,tokomodo != 0 ? &komodoshis : &fiatoshis);
|
||||||
|
|||||||
@@ -16,21 +16,52 @@
|
|||||||
#include "uthash.h"
|
#include "uthash.h"
|
||||||
#include "utlist.h"
|
#include "utlist.h"
|
||||||
|
|
||||||
|
/*#ifdef WIN32
|
||||||
|
#define PACKED
|
||||||
|
#else
|
||||||
|
#define PACKED __attribute__((packed))
|
||||||
|
#endif*/
|
||||||
|
|
||||||
#define GENESIS_NBITS 0x1f00ffff
|
#define GENESIS_NBITS 0x1f00ffff
|
||||||
#define KOMODO_MINRATIFY 7
|
#define KOMODO_MINRATIFY ((height < 90000) ? 7 : 11)
|
||||||
#define KOMODO_MAXBLOCKS 5000000
|
#define KOMODO_MAXBLOCKS 5000000
|
||||||
|
|
||||||
|
#define KOMODO_EVENT_RATIFY 'P'
|
||||||
|
#define KOMODO_EVENT_NOTARIZED 'N'
|
||||||
|
#define KOMODO_EVENT_KMDHEIGHT 'K'
|
||||||
|
#define KOMODO_EVENT_REWIND 'B'
|
||||||
|
#define KOMODO_EVENT_PRICEFEED 'V'
|
||||||
|
#define KOMODO_EVENT_OPRETURN 'R'
|
||||||
|
#define KOMODO_OPRETURN_DEPOSIT 'D'
|
||||||
|
#define KOMODO_OPRETURN_ISSUED 'I' // assetchain
|
||||||
|
#define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain
|
||||||
|
#define KOMODO_OPRETURN_REDEEMED 'X'
|
||||||
|
|
||||||
|
struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; };
|
||||||
|
struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; };
|
||||||
|
struct komodo_event_opreturn { uint256 txid; uint64_t value; uint16_t vout,oplen; uint8_t opret[]; };
|
||||||
|
struct komodo_event_pricefeed { uint8_t num; uint32_t prices[35]; };
|
||||||
|
|
||||||
|
struct komodo_event
|
||||||
|
{
|
||||||
|
struct komodo_event *related;
|
||||||
|
uint16_t len;
|
||||||
|
int32_t height;
|
||||||
|
uint8_t type,reorged;
|
||||||
|
char symbol[16];
|
||||||
|
uint8_t space[];
|
||||||
|
};
|
||||||
|
|
||||||
struct pax_transaction
|
struct pax_transaction
|
||||||
{
|
{
|
||||||
UT_hash_handle hh;
|
UT_hash_handle hh;
|
||||||
uint256 txid;
|
uint256 txid;
|
||||||
uint64_t komodoshis,fiatoshis;
|
uint64_t komodoshis,fiatoshis,validated;
|
||||||
int32_t marked,height,otherheight;
|
int32_t marked,height,otherheight,approved,didstats;
|
||||||
uint16_t vout;
|
uint16_t vout;
|
||||||
char symbol[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 knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; };
|
||||||
struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; };
|
struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; };
|
||||||
struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t nHeight,notarized_height; };
|
struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t nHeight,notarized_height; };
|
||||||
@@ -38,6 +69,10 @@ struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t
|
|||||||
struct komodo_state
|
struct komodo_state
|
||||||
{
|
{
|
||||||
uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID;
|
uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID;
|
||||||
int32_t CURRENT_HEIGHT,NOTARIZED_HEIGHT,rewinding;
|
int32_t SAVEDHEIGHT,CURRENT_HEIGHT,NOTARIZED_HEIGHT;
|
||||||
// gateway state
|
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;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1261,43 +1261,83 @@ void komodo_userpass(char *username,char *password,FILE *fp)
|
|||||||
free(rpcpassword);
|
free(rpcpassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void komodo_statefname(char *fname,char *symbol,char *str)
|
||||||
|
{
|
||||||
|
int32_t n,len;
|
||||||
|
sprintf(fname,"%s",GetDataDir(false).string().c_str());
|
||||||
|
if ( (n= (int32_t)strlen(ASSETCHAINS_SYMBOL)) != 0 )
|
||||||
|
{
|
||||||
|
len = (int32_t)strlen(fname);
|
||||||
|
if ( strcmp(ASSETCHAINS_SYMBOL,&fname[len - n]) == 0 )
|
||||||
|
fname[len - n] = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("unexpected fname.(%s) vs %s [%s] n.%d len.%d (%s)\n",fname,symbol,ASSETCHAINS_SYMBOL,n,len,&fname[len - n]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
strcat(fname,"\\");
|
||||||
|
#else
|
||||||
|
strcat(fname,"/");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if ( symbol != 0 && symbol[0] != 0 && strcmp("KMD",symbol) != 0 )
|
||||||
|
{
|
||||||
|
strcat(fname,symbol);
|
||||||
|
//printf("statefname.(%s) -> (%s)\n",symbol,fname);
|
||||||
|
#ifdef WIN32
|
||||||
|
strcat(fname,"\\");
|
||||||
|
#else
|
||||||
|
strcat(fname,"/");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
strcat(fname,str);
|
||||||
|
//printf("test.(%s) -> [%s] statename.(%s) %s\n",test,ASSETCHAINS_SYMBOL,symbol,fname);
|
||||||
|
}
|
||||||
|
|
||||||
void komodo_configfile(char *symbol,uint16_t port)
|
void komodo_configfile(char *symbol,uint16_t port)
|
||||||
{
|
{
|
||||||
static char myusername[512],mypassword[8192];
|
static char myusername[512],mypassword[8192];
|
||||||
FILE *fp; uint8_t buf2[33]; char fname[512],buf[128],username[512],password[8192]; uint32_t crc,r,r2,i;
|
FILE *fp; uint8_t buf2[33]; char fname[512],buf[128],username[512],password[8192]; uint32_t crc,r,r2,i;
|
||||||
r = (uint32_t)time(NULL);
|
if ( symbol != 0 && port != 0 )
|
||||||
r2 = OS_milliseconds();
|
{
|
||||||
memcpy(buf,&r,sizeof(r));
|
r = (uint32_t)time(NULL);
|
||||||
memcpy(&buf[sizeof(r)],&r2,sizeof(r2));
|
r2 = OS_milliseconds();
|
||||||
memcpy(&buf[sizeof(r)+sizeof(r2)],symbol,strlen(symbol));
|
memcpy(buf,&r,sizeof(r));
|
||||||
crc = calc_crc32(0,(uint8_t *)buf,(int32_t)(sizeof(r)+sizeof(r2)+strlen(symbol)));
|
memcpy(&buf[sizeof(r)],&r2,sizeof(r2));
|
||||||
OS_randombytes(buf2,sizeof(buf2));
|
memcpy(&buf[sizeof(r)+sizeof(r2)],symbol,strlen(symbol));
|
||||||
for (i=0; i<sizeof(buf2); i++)
|
crc = calc_crc32(0,(uint8_t *)buf,(int32_t)(sizeof(r)+sizeof(r2)+strlen(symbol)));
|
||||||
sprintf(&password[i*2],"%02x",buf2[i]);
|
OS_randombytes(buf2,sizeof(buf2));
|
||||||
password[i*2] = 0;
|
for (i=0; i<sizeof(buf2); i++)
|
||||||
sprintf(buf,"%s.conf",symbol);
|
sprintf(&password[i*2],"%02x",buf2[i]);
|
||||||
BITCOIND_PORT = port;
|
password[i*2] = 0;
|
||||||
|
sprintf(buf,"%s.conf",symbol);
|
||||||
|
BITCOIND_PORT = port;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),buf);
|
sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),buf);
|
||||||
#else
|
#else
|
||||||
sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),buf);
|
sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),buf);
|
||||||
#endif
|
#endif
|
||||||
if ( (fp= fopen(fname,"rb")) == 0 )
|
if ( (fp= fopen(fname,"rb")) == 0 )
|
||||||
{
|
|
||||||
if ( (fp= fopen(fname,"wb")) != 0 )
|
|
||||||
{
|
{
|
||||||
fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\n\n",crc,password,port);
|
if ( (fp= fopen(fname,"wb")) != 0 )
|
||||||
|
{
|
||||||
|
fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\n\n",crc,password,port);
|
||||||
|
fclose(fp);
|
||||||
|
printf("Created (%s)\n",fname);
|
||||||
|
} else printf("Couldnt create (%s)\n",fname);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
komodo_userpass(myusername,mypassword,fp);
|
||||||
|
mapArgs["-rpcpassword"] = mypassword;
|
||||||
|
mapArgs["-rpcusername"] = myusername;
|
||||||
|
//fprintf(stderr,"myusername.(%s)\n",myusername);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
printf("Created (%s)\n",fname);
|
}
|
||||||
} else printf("Couldnt create (%s)\n",fname);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
komodo_userpass(myusername,mypassword,fp);
|
|
||||||
mapArgs["-rpcpassword"] = mypassword;
|
|
||||||
mapArgs["-rpcusername"] = myusername;
|
|
||||||
//fprintf(stderr,"myusername.(%s)\n",myusername);
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
strcpy(fname,GetDataDir().string().c_str());
|
strcpy(fname,GetDataDir().string().c_str());
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -1309,25 +1349,45 @@ void komodo_configfile(char *symbol,uint16_t port)
|
|||||||
fname[strlen(fname)-1] = 0;
|
fname[strlen(fname)-1] = 0;
|
||||||
strcat(fname,"komodo.conf");
|
strcat(fname,"komodo.conf");
|
||||||
#endif
|
#endif
|
||||||
//printf("KOMODO.(%s)\n",fname);
|
|
||||||
if ( (fp= fopen(fname,"rb")) != 0 )
|
if ( (fp= fopen(fname,"rb")) != 0 )
|
||||||
{
|
{
|
||||||
komodo_userpass(username,password,fp);
|
komodo_userpass(username,password,fp);
|
||||||
sprintf(KMDUSERPASS,"%s:%s",username,password);
|
sprintf(KMDUSERPASS,"%s:%s",username,password);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
//printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS);
|
||||||
} else printf("couldnt open.(%s)\n",fname);
|
} else printf("couldnt open.(%s)\n",fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t komodo_userpass(char *userpass,char *symbol)
|
||||||
|
{
|
||||||
|
FILE *fp; char fname[512],username[512],password[512],confname[16];
|
||||||
|
userpass[0] = 0;
|
||||||
|
if ( strcmp("KMD",symbol) == 0 )
|
||||||
|
sprintf(confname,"komodo.conf");
|
||||||
|
else sprintf(confname,"%s.conf",symbol);
|
||||||
|
komodo_statefname(fname,symbol,confname);
|
||||||
|
if ( (fp= fopen(fname,"rb")) != 0 )
|
||||||
|
{
|
||||||
|
komodo_userpass(username,password,fp);
|
||||||
|
sprintf(userpass,"%s:%s",username,password);
|
||||||
|
fclose(fp);
|
||||||
|
return((int32_t)strlen(userpass));
|
||||||
|
}
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t komodo_assetmagic(char *symbol,uint64_t supply)
|
uint32_t komodo_assetmagic(char *symbol,uint64_t supply)
|
||||||
{
|
{
|
||||||
uint8_t buf[512]; int32_t len = 0;
|
uint8_t buf[512]; int32_t len = 0;
|
||||||
|
if ( strcmp(symbol,"KMD") == 0 )
|
||||||
|
return(0x8de4eef9);
|
||||||
len = iguana_rwnum(1,&buf[len],sizeof(supply),(void *)&supply);
|
len = iguana_rwnum(1,&buf[len],sizeof(supply),(void *)&supply);
|
||||||
strcpy((char *)&buf[len],symbol);
|
strcpy((char *)&buf[len],symbol);
|
||||||
len += strlen(symbol);
|
len += strlen(symbol);
|
||||||
return(calc_crc32(0,buf,len));
|
return(calc_crc32(0,buf,len));
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_shortflag(char *symbol)
|
/*int32_t komodo_shortflag(char *symbol)
|
||||||
{
|
{
|
||||||
int32_t i,shortflag = 0;
|
int32_t i,shortflag = 0;
|
||||||
if ( symbol[0] == '-' )
|
if ( symbol[0] == '-' )
|
||||||
@@ -1338,26 +1398,32 @@ int32_t komodo_shortflag(char *symbol)
|
|||||||
symbol[i] = 0;
|
symbol[i] = 0;
|
||||||
}
|
}
|
||||||
return(shortflag);
|
return(shortflag);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
uint16_t komodo_assetport(uint32_t magic)
|
||||||
|
{
|
||||||
|
if ( magic == 0x8de4eef9 )
|
||||||
|
return(7770);
|
||||||
|
else return(8000 + (magic % 7777));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t komodo_assetport(uint32_t magic,int32_t shortflag)
|
uint16_t komodo_port(char *symbol,uint64_t supply,uint32_t *magicp)
|
||||||
{
|
|
||||||
return(8000 + shortflag*7777 + (magic % 7777));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t komodo_port(char *symbol,uint64_t supply,uint32_t *magicp,int32_t *shortflagp)
|
|
||||||
{
|
{
|
||||||
|
if ( symbol == 0 || symbol[0] == 0 || strcmp("KMD",symbol) == 0 )
|
||||||
|
{
|
||||||
|
*magicp = 0x8de4eef9;
|
||||||
|
return(7770);
|
||||||
|
}
|
||||||
*magicp = komodo_assetmagic(symbol,supply);
|
*magicp = komodo_assetmagic(symbol,supply);
|
||||||
*shortflagp = komodo_shortflag(symbol);
|
return(komodo_assetport(*magicp));
|
||||||
return(komodo_assetport(*magicp,*shortflagp));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void komodo_ports(uint16_t ports[MAX_CURRENCIES])
|
void komodo_ports(uint16_t ports[MAX_CURRENCIES])
|
||||||
{
|
{
|
||||||
int32_t i,shortflag; uint32_t magic;
|
int32_t i; uint32_t magic;
|
||||||
for (i=0; i<MAX_CURRENCIES; i++)
|
for (i=0; i<MAX_CURRENCIES; i++)
|
||||||
{
|
{
|
||||||
ports[i] = komodo_port(CURRENCIES[i],10,&magic,&shortflag);
|
ports[i] = komodo_port(CURRENCIES[i],10,&magic);
|
||||||
printf("%u ",ports[i]);
|
printf("%u ",ports[i]);
|
||||||
}
|
}
|
||||||
printf("ports\n");
|
printf("ports\n");
|
||||||
@@ -1366,6 +1432,16 @@ void komodo_ports(uint16_t ports[MAX_CURRENCIES])
|
|||||||
char *iguanafmtstr = (char *)"curl --url \"http://127.0.0.1:7778\" --data \"{\\\"conf\\\":\\\"%s.conf\\\",\\\"path\\\":\\\"${HOME#\"/\"}/.komodo/%s\\\",\\\"unitval\\\":\\\"20\\\",\\\"zcash\\\":1,\\\"RELAY\\\":1,\\\"VALIDATE\\\":1,\\\"prefetchlag\\\":-1,\\\"poll\\\":100,\\\"active\\\":1,\\\"agent\\\":\\\"iguana\\\",\\\"method\\\":\\\"addcoin\\\",\\\"startpend\\\":4,\\\"endpend\\\":4,\\\"services\\\":129,\\\"maxpeers\\\":8,\\\"newcoin\\\":\\\"%s\\\",\\\"name\\\":\\\"%s\\\",\\\"hasheaders\\\":1,\\\"useaddmultisig\\\":0,\\\"netmagic\\\":\\\"%s\\\",\\\"p2p\\\":%u,\\\"rpc\\\":%u,\\\"pubval\\\":60,\\\"p2shval\\\":85,\\\"wifval\\\":188,\\\"txfee_satoshis\\\":\\\"10000\\\",\\\"isPoS\\\":0,\\\"minoutput\\\":10000,\\\"minconfirms\\\":2,\\\"genesishash\\\":\\\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\\\",\\\"protover\\\":170002,\\\"genesisblock\\\":\\\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\\\",\\\"debug\\\":0,\\\"seedipaddr\\\":\\\"%s\\\"}\"";
|
char *iguanafmtstr = (char *)"curl --url \"http://127.0.0.1:7778\" --data \"{\\\"conf\\\":\\\"%s.conf\\\",\\\"path\\\":\\\"${HOME#\"/\"}/.komodo/%s\\\",\\\"unitval\\\":\\\"20\\\",\\\"zcash\\\":1,\\\"RELAY\\\":1,\\\"VALIDATE\\\":1,\\\"prefetchlag\\\":-1,\\\"poll\\\":100,\\\"active\\\":1,\\\"agent\\\":\\\"iguana\\\",\\\"method\\\":\\\"addcoin\\\",\\\"startpend\\\":4,\\\"endpend\\\":4,\\\"services\\\":129,\\\"maxpeers\\\":8,\\\"newcoin\\\":\\\"%s\\\",\\\"name\\\":\\\"%s\\\",\\\"hasheaders\\\":1,\\\"useaddmultisig\\\":0,\\\"netmagic\\\":\\\"%s\\\",\\\"p2p\\\":%u,\\\"rpc\\\":%u,\\\"pubval\\\":60,\\\"p2shval\\\":85,\\\"wifval\\\":188,\\\"txfee_satoshis\\\":\\\"10000\\\",\\\"isPoS\\\":0,\\\"minoutput\\\":10000,\\\"minconfirms\\\":2,\\\"genesishash\\\":\\\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\\\",\\\"protover\\\":170002,\\\"genesisblock\\\":\\\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\\\",\\\"debug\\\":0,\\\"seedipaddr\\\":\\\"%s\\\"}\"";
|
||||||
|
|
||||||
|
|
||||||
|
int32_t komodo_whoami(char *pubkeystr,int32_t height)
|
||||||
|
{
|
||||||
|
int32_t i,notaryid;
|
||||||
|
for (i=0; i<33; i++)
|
||||||
|
sprintf(&pubkeystr[i<<1],"%02x",NOTARY_PUBKEY33[i]);
|
||||||
|
pubkeystr[66] = 0;
|
||||||
|
komodo_chosennotary(¬aryid,height,NOTARY_PUBKEY33);
|
||||||
|
return(notaryid);
|
||||||
|
}
|
||||||
|
|
||||||
void komodo_args()
|
void komodo_args()
|
||||||
{
|
{
|
||||||
std::string name,addn; char *dirname,fname[512],magicstr[9]; uint8_t magic[4]; FILE *fp; int32_t i,len;
|
std::string name,addn; char *dirname,fname[512],magicstr[9]; uint8_t magic[4]; FILE *fp; int32_t i,len;
|
||||||
@@ -1374,6 +1450,8 @@ void komodo_args()
|
|||||||
if ( strlen(NOTARY_PUBKEY.c_str()) == 66 )
|
if ( strlen(NOTARY_PUBKEY.c_str()) == 66 )
|
||||||
USE_EXTERNAL_PUBKEY = 1;
|
USE_EXTERNAL_PUBKEY = 1;
|
||||||
name = GetArg("-ac_name","");
|
name = GetArg("-ac_name","");
|
||||||
|
if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 )
|
||||||
|
;
|
||||||
if ( name.c_str()[0] != 0 )
|
if ( name.c_str()[0] != 0 )
|
||||||
{
|
{
|
||||||
ASSETCHAINS_SUPPLY = GetArg("-ac_supply",10);
|
ASSETCHAINS_SUPPLY = GetArg("-ac_supply",10);
|
||||||
@@ -1381,8 +1459,7 @@ void komodo_args()
|
|||||||
if ( strlen(addn.c_str()) > 0 )
|
if ( strlen(addn.c_str()) > 0 )
|
||||||
ASSETCHAINS_SEED = 1;
|
ASSETCHAINS_SEED = 1;
|
||||||
strncpy(ASSETCHAINS_SYMBOL,name.c_str(),sizeof(ASSETCHAINS_SYMBOL)-1);
|
strncpy(ASSETCHAINS_SYMBOL,name.c_str(),sizeof(ASSETCHAINS_SYMBOL)-1);
|
||||||
ASSETCHAINS_PORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,&ASSETCHAINS_SHORTFLAG);
|
ASSETCHAINS_PORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC);
|
||||||
//fprintf(stderr,"after args: %c%s port.%u magic.%08x supply.%u\n",ASSETCHAINS_SHORTFLAG!=0?'-':'+',ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT,ASSETCHAINS_MAGIC,(int32_t)ASSETCHAINS_SUPPLY);
|
|
||||||
while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 )
|
while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"waiting for datadir\n");
|
fprintf(stderr,"waiting for datadir\n");
|
||||||
@@ -1394,8 +1471,7 @@ void komodo_args()
|
|||||||
int32_t komodo_baseid(char *origbase);
|
int32_t komodo_baseid(char *origbase);
|
||||||
extern int COINBASE_MATURITY;
|
extern int COINBASE_MATURITY;
|
||||||
komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1);
|
komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1);
|
||||||
//if ( komodo_baseid(ASSETCHAINS_SYMBOL) >= 0 )
|
COINBASE_MATURITY = 1;
|
||||||
COINBASE_MATURITY = 1;
|
|
||||||
}
|
}
|
||||||
ASSETCHAINS_NOTARIES = GetArg("-ac_notaries","");
|
ASSETCHAINS_NOTARIES = GetArg("-ac_notaries","");
|
||||||
komodo_assetchain_pubkeys((char *)ASSETCHAINS_NOTARIES.c_str());
|
komodo_assetchain_pubkeys((char *)ASSETCHAINS_NOTARIES.c_str());
|
||||||
@@ -1413,32 +1489,59 @@ void komodo_args()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
char fname[512],username[512],password[4096]; FILE *fp;
|
||||||
ASSETCHAINS_PORT = 8777;
|
ASSETCHAINS_PORT = 8777;
|
||||||
//fprintf(stderr,"IS_KOMODO_NOTARY %d %s\n",IS_KOMODO_NOTARY,NOTARY_PUBKEY.c_str());
|
strcpy(fname,GetDataDir().string().c_str());
|
||||||
|
#ifdef WIN32
|
||||||
|
while ( fname[strlen(fname)-1] != '\\' )
|
||||||
|
fname[strlen(fname)-1] = 0;
|
||||||
|
strcat(fname,".komodo/komodo.conf");
|
||||||
|
#else
|
||||||
|
while ( fname[strlen(fname)-1] != '/' )
|
||||||
|
fname[strlen(fname)-1] = 0;
|
||||||
|
strcat(fname,".komodo/komodo.conf");
|
||||||
|
#endif
|
||||||
|
if ( (fp= fopen(fname,"rb")) != 0 )
|
||||||
|
{
|
||||||
|
komodo_userpass(username,password,fp);
|
||||||
|
sprintf(KMDUSERPASS,"%s:%s",username,password);
|
||||||
|
fclose(fp);
|
||||||
|
//printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS);
|
||||||
|
} else printf("couldnt open.(%s)\n",fname);
|
||||||
}
|
}
|
||||||
//fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL);
|
//fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct komodo_state *komodo_stateptr(char *symbol,char *dest)
|
void komodo_nameset(char *symbol,char *dest,char *source)
|
||||||
{
|
{
|
||||||
int32_t baseid; struct komodo_state *sp;
|
if ( source[0] == 0 )
|
||||||
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
|
||||||
{
|
{
|
||||||
strcpy(symbol,"KMD");
|
strcpy(symbol,(char *)"KMD");
|
||||||
strcpy(dest,"BTC");
|
strcpy(dest,(char *)"BTC");
|
||||||
sp = &KOMODO_STATES[0];
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(symbol,ASSETCHAINS_SYMBOL);
|
strcpy(symbol,source);
|
||||||
strcpy(dest,"KMD");
|
strcpy(dest,(char *)"KMD");
|
||||||
if ( (baseid= komodo_baseid(ASSETCHAINS_SYMBOL)) >= 0 )
|
|
||||||
sp = &KOMODO_STATES[baseid];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr,"komodo_stateupdate.(%s) not supported\n",ASSETCHAINS_SYMBOL);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return(sp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct komodo_state *komodo_stateptrget(char *base)
|
||||||
|
{
|
||||||
|
int32_t baseid;
|
||||||
|
if ( base == 0 || base[0] == 0 || strcmp(base,(char *)"KMD") == 0 )
|
||||||
|
return(&KOMODO_STATES[33]);
|
||||||
|
else if ( (baseid= komodo_baseid(base)) >= 0 )
|
||||||
|
return(&KOMODO_STATES[baseid+1]);
|
||||||
|
else return(&KOMODO_STATES[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct komodo_state *komodo_stateptr(char *symbol,char *dest)
|
||||||
|
{
|
||||||
|
int32_t baseid;
|
||||||
|
komodo_nameset(symbol,dest,ASSETCHAINS_SYMBOL);
|
||||||
|
return(komodo_stateptrget(symbol));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
30
src/main.cpp
30
src/main.cpp
@@ -538,7 +538,7 @@ CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& loc
|
|||||||
if (mi != mapBlockIndex.end())
|
if (mi != mapBlockIndex.end())
|
||||||
{
|
{
|
||||||
CBlockIndex* pindex = (*mi).second;
|
CBlockIndex* pindex = (*mi).second;
|
||||||
if (chain.Contains(pindex))
|
if (pindex != 0 && chain.Contains(pindex))
|
||||||
return pindex;
|
return pindex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -676,14 +676,18 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
|
|||||||
txnouttype whichType;
|
txnouttype whichType;
|
||||||
BOOST_FOREACH(const CTxOut& txout, tx.vout)
|
BOOST_FOREACH(const CTxOut& txout, tx.vout)
|
||||||
{
|
{
|
||||||
if (!::IsStandard(txout.scriptPubKey, whichType)) {
|
if (!::IsStandard(txout.scriptPubKey, whichType))
|
||||||
|
{
|
||||||
reason = "scriptpubkey";
|
reason = "scriptpubkey";
|
||||||
fprintf(stderr,"vout.%d nDataout.%d\n",v,nDataOut);
|
fprintf(stderr,">>>>>>>>>>>>>>> vout.%d nDataout.%d\n",v,nDataOut);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (whichType == TX_NULL_DATA)
|
if (whichType == TX_NULL_DATA)
|
||||||
|
{
|
||||||
nDataOut++;
|
nDataOut++;
|
||||||
|
//fprintf(stderr,"is OP_RETURN\n");
|
||||||
|
}
|
||||||
else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd)) {
|
else if ((whichType == TX_MULTISIG) && (!fIsBareMultisigStd)) {
|
||||||
reason = "bare-multisig";
|
reason = "bare-multisig";
|
||||||
return false;
|
return false;
|
||||||
@@ -1179,7 +1183,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
|||||||
view.GetBestBlock();
|
view.GetBestBlock();
|
||||||
|
|
||||||
nValueIn = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime);
|
nValueIn = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime);
|
||||||
if ( interest != 0 )
|
if ( 0 && interest != 0 )
|
||||||
fprintf(stderr,"add interest %.8f\n",(double)interest/COIN);
|
fprintf(stderr,"add interest %.8f\n",(double)interest/COIN);
|
||||||
// we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool
|
// we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool
|
||||||
view.SetBackend(dummy);
|
view.SetBackend(dummy);
|
||||||
@@ -2551,6 +2555,7 @@ static int64_t nTimePostConnect = 0;
|
|||||||
* corresponding to pindexNew, to bypass loading it again from disk.
|
* corresponding to pindexNew, to bypass loading it again from disk.
|
||||||
*/
|
*/
|
||||||
bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *pblock) {
|
bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *pblock) {
|
||||||
|
|
||||||
assert(pindexNew->pprev == chainActive.Tip());
|
assert(pindexNew->pprev == chainActive.Tip());
|
||||||
mempool.check(pcoinsTip);
|
mempool.check(pcoinsTip);
|
||||||
// Read block from disk.
|
// Read block from disk.
|
||||||
@@ -2689,6 +2694,7 @@ static void PruneBlockIndexCandidates() {
|
|||||||
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
|
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
|
||||||
*/
|
*/
|
||||||
static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMostWork, CBlock *pblock) {
|
static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMostWork, CBlock *pblock) {
|
||||||
|
extern int32_t KOMODO_REWIND;
|
||||||
AssertLockHeld(cs_main);
|
AssertLockHeld(cs_main);
|
||||||
bool fInvalidFound = false;
|
bool fInvalidFound = false;
|
||||||
const CBlockIndex *pindexOldTip = chainActive.Tip();
|
const CBlockIndex *pindexOldTip = chainActive.Tip();
|
||||||
@@ -2699,7 +2705,21 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
|
|||||||
if (!DisconnectTip(state))
|
if (!DisconnectTip(state))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if ( KOMODO_REWIND != 0 && chainActive.Tip()->nHeight > KOMODO_REWIND )
|
||||||
|
{
|
||||||
|
static int32_t didinit;
|
||||||
|
if ( didinit++ == 0 )
|
||||||
|
{
|
||||||
|
while (chainActive.Tip()->nHeight > KOMODO_REWIND )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight);
|
||||||
|
if ( !DisconnectTip(state) )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pindexOldTip = chainActive.Tip();
|
||||||
|
pindexFork = chainActive.FindFork(pindexMostWork);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Build list of new blocks to connect.
|
// Build list of new blocks to connect.
|
||||||
std::vector<CBlockIndex*> vpindexToConnect;
|
std::vector<CBlockIndex*> vpindexToConnect;
|
||||||
bool fContinue = true;
|
bool fContinue = true;
|
||||||
|
|||||||
@@ -99,8 +99,8 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define ASSETCHAINS_MINHEIGHT 100
|
#define ASSETCHAINS_MINHEIGHT 100
|
||||||
#define ROUNDROBIN_DELAY 45
|
#define ROUNDROBIN_DELAY 58
|
||||||
extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,ASSETCHAINS_SHORTFLAG,KOMODO_REALTIME;
|
extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE;
|
||||||
extern char ASSETCHAINS_SYMBOL[16];
|
extern char ASSETCHAINS_SYMBOL[16];
|
||||||
extern std::string NOTARY_PUBKEY;
|
extern std::string NOTARY_PUBKEY;
|
||||||
extern uint8_t NOTARY_PUBKEY33[33];
|
extern uint8_t NOTARY_PUBKEY33[33];
|
||||||
@@ -110,28 +110,32 @@ int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]);
|
|||||||
int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize);
|
int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize);
|
||||||
uint64_t komodo_paxtotal();
|
uint64_t komodo_paxtotal();
|
||||||
int32_t komodo_is_issuer();
|
int32_t komodo_is_issuer();
|
||||||
int32_t komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *symbol,int32_t tokomodo);
|
int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t tokomodo);
|
||||||
|
int32_t komodo_isrealtime(int32_t *kmdheightp);
|
||||||
|
|
||||||
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||||
{
|
{
|
||||||
uint64_t deposits; const CChainParams& chainparams = Params();
|
uint64_t deposits; int32_t isrealtime,kmdheight; const CChainParams& chainparams = Params();
|
||||||
// Create new block
|
// Create new block
|
||||||
unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
|
unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
|
||||||
if(!pblocktemplate.get())
|
if(!pblocktemplate.get())
|
||||||
return NULL;
|
return NULL;
|
||||||
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight >= 100 )
|
if ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d RT.%u KOMODO_ON_DEMAND.%d\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize(),KOMODO_REALTIME,KOMODO_ON_DEMAND);
|
isrealtime = komodo_isrealtime(&kmdheight);
|
||||||
while ( KOMODO_ON_DEMAND == 0 )//mempool.GetTotalTxSize() <= 0 )
|
while ( KOMODO_ON_DEMAND == 0 )
|
||||||
{
|
{
|
||||||
deposits = komodo_paxtotal();
|
deposits = komodo_paxtotal();
|
||||||
if ( KOMODO_INITDONE == 0 || KOMODO_REALTIME == 0 )
|
if ( KOMODO_INITDONE == 0 || (isrealtime= komodo_isrealtime(&kmdheight)) == 0 )
|
||||||
{
|
{
|
||||||
//fprintf(stderr,"INITDONE.%d RT.%d deposits %.8f\n",KOMODO_INITDONE,KOMODO_REALTIME,(double)deposits/COIN);
|
//fprintf(stderr,"INITDONE.%d RT.%d deposits %.8f ht.%d\n",KOMODO_INITDONE,isrealtime,(double)deposits/COIN,kmdheight);
|
||||||
}
|
}
|
||||||
else if ( deposits != 0 )
|
else if ( deposits != 0 )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d RT.%u KOMODO_ON_DEMAND.%d\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize(),isrealtime,KOMODO_ON_DEMAND);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
sleep(10);
|
sleep(10);
|
||||||
}
|
}
|
||||||
KOMODO_ON_DEMAND = 0;
|
KOMODO_ON_DEMAND = 0;
|
||||||
@@ -374,9 +378,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||||
{
|
{
|
||||||
int32_t i,opretlen; uint8_t opret[256],*ptr;
|
int32_t i,opretlen; uint8_t opret[256],*ptr;
|
||||||
if ( komodo_gateway_deposits(&txNew,0,(char *)"EUR",1) == 0 )
|
if ( (nHeight % 60) == 0 || komodo_gateway_deposits(&txNew,(char *)"KMD",1) == 0 )
|
||||||
{
|
{
|
||||||
if ( (opretlen= komodo_pax_opreturn(opret,sizeof(opret))) > 0 )
|
if ( (opretlen= komodo_pax_opreturn(opret,sizeof(opret))) > 0 ) // have pricefeed
|
||||||
{
|
{
|
||||||
txNew.vout.resize(2);
|
txNew.vout.resize(2);
|
||||||
txNew.vout[1].scriptPubKey.resize(opretlen);
|
txNew.vout[1].scriptPubKey.resize(opretlen);
|
||||||
@@ -390,8 +394,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
}
|
}
|
||||||
else if ( komodo_is_issuer() != 0 )
|
else if ( komodo_is_issuer() != 0 )
|
||||||
{
|
{
|
||||||
komodo_gateway_deposits(&txNew,0,ASSETCHAINS_SYMBOL,0);
|
komodo_gateway_deposits(&txNew,ASSETCHAINS_SYMBOL,0);
|
||||||
fprintf(stderr,"txNew numvouts.%d\n",(int32_t)txNew.vout.size());
|
if ( txNew.vout.size() > 1 )
|
||||||
|
fprintf(stderr,"%s txNew numvouts.%d\n",ASSETCHAINS_SYMBOL,(int32_t)txNew.vout.size());
|
||||||
}
|
}
|
||||||
pblock->vtx[0] = txNew;
|
pblock->vtx[0] = txNew;
|
||||||
pblocktemplate->vTxFees[0] = -nFees;
|
pblocktemplate->vTxFees[0] = -nFees;
|
||||||
@@ -445,6 +450,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
|
|||||||
//
|
//
|
||||||
// Internal miner
|
// Internal miner
|
||||||
//
|
//
|
||||||
|
int8_t komodo_minerid(int32_t height);
|
||||||
|
|
||||||
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
||||||
{
|
{
|
||||||
@@ -467,6 +473,12 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
|||||||
script[34] = OP_CHECKSIG;
|
script[34] = OP_CHECKSIG;
|
||||||
//scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
|
//scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
|
||||||
}
|
}
|
||||||
|
if ( 0 && ASSETCHAINS_SYMBOL[0] == 0 )
|
||||||
|
{
|
||||||
|
for (i=0; i<65; i++)
|
||||||
|
fprintf(stderr,"%d ",komodo_minerid(chainActive.Tip()->nHeight-i));
|
||||||
|
fprintf(stderr," minerids.special %d from ht.%d\n",komodo_is_special(chainActive.Tip()->nHeight+1,NOTARY_PUBKEY33),chainActive.Tip()->nHeight);
|
||||||
|
}
|
||||||
return CreateNewBlock(scriptPubKey);
|
return CreateNewBlock(scriptPubKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,7 +544,7 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
else solver = "default";
|
else solver = "default";
|
||||||
assert(solver == "tromp" || solver == "default");
|
assert(solver == "tromp" || solver == "default");
|
||||||
LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k);
|
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;
|
std::mutex m_cs;
|
||||||
bool cancelSolver = false;
|
bool cancelSolver = false;
|
||||||
boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
|
boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
|
||||||
@@ -548,8 +560,8 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
{
|
{
|
||||||
if (chainparams.MiningRequiresPeers())
|
if (chainparams.MiningRequiresPeers())
|
||||||
{
|
{
|
||||||
if ( ASSETCHAINS_SEED != 0 && chainActive.Tip()->nHeight < 100 )
|
//if ( ASSETCHAINS_SEED != 0 && chainActive.Tip()->nHeight < 100 )
|
||||||
break;
|
// break;
|
||||||
// Busy-wait for the network to come online so we don't waste time mining
|
// Busy-wait for the network to come online so we don't waste time mining
|
||||||
// on an obsolete chain. In regtest mode we expect to fly solo.
|
// on an obsolete chain. In regtest mode we expect to fly solo.
|
||||||
//fprintf(stderr,"Wait for peers...\n");
|
//fprintf(stderr,"Wait for peers...\n");
|
||||||
@@ -567,6 +579,11 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
} while (true);
|
} while (true);
|
||||||
//fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL);
|
//fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL);
|
||||||
}
|
}
|
||||||
|
/*while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight < ASSETCHAINS_MINHEIGHT )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"%s waiting for block 100, ht.%d\n",ASSETCHAINS_SYMBOL,chainActive.Tip()->nHeight);
|
||||||
|
sleep(3);
|
||||||
|
}*/
|
||||||
//
|
//
|
||||||
// Create new block
|
// Create new block
|
||||||
//
|
//
|
||||||
@@ -577,7 +594,7 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
Mining_height = pindexPrev->nHeight+1;
|
Mining_height = pindexPrev->nHeight+1;
|
||||||
Mining_start = (uint32_t)time(NULL);
|
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);
|
fprintf(stderr,"%s create new block ht.%d\n",ASSETCHAINS_SYMBOL,Mining_height);
|
||||||
|
|
||||||
unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey));
|
unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey));
|
||||||
@@ -598,11 +615,16 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_is_special(pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 )
|
if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_is_special(pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 )
|
||||||
{
|
{
|
||||||
hashTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS);
|
hashTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS);
|
||||||
//fprintf(stderr,"I am the chosen one for %s ht.%d\n",ASSETCHAINS_SYMBOL,pindexPrev->nHeight+1);
|
fprintf(stderr,"I am the chosen one for %s ht.%d\n",ASSETCHAINS_SYMBOL,pindexPrev->nHeight+1);
|
||||||
} else Mining_start = 0;
|
} else Mining_start = 0;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
//fprintf(stderr,"%s start mining loop\n",ASSETCHAINS_SYMBOL);
|
if ( ASSETCHAINS_SYMBOL[0] != 0 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT )
|
||||||
|
{
|
||||||
|
//fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL);
|
||||||
|
sleep(10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
// Hash state
|
// Hash state
|
||||||
KOMODO_CHOSEN_ONE = 0;
|
KOMODO_CHOSEN_ONE = 0;
|
||||||
crypto_generichash_blake2b_state state;
|
crypto_generichash_blake2b_state state;
|
||||||
@@ -629,16 +651,19 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
solutionTargetChecks.increment();
|
solutionTargetChecks.increment();
|
||||||
if ( UintToArith256(pblock->GetHash()) > hashTarget )
|
if ( UintToArith256(pblock->GetHash()) > hashTarget )
|
||||||
{
|
{
|
||||||
//if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
// printf("missed target\n");
|
fprintf(stderr,"missed target\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+ROUNDROBIN_DELAY )
|
if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+ROUNDROBIN_DELAY )
|
||||||
{
|
{
|
||||||
printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+ROUNDROBIN_DELAY-time(NULL)));
|
//printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+ROUNDROBIN_DELAY-time(NULL)));
|
||||||
sleep(Mining_start+ROUNDROBIN_DELAY-time(NULL));
|
int32_t nseconds = Mining_start+ROUNDROBIN_DELAY-time(NULL);
|
||||||
KOMODO_CHOSEN_ONE = 1;
|
if ( nseconds > 0 )
|
||||||
|
sleep(nseconds);
|
||||||
|
MilliSleep((rand() % 700) + 1);
|
||||||
}
|
}
|
||||||
|
KOMODO_CHOSEN_ONE = 1;
|
||||||
// Found a solution
|
// Found a solution
|
||||||
SetThreadPriority(THREAD_PRIORITY_NORMAL);
|
SetThreadPriority(THREAD_PRIORITY_NORMAL);
|
||||||
LogPrintf("KomodoMiner:\n");
|
LogPrintf("KomodoMiner:\n");
|
||||||
@@ -649,10 +674,6 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
cancelSolver = false;
|
cancelSolver = false;
|
||||||
}
|
}
|
||||||
KOMODO_CHOSEN_ONE = 0;
|
KOMODO_CHOSEN_ONE = 0;
|
||||||
int32_t i; uint256 hash = pblock->GetHash();
|
|
||||||
for (i=0; i<32; i++)
|
|
||||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
|
||||||
fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height);
|
|
||||||
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
||||||
// In regression test mode, stop mining after a block is found.
|
// In regression test mode, stop mining after a block is found.
|
||||||
if (chainparams.MineBlocksOnDemand()) {
|
if (chainparams.MineBlocksOnDemand()) {
|
||||||
@@ -706,6 +727,11 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
bool found = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled);
|
bool found = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled);
|
||||||
ehSolverRuns.increment();
|
ehSolverRuns.increment();
|
||||||
if (found) {
|
if (found) {
|
||||||
|
int32_t i; uint256 hash = pblock->GetHash();
|
||||||
|
for (i=0; i<32; i++)
|
||||||
|
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||||
|
fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height);
|
||||||
|
sleep(60); // avoid mining forks
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (EhSolverCancelledException&) {
|
} catch (EhSolverCancelledException&) {
|
||||||
@@ -720,25 +746,28 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
// Regtest mode doesn't require peers
|
// Regtest mode doesn't require peers
|
||||||
if (vNodes.empty() && chainparams.MiningRequiresPeers())
|
if (vNodes.empty() && chainparams.MiningRequiresPeers())
|
||||||
{
|
{
|
||||||
if ( ASSETCHAINS_SYMBOL[0] == 0 || Mining_height >= 100 )
|
if ( ASSETCHAINS_SYMBOL[0] == 0 || Mining_height > ASSETCHAINS_MINHEIGHT )
|
||||||
|
{
|
||||||
|
//fprintf(stderr,"no nodes, break\n");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff)
|
if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff)
|
||||||
{
|
{
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
printf("0xffff, break\n");
|
fprintf(stderr,"0xffff, break\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
|
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
|
||||||
{
|
{
|
||||||
//if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
// printf("timeout, break\n");
|
fprintf(stderr,"timeout, break\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( pindexPrev != chainActive.Tip() )
|
if ( pindexPrev != chainActive.Tip() )
|
||||||
{
|
{
|
||||||
//if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
// printf("Tip advanced, break\n");
|
fprintf(stderr,"Tip advanced, break\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Update nNonce and nTime
|
// Update nNonce and nTime
|
||||||
|
|||||||
44
src/pow.cpp
44
src/pow.cpp
@@ -108,11 +108,12 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33)
|
|||||||
int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]);
|
int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]);
|
||||||
int32_t komodo_currentheight();
|
int32_t komodo_currentheight();
|
||||||
extern int32_t KOMODO_CHOSEN_ONE;
|
extern int32_t KOMODO_CHOSEN_ONE;
|
||||||
//extern int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks
|
#define KOMODO_ELECTION_GAP 2000
|
||||||
|
|
||||||
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params)
|
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params)
|
||||||
{
|
{
|
||||||
bool fNegative,fOverflow; int32_t i,nonz=0,special,special2,notaryid,flag = 0;
|
extern int32_t KOMODO_REWIND;
|
||||||
|
bool fNegative,fOverflow; int32_t i,nonz=0,special,special2,notaryid=-1,flag = 0;
|
||||||
arith_uint256 bnTarget;
|
arith_uint256 bnTarget;
|
||||||
|
|
||||||
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
||||||
@@ -128,41 +129,32 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
|
|||||||
}
|
}
|
||||||
if ( nonz == 0 )
|
if ( nonz == 0 )
|
||||||
return(true); // will come back via different path with pubkey set
|
return(true); // will come back via different path with pubkey set
|
||||||
//if ( height > 60000 )
|
special2 = komodo_is_special(height,pubkey33);
|
||||||
|
if ( notaryid >= 0 && ((height >= 64000 && height <= 90065) || (height % KOMODO_ELECTION_GAP) > 64) )
|
||||||
{
|
{
|
||||||
if ( notaryid >= 0 )
|
//if ( special2 == -2 )
|
||||||
|
// printf("height.%d special2.%d special.%d\n",height,special2,special);
|
||||||
|
if ( (height >= 64000 && height <= 90065) || (height % KOMODO_ELECTION_GAP) == 0 || (height < 80000 && (special != 0 || special2 > 0)) || (height >= 80000 && special2 > 0) )
|
||||||
{
|
{
|
||||||
special2 = komodo_is_special(height,pubkey33);
|
|
||||||
if ( special2 == -2 )
|
|
||||||
printf("height.%d special2.%d special.%d\n",height,special2,special);
|
|
||||||
if ( special2 == -2 || (height < 70000 && (special != 0 || special2 > 0)) ||
|
|
||||||
(height >= 70000 && special2 > 0) )
|
|
||||||
{
|
|
||||||
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
|
||||||
flag = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*else
|
|
||||||
{
|
|
||||||
if ( special > 0 ) // special notary id == (height % numnotaries)
|
|
||||||
{
|
|
||||||
if (UintToArith256(hash) <= bnTarget) // accept normal diff
|
|
||||||
return true;
|
|
||||||
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||||
flag = 1;
|
flag = 1;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
|
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
|
||||||
return error("CheckProofOfWork(): nBits below minimum work");
|
return error("CheckProofOfWork(): nBits below minimum work");
|
||||||
// Check proof of work matches claimed amount
|
// Check proof of work matches claimed amount
|
||||||
if ( UintToArith256(hash) > bnTarget )
|
if ( UintToArith256(hash) > bnTarget )
|
||||||
{
|
{
|
||||||
//for (i=0; i<33; i++)
|
int32_t i;
|
||||||
// printf("%02x",pubkey33[i]);
|
for (i=31; i>=0; i--)
|
||||||
//printf(" special.%d notaryid.%d ht.%d mod.%d error\n",special,notaryid,height,(height % 35));
|
printf("%02x",((uint8_t *)&hash)[i]);
|
||||||
return error("CheckProofOfWork(): hash doesn't match nBits");
|
printf(" hash vs ");
|
||||||
|
for (i=31; i>=0; i--)
|
||||||
|
printf("%02x",((uint8_t *)&bnTarget)[i]);
|
||||||
|
printf(" ht.%d REWIND.%d special.%d notaryid.%d ht.%d mod.%d error\n",height,KOMODO_REWIND,special,notaryid,height,(height % 35));
|
||||||
|
if ( height <= KOMODO_REWIND )
|
||||||
|
return error("CheckProofOfWork(): hash doesn't match nBits");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ QT_TRANSLATE_NOOP("bitcoin-core", "Corrupted block database detected"),
|
|||||||
QT_TRANSLATE_NOOP("bitcoin-core", "Could not parse -rpcbind value %s as network address"),
|
QT_TRANSLATE_NOOP("bitcoin-core", "Could not parse -rpcbind value %s as network address"),
|
||||||
QT_TRANSLATE_NOOP("bitcoin-core", "Debugging/Testing options:"),
|
QT_TRANSLATE_NOOP("bitcoin-core", "Debugging/Testing options:"),
|
||||||
QT_TRANSLATE_NOOP("bitcoin-core", "Do not load the wallet and disable wallet RPC calls"),
|
QT_TRANSLATE_NOOP("bitcoin-core", "Do not load the wallet and disable wallet RPC calls"),
|
||||||
QT_TRANSLATE_NOOP("bitcoin-core", "Do you want to rebuild the block database now?"),
|
QT_TRANSLATE_NOOP("bitcoin-core", "error with HDD data, maybe just need to update to latest version"),
|
||||||
QT_TRANSLATE_NOOP("bitcoin-core", "Done loading"),
|
QT_TRANSLATE_NOOP("bitcoin-core", "Done loading"),
|
||||||
QT_TRANSLATE_NOOP("bitcoin-core", "Error initializing block database"),
|
QT_TRANSLATE_NOOP("bitcoin-core", "Error initializing block database"),
|
||||||
QT_TRANSLATE_NOOP("bitcoin-core", "Error initializing wallet database environment %s!"),
|
QT_TRANSLATE_NOOP("bitcoin-core", "Error initializing wallet database environment %s!"),
|
||||||
|
|||||||
@@ -272,6 +272,22 @@ Value getblockhash(const Array& params, bool fHelp)
|
|||||||
return pblockindex->GetBlockHash().GetHex();
|
return pblockindex->GetBlockHash().GetHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint256 _komodo_getblockhash(int32_t nHeight)
|
||||||
|
{
|
||||||
|
uint256 hash;
|
||||||
|
LOCK(cs_main);
|
||||||
|
if ( nHeight >= 0 && nHeight <= chainActive.Height() )
|
||||||
|
{
|
||||||
|
CBlockIndex* pblockindex = chainActive[nHeight];
|
||||||
|
hash = pblockindex->GetBlockHash();
|
||||||
|
int32_t i;
|
||||||
|
for (i=0; i<32; i++)
|
||||||
|
printf("%02x",((uint8_t *)&hash)[i]);
|
||||||
|
printf(" blockhash.%d\n",nHeight);
|
||||||
|
} else memset(&hash,0,sizeof(hash));
|
||||||
|
return(hash);
|
||||||
|
}
|
||||||
|
|
||||||
Value getblock(const Array& params, bool fHelp)
|
Value getblock(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||||
@@ -387,6 +403,58 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas
|
|||||||
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height);
|
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height);
|
||||||
char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len);
|
char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len);
|
||||||
uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n);
|
uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n);
|
||||||
|
int32_t komodo_minerids(uint8_t *minerids,int32_t height);
|
||||||
|
|
||||||
|
Value minerids(const Array& params, bool fHelp)
|
||||||
|
{
|
||||||
|
Object ret; Array a; uint8_t minerids[1000],pubkeys[64][33]; int32_t i,j,n,numnotaries,tally[65];
|
||||||
|
if ( fHelp || params.size() != 1 )
|
||||||
|
throw runtime_error("minerids needs height\n");
|
||||||
|
LOCK(cs_main);
|
||||||
|
int32_t height = atoi(params[0].get_str().c_str());
|
||||||
|
if ( height <= 0 )
|
||||||
|
height = chainActive.Tip()->nHeight;
|
||||||
|
if ( (n= komodo_minerids(minerids,height)) > 0 )
|
||||||
|
{
|
||||||
|
memset(tally,0,sizeof(tally));
|
||||||
|
numnotaries = komodo_notaries(pubkeys,height);
|
||||||
|
if ( numnotaries > 0 )
|
||||||
|
{
|
||||||
|
for (i=0; i<n; i++)
|
||||||
|
{
|
||||||
|
if ( minerids[i] >= numnotaries )
|
||||||
|
tally[64]++;
|
||||||
|
else tally[minerids[i]]++;
|
||||||
|
}
|
||||||
|
for (i=0; i<64; i++)
|
||||||
|
{
|
||||||
|
Object item; std::string hex,kmdaddress; char *hexstr,kmdaddr[64],*ptr; int32_t m;
|
||||||
|
hex.resize(66);
|
||||||
|
hexstr = (char *)hex.data();
|
||||||
|
for (j=0; j<33; j++)
|
||||||
|
sprintf(&hexstr[j*2],"%02x",pubkeys[i][j]);
|
||||||
|
item.push_back(Pair("notaryid", i));
|
||||||
|
|
||||||
|
bitcoin_address(kmdaddr,60,pubkeys[i],33);
|
||||||
|
m = (int32_t)strlen(kmdaddr);
|
||||||
|
kmdaddress.resize(m);
|
||||||
|
ptr = (char *)kmdaddress.data();
|
||||||
|
memcpy(ptr,kmdaddr,m);
|
||||||
|
item.push_back(Pair("KMDaddress", kmdaddress));
|
||||||
|
|
||||||
|
item.push_back(Pair("pubkey", hex));
|
||||||
|
item.push_back(Pair("blocks", tally[i]));
|
||||||
|
a.push_back(item);
|
||||||
|
}
|
||||||
|
Object item;
|
||||||
|
item.push_back(Pair("pubkey", (char *)"external miners"));
|
||||||
|
item.push_back(Pair("blocks", tally[64]));
|
||||||
|
a.push_back(item);
|
||||||
|
}
|
||||||
|
ret.push_back(Pair("mined", a));
|
||||||
|
} else ret.push_back(Pair("error", (char *)"couldnt extract minerids"));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
Value notaries(const Array& params, bool fHelp)
|
Value notaries(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
@@ -398,9 +466,9 @@ Value notaries(const Array& params, bool fHelp)
|
|||||||
if ( height < 0 )
|
if ( height < 0 )
|
||||||
height = 0;
|
height = 0;
|
||||||
//fprintf(stderr,"notaries as of height.%d\n",height);
|
//fprintf(stderr,"notaries as of height.%d\n",height);
|
||||||
if ( height > chainActive.Height()+20000 )
|
//if ( height > chainActive.Height()+20000 )
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
|
// throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
|
||||||
else
|
//else
|
||||||
{
|
{
|
||||||
if ( (n= komodo_notaries(pubkeys,height)) > 0 )
|
if ( (n= komodo_notaries(pubkeys,height)) > 0 )
|
||||||
{
|
{
|
||||||
@@ -436,6 +504,41 @@ Value notaries(const Array& params, bool fHelp)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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; 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;
|
||||||
|
}
|
||||||
|
|
||||||
Value paxprice(const Array& params, bool fHelp)
|
Value paxprice(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if ( fHelp || params.size() < 3 || params.size() > 4 )
|
if ( fHelp || params.size() < 3 || params.size() > 4 )
|
||||||
@@ -590,29 +693,6 @@ Value gettxout(const Array& params, bool fHelp)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t gettxout_scriptPubKey(uint8_t *scriptPubKey,int32_t maxsize,uint256 txid,int32_t n)
|
|
||||||
{
|
|
||||||
int32_t i,m; uint8_t *ptr;
|
|
||||||
LOCK(cs_main);
|
|
||||||
CCoins coins;
|
|
||||||
if ( 1 )
|
|
||||||
{
|
|
||||||
LOCK(mempool.cs);
|
|
||||||
CCoinsViewMemPool view(pcoinsTip,mempool);
|
|
||||||
if ( view.GetCoins(txid,coins) == 0 )
|
|
||||||
return(-1);
|
|
||||||
mempool.pruneSpent(txid, coins); // TODO: this should be done by the CCoinsViewMemPool
|
|
||||||
} else if ( pcoinsTip->GetCoins(txid,coins) == 0 )
|
|
||||||
return(-1);
|
|
||||||
if ( n < 0 || (unsigned int)n >= coins.vout.size() || coins.vout[n].IsNull() )
|
|
||||||
return(-1);
|
|
||||||
ptr = (uint8_t *)coins.vout[n].scriptPubKey.data();
|
|
||||||
m = coins.vout[n].scriptPubKey.size();
|
|
||||||
for (i=0; i<maxsize&&i<m; i++)
|
|
||||||
scriptPubKey[i] = ptr[i];
|
|
||||||
return(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
Value verifychain(const Array& params, bool fHelp)
|
Value verifychain(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() > 2)
|
if (fHelp || params.size() > 2)
|
||||||
|
|||||||
@@ -108,7 +108,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||||||
{ "z_importkey", 1 },
|
{ "z_importkey", 1 },
|
||||||
{ "paxprice", 4 },
|
{ "paxprice", 4 },
|
||||||
{ "paxprices", 3 },
|
{ "paxprices", 3 },
|
||||||
|
{ "paxpending", 0 },
|
||||||
{ "notaries", 1 },
|
{ "notaries", 1 },
|
||||||
|
{ "minerids", 1 },
|
||||||
};
|
};
|
||||||
|
|
||||||
class CRPCConvertTable
|
class CRPCConvertTable
|
||||||
|
|||||||
@@ -40,12 +40,14 @@ using namespace std;
|
|||||||
* Or alternatively, create a specific query method for the information.
|
* Or alternatively, create a specific query method for the information.
|
||||||
**/
|
**/
|
||||||
uint64_t komodo_interestsum();
|
uint64_t komodo_interestsum();
|
||||||
|
int32_t komodo_longestchain();
|
||||||
int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp);
|
int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp);
|
||||||
|
int32_t komodo_whoami(char *pubkeystr,int32_t height);
|
||||||
|
|
||||||
Value getinfo(const Array& params, bool fHelp)
|
Value getinfo(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
uint256 notarized_hash,notarized_desttxid;
|
uint256 notarized_hash,notarized_desttxid;
|
||||||
int32_t notarized_height;
|
int32_t notarized_height,longestchain;
|
||||||
if (fHelp || params.size() != 0)
|
if (fHelp || params.size() != 0)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"getinfo\n"
|
"getinfo\n"
|
||||||
@@ -98,6 +100,9 @@ Value getinfo(const Array& params, bool fHelp)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
obj.push_back(Pair("blocks", (int)chainActive.Height()));
|
obj.push_back(Pair("blocks", (int)chainActive.Height()));
|
||||||
|
if ( (longestchain= komodo_longestchain()) != 0 && chainActive.Height() > longestchain )
|
||||||
|
longestchain = chainActive.Height();
|
||||||
|
obj.push_back(Pair("longestchain", longestchain));
|
||||||
obj.push_back(Pair("timeoffset", GetTimeOffset()));
|
obj.push_back(Pair("timeoffset", GetTimeOffset()));
|
||||||
if ( chainActive.Tip() != 0 )
|
if ( chainActive.Tip() != 0 )
|
||||||
obj.push_back(Pair("tiptime", (int)chainActive.Tip()->nTime));
|
obj.push_back(Pair("tiptime", (int)chainActive.Tip()->nTime));
|
||||||
@@ -116,6 +121,12 @@ Value getinfo(const Array& params, bool fHelp)
|
|||||||
#endif
|
#endif
|
||||||
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
|
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
|
||||||
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
||||||
|
{
|
||||||
|
char pubkeystr[65]; int32_t notaryid;
|
||||||
|
notaryid = komodo_whoami(pubkeystr,longestchain);
|
||||||
|
obj.push_back(Pair("notaryid", notaryid));
|
||||||
|
obj.push_back(Pair("pubkey", pubkeystr));
|
||||||
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -165,6 +165,36 @@ Value getpeerinfo(const Array& params, bool fHelp)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t komodo_longestchain()
|
||||||
|
{
|
||||||
|
int32_t ht,n=0,num=0,maxheight=0,height = 0;
|
||||||
|
LOCK(cs_main);
|
||||||
|
vector<CNodeStats> vstats;
|
||||||
|
CopyNodeStats(vstats);
|
||||||
|
BOOST_FOREACH(const CNodeStats& stats, vstats)
|
||||||
|
{
|
||||||
|
CNodeStateStats statestats;
|
||||||
|
bool fStateStats = GetNodeStateStats(stats.nodeid,statestats);
|
||||||
|
ht = 0;
|
||||||
|
if ( stats.nStartingHeight > ht )
|
||||||
|
ht = stats.nStartingHeight;
|
||||||
|
if ( statestats.nSyncHeight > ht )
|
||||||
|
ht = statestats.nSyncHeight;
|
||||||
|
if ( statestats.nCommonHeight > ht )
|
||||||
|
ht = statestats.nCommonHeight;
|
||||||
|
if ( maxheight == 0 || ht > maxheight*1.01 )
|
||||||
|
maxheight = ht, num = 1;
|
||||||
|
else if ( ht > maxheight*0.99 )
|
||||||
|
num++;
|
||||||
|
n++;
|
||||||
|
if ( ht > height )
|
||||||
|
height = ht;
|
||||||
|
}
|
||||||
|
if ( num > (n >> 1) )
|
||||||
|
return(height);
|
||||||
|
else return(0);
|
||||||
|
}
|
||||||
|
|
||||||
Value addnode(const Array& params, bool fHelp)
|
Value addnode(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
string strCommand;
|
string strCommand;
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
|
|||||||
{
|
{
|
||||||
extern char ASSETCHAINS_SYMBOL[16];
|
extern char ASSETCHAINS_SYMBOL[16];
|
||||||
interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,tipindex->nTime);
|
interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,tipindex->nTime);
|
||||||
if ( strcmp("REVS",ASSETCHAINS_SYMBOL) == 0 )
|
if ( 0 && strcmp("REVS",ASSETCHAINS_SYMBOL) == 0 )
|
||||||
fprintf(stderr,"TxtoJSON interest %llu %.8f (%d %llu %u %u)\n",(long long)interest,(double)interest/COIN,(int32_t)pindex->nHeight,(long long)txout.nValue,(uint32_t)tx.nLockTime,(int32_t)tipindex->nTime);
|
fprintf(stderr,"TxtoJSON interest %llu %.8f (%d %llu %u %u)\n",(long long)interest,(double)interest/COIN,(int32_t)pindex->nHeight,(long long)txout.nValue,(uint32_t)tx.nLockTime,(int32_t)tipindex->nTime);
|
||||||
out.push_back(Pair("interest", ValueFromAmount(interest)));
|
out.push_back(Pair("interest", ValueFromAmount(interest)));
|
||||||
}
|
}
|
||||||
@@ -253,6 +253,56 @@ Value getrawtransaction(const Array& params, bool fHelp)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t gettxout_scriptPubKey(uint8_t *scriptPubKey,int32_t maxsize,uint256 txid,int32_t n)
|
||||||
|
{
|
||||||
|
int32_t i,m; uint8_t *ptr;
|
||||||
|
LOCK(cs_main);
|
||||||
|
/*CCoins coins;
|
||||||
|
for (iter=0; iter<2; iter++)
|
||||||
|
{
|
||||||
|
if ( iter == 0 )
|
||||||
|
{
|
||||||
|
LOCK(mempool.cs);
|
||||||
|
CCoinsViewMemPool view(pcoinsTip,mempool);
|
||||||
|
if ( view.GetCoins(txid,coins) == 0 )
|
||||||
|
{
|
||||||
|
//fprintf(stderr,"cant get view\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
mempool.pruneSpent(txid, coins); // TODO: this should be done by the CCoinsViewMemPool
|
||||||
|
}
|
||||||
|
else if ( pcoinsTip->GetCoins(txid,coins) == 0 )
|
||||||
|
{
|
||||||
|
//fprintf(stderr,"cant get pcoinsTip->GetCoins\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( n < 0 || (unsigned int)n >= coins.vout.size() || coins.vout[n].IsNull() )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"iter.%d n.%d vs voutsize.%d\n",iter,n,(int32_t)coins.vout.size());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ptr = (uint8_t *)coins.vout[n].scriptPubKey.data();
|
||||||
|
m = coins.vout[n].scriptPubKey.size();
|
||||||
|
for (i=0; i<maxsize&&i<m; i++)
|
||||||
|
scriptPubKey[i] = ptr[i];
|
||||||
|
return(i);
|
||||||
|
}*/
|
||||||
|
CTransaction tx;
|
||||||
|
uint256 hashBlock;
|
||||||
|
if ( GetTransaction(txid,tx,hashBlock,true) == 0 )
|
||||||
|
return(-1);
|
||||||
|
else if ( n <= tx.vout.size() ) // vout.size() seems off by 1
|
||||||
|
{
|
||||||
|
ptr = (uint8_t *)tx.vout[n].scriptPubKey.data();
|
||||||
|
m = tx.vout[n].scriptPubKey.size();
|
||||||
|
for (i=0; i<maxsize&&i<m; i++)
|
||||||
|
scriptPubKey[i] = ptr[i];
|
||||||
|
//fprintf(stderr,"got scriptPubKey via rawtransaction\n");
|
||||||
|
return(i);
|
||||||
|
}
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
Value gettxoutproof(const Array& params, bool fHelp)
|
Value gettxoutproof(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || (params.size() != 1 && params.size() != 2))
|
if (fHelp || (params.size() != 1 && params.size() != 2))
|
||||||
|
|||||||
@@ -301,8 +301,10 @@ static const CRPCCommand vRPCCommands[] =
|
|||||||
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true },
|
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true },
|
||||||
{ "blockchain", "verifychain", &verifychain, true },
|
{ "blockchain", "verifychain", &verifychain, true },
|
||||||
{ "blockchain", "paxprice", &paxprice, true },
|
{ "blockchain", "paxprice", &paxprice, true },
|
||||||
|
{ "blockchain", "paxpending", &paxpending, true },
|
||||||
{ "blockchain", "paxprices", &paxprices, true },
|
{ "blockchain", "paxprices", &paxprices, true },
|
||||||
{ "blockchain", "notaries", ¬aries, true },
|
{ "blockchain", "notaries", ¬aries, true },
|
||||||
|
{ "blockchain", "minerids", &minerids, true },
|
||||||
|
|
||||||
/* Mining */
|
/* Mining */
|
||||||
{ "mining", "getblocktemplate", &getblocktemplate, true },
|
{ "mining", "getblocktemplate", &getblocktemplate, true },
|
||||||
|
|||||||
@@ -244,7 +244,9 @@ extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp)
|
|||||||
extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value notaries(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value notaries(const json_spirit::Array& params, bool fHelp);
|
||||||
|
extern json_spirit::Value minerids(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp);
|
||||||
|
extern json_spirit::Value paxpending(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value paxprices(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value paxprices(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value paxdeposit(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value paxdeposit(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value paxwithdraw(const json_spirit::Array& params, bool fHelp);
|
extern json_spirit::Value paxwithdraw(const json_spirit::Array& params, bool fHelp);
|
||||||
|
|||||||
@@ -144,7 +144,10 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
|
|||||||
{
|
{
|
||||||
// small pushdata, <= nMaxDatacarrierBytes
|
// small pushdata, <= nMaxDatacarrierBytes
|
||||||
if (vch1.size() > nMaxDatacarrierBytes)
|
if (vch1.size() > nMaxDatacarrierBytes)
|
||||||
|
{
|
||||||
|
fprintf(stderr,"size.%d > nMaxDatacarrier.%d\n",(int32_t)vch1.size(),(int32_t)nMaxDatacarrierBytes);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (opcode1 != opcode2 || vch1 != vch2)
|
else if (opcode1 != opcode2 || vch1 != vch2)
|
||||||
{
|
{
|
||||||
@@ -202,7 +205,6 @@ bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType)
|
|||||||
if (m < 1 || m > n)
|
if (m < 1 || m > n)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return whichType != TX_NONSTANDARD;
|
return whichType != TX_NONSTANDARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -401,18 +401,14 @@ void PrintExceptionContinue(const std::exception* pex, const char* pszThread)
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern char ASSETCHAINS_SYMBOL[16];
|
extern char ASSETCHAINS_SYMBOL[16];
|
||||||
extern int32_t ASSETCHAINS_SHORTFLAG;
|
|
||||||
|
|
||||||
boost::filesystem::path GetDefaultDataDir()
|
boost::filesystem::path GetDefaultDataDir()
|
||||||
{
|
{
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
char symbol[16];
|
char symbol[16];
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
{
|
strcpy(symbol,ASSETCHAINS_SYMBOL);
|
||||||
if ( ASSETCHAINS_SHORTFLAG != 0 )
|
else symbol[0] = 0;
|
||||||
sprintf(symbol,"-%s",ASSETCHAINS_SYMBOL);
|
|
||||||
else strcpy(symbol,ASSETCHAINS_SYMBOL);
|
|
||||||
} else symbol[0] = 0;
|
|
||||||
// Windows < Vista: C:\Documents and Settings\Username\Application Data\Zcash
|
// Windows < Vista: C:\Documents and Settings\Username\Application Data\Zcash
|
||||||
// Windows >= Vista: C:\Users\Username\AppData\Roaming\Zcash
|
// Windows >= Vista: C:\Users\Username\AppData\Roaming\Zcash
|
||||||
// Mac: ~/Library/Application Support/Zcash
|
// Mac: ~/Library/Application Support/Zcash
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ bool CDBEnv::Open(const boost::filesystem::path& pathIn)
|
|||||||
TryCreateDirectory(pathLogDir);
|
TryCreateDirectory(pathLogDir);
|
||||||
boost::filesystem::path pathErrorFile = pathIn / "db.log";
|
boost::filesystem::path pathErrorFile = pathIn / "db.log";
|
||||||
LogPrintf("CDBEnv::Open: LogDir=%s ErrorFile=%s pathIn.(%s)\n", pathLogDir.string(), pathErrorFile.string(),pathIn.string());
|
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;
|
unsigned int nEnvFlags = 0;
|
||||||
if (GetBoolArg("-privdb", true))
|
if (GetBoolArg("-privdb", true))
|
||||||
|
|||||||
@@ -481,17 +481,19 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_
|
|||||||
extern char ASSETCHAINS_SYMBOL[16];
|
extern char ASSETCHAINS_SYMBOL[16];
|
||||||
int32_t komodo_is_issuer();
|
int32_t komodo_is_issuer();
|
||||||
int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
|
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)
|
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;
|
bool fSubtractFeeFromAmount = false;
|
||||||
if ( komodo_is_issuer() != 0 )
|
if ( komodo_is_issuer() != 0 )
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KMD");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KMD");
|
||||||
if (!EnsureWalletIsAvailable(fHelp))
|
if (!EnsureWalletIsAvailable(fHelp))
|
||||||
return Value::null;
|
return Value::null;
|
||||||
if (fHelp || params.size() != 3)
|
if (fHelp || params.size() != 3)
|
||||||
throw runtime_error("paxdeposit \"address\" [-]fiatoshis \"base\"\nnegative fiatoshis means a short position, long position capped at 100% gain");
|
throw runtime_error("paxdeposit address fiatoshis base");
|
||||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
CBitcoinAddress address(params[0].get_str());
|
CBitcoinAddress address(params[0].get_str());
|
||||||
if (!address.IsValid())
|
if (!address.IsValid())
|
||||||
@@ -500,14 +502,16 @@ Value paxdeposit(const Array& params, bool fHelp)
|
|||||||
std::string base = params[2].get_str();
|
std::string base = params[2].get_str();
|
||||||
std::string dest;
|
std::string dest;
|
||||||
height = chainActive.Tip()->nHeight;
|
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);
|
komodoshis = PAX_fiatdest(&seed,0,destaddr,pubkey37,(char *)params[0].get_str().c_str(),height,(char *)base.c_str(),fiatoshis);
|
||||||
dest.append(destaddr);
|
dest.append(destaddr);
|
||||||
CBitcoinAddress destaddress(CRYPTO777_KMDADDR);
|
CBitcoinAddress destaddress(CRYPTO777_KMDADDR);
|
||||||
if (!destaddress.IsValid())
|
if (!destaddress.IsValid())
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address");
|
||||||
for (i=0; i<33; i++)
|
for (i=0; i<33; i++)
|
||||||
printf("%02x",pubkey37[i]);
|
fprintf(stderr,"%02x",pubkey37[i]);
|
||||||
printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu seed.%llx\n",height,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)komodoshis,(long long)seed);
|
fprintf(stderr," ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu seed.%llx\n",height,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)komodoshis,(long long)seed);
|
||||||
EnsureWalletIsUnlocked();
|
EnsureWalletIsUnlocked();
|
||||||
CWalletTx wtx;
|
CWalletTx wtx;
|
||||||
uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = komodoshis / 1000;
|
uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = komodoshis / 1000;
|
||||||
@@ -521,22 +525,20 @@ Value paxdeposit(const Array& params, bool fHelp)
|
|||||||
|
|
||||||
Value paxwithdraw(const Array& params, bool fHelp)
|
Value paxwithdraw(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
extern int32_t KMDHEIGHT,KOMODO_REALTIME;
|
|
||||||
CWalletTx wtx; std::string dest; int32_t kmdheight; uint64_t seed,komodoshis = 0; char destaddr[64]; uint8_t i,pubkey37[37]; bool fSubtractFeeFromAmount = false;
|
CWalletTx wtx; std::string dest; int32_t kmdheight; uint64_t seed,komodoshis = 0; char destaddr[64]; uint8_t i,pubkey37[37]; bool fSubtractFeeFromAmount = false;
|
||||||
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||||
return(0);
|
return(0);
|
||||||
if (!EnsureWalletIsAvailable(fHelp))
|
if (!EnsureWalletIsAvailable(fHelp))
|
||||||
return 0;
|
return 0;
|
||||||
if (fHelp || params.size() != 2)
|
if (fHelp || params.size() != 2)
|
||||||
throw runtime_error("paxwithdraw \"address\" fiatamount");
|
throw runtime_error("paxwithdraw address fiatamount");
|
||||||
if ( KOMODO_REALTIME == 0 )
|
if ( komodo_isrealtime(&kmdheight) == 0 )
|
||||||
return(0);
|
return(0);
|
||||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
CBitcoinAddress address(params[0].get_str());
|
CBitcoinAddress address(params[0].get_str());
|
||||||
if (!address.IsValid())
|
if (!address.IsValid())
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
||||||
int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN;
|
int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN;
|
||||||
kmdheight = KMDHEIGHT;
|
|
||||||
komodoshis = PAX_fiatdest(&seed,1,destaddr,pubkey37,(char *)params[0].get_str().c_str(),kmdheight,ASSETCHAINS_SYMBOL,fiatoshis);
|
komodoshis = PAX_fiatdest(&seed,1,destaddr,pubkey37,(char *)params[0].get_str().c_str(),kmdheight,ASSETCHAINS_SYMBOL,fiatoshis);
|
||||||
dest.append(destaddr);
|
dest.append(destaddr);
|
||||||
CBitcoinAddress destaddress(CRYPTO777_KMDADDR);
|
CBitcoinAddress destaddress(CRYPTO777_KMDADDR);
|
||||||
|
|||||||
@@ -748,6 +748,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
|
|||||||
|
|
||||||
void CWallet::DecrementNoteWitnesses()
|
void CWallet::DecrementNoteWitnesses()
|
||||||
{
|
{
|
||||||
|
extern int32_t KOMODO_REWIND;
|
||||||
{
|
{
|
||||||
LOCK(cs_wallet);
|
LOCK(cs_wallet);
|
||||||
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
|
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
|
||||||
@@ -770,12 +771,13 @@ void CWallet::DecrementNoteWitnesses()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: If nWitnessCache is zero, we need to regenerate the caches (#1302)
|
// TODO: If nWitnessCache is zero, we need to regenerate the caches (#1302)
|
||||||
assert(nWitnessCacheSize > 0);
|
|
||||||
if ( nWitnessCacheSize <= 0 )
|
if ( nWitnessCacheSize <= 0 )
|
||||||
{
|
{
|
||||||
extern char ASSETCHAINS_SYMBOL[16];
|
extern char ASSETCHAINS_SYMBOL[16];
|
||||||
fprintf(stderr,"%s nWitnessCacheSize.%d\n",ASSETCHAINS_SYMBOL,(int32_t)nWitnessCacheSize);
|
fprintf(stderr,"%s nWitnessCacheSize.%d\n",ASSETCHAINS_SYMBOL,(int32_t)nWitnessCacheSize);
|
||||||
}
|
}
|
||||||
|
if ( KOMODO_REWIND == 0 )
|
||||||
|
assert(nWitnessCacheSize > 0);
|
||||||
if (fFileBacked) {
|
if (fFileBacked) {
|
||||||
CWalletDB walletdb(strWalletFile);
|
CWalletDB walletdb(strWalletFile);
|
||||||
WriteWitnessCache(walletdb);
|
WriteWitnessCache(walletdb);
|
||||||
|
|||||||
Reference in New Issue
Block a user