@@ -26,6 +26,7 @@ std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee);
|
||||
std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount);
|
||||
std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector <uint8_t> data);
|
||||
// CCcustom
|
||||
UniValue OracleDataSample(uint256 reforacletxid,uint256 txid);
|
||||
UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num);
|
||||
UniValue OracleInfo(uint256 origtxid);
|
||||
UniValue OraclesList();
|
||||
|
||||
@@ -638,11 +638,7 @@ bool OraclesDataValidate(struct CCcontract_info *cp,Eval* eval,const CTransactio
|
||||
|
||||
int32_t GetLatestTimestamp(int32_t height)
|
||||
{
|
||||
uint256 blockHash; CBlock block; CBlockIndex* pindex;
|
||||
|
||||
blockHash = chainActive[height]->GetBlockHash();
|
||||
pindex = mapBlockIndex[blockHash];
|
||||
return(pindex->nTime);
|
||||
return(komodo_heightstamp(height));
|
||||
}
|
||||
|
||||
bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn)
|
||||
@@ -1059,6 +1055,38 @@ UniValue OracleFormat(uint8_t *data,int32_t datalen,char *format,int32_t formatl
|
||||
return(obj);
|
||||
}
|
||||
|
||||
UniValue OracleDataSample(uint256 reforacletxid,uint256 txid)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); CTransaction tx,oracletx; uint256 hashBlock,btxid,oracletxid; std::string error;
|
||||
CPubKey pk; std::string name,description,format; int32_t numvouts; std::vector<uint8_t> data; char str[67], *formatstr = 0;
|
||||
|
||||
result.push_back(Pair("result","success"));
|
||||
if ( GetTransaction(reforacletxid,oracletx,hashBlock,false) != 0 && (numvouts=oracletx.vout.size()) > 0 )
|
||||
{
|
||||
if ( DecodeOraclesCreateOpRet(oracletx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' )
|
||||
{
|
||||
if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0 )
|
||||
{
|
||||
if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D' && reforacletxid == oracletxid )
|
||||
{
|
||||
if ( (formatstr= (char *)format.c_str()) == 0 )
|
||||
formatstr = (char *)"";
|
||||
result.push_back(Pair("txid",uint256_str(str,txid)));
|
||||
result.push_back(Pair("data",OracleFormat((uint8_t *)data.data(),(int32_t)data.size(),formatstr,(int32_t)format.size())));
|
||||
return(result);
|
||||
}
|
||||
else error="invalid data tx";
|
||||
}
|
||||
else error="cannot find data txid";
|
||||
}
|
||||
else error="invalid oracles txid";
|
||||
}
|
||||
else error="cannot find oracles txid";
|
||||
result.push_back(Pair("result","error"));
|
||||
result.push_back(Pair("error",error));
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ),b(UniValue::VARR); CTransaction tx,oracletx; uint256 txid,hashBlock,btxid,oracletxid;
|
||||
|
||||
@@ -1692,7 +1692,7 @@ int8_t equihash_params_possible(uint64_t n, uint64_t k)
|
||||
|
||||
void komodo_args(char *argv0)
|
||||
{
|
||||
std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256], ccEnablesHeight[512];
|
||||
std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256], ccEnablesHeight[512] = {0};
|
||||
IS_KOMODO_NOTARY = GetBoolArg("-notary", false);
|
||||
IS_STAKED_NOTARY = GetArg("-stakednotary", -1);
|
||||
memset(ccenables,0,sizeof(ccenables));
|
||||
@@ -1717,15 +1717,17 @@ void komodo_args(char *argv0)
|
||||
// I think on season change should reccomend notaries to use -notary to avoid needing this.
|
||||
int32_t kmd_season = getacseason(time(NULL));
|
||||
for (i=0; i<64; i++)
|
||||
if ( strcmp(NOTARY_PUBKEY.c_str(),notaries_elected[kmd_season][NUM_KMD_NOTARIES][1]) == 0 )
|
||||
{
|
||||
if ( strcmp(NOTARY_PUBKEY.c_str(),notaries_elected[kmd_season-1][i][1]) == 0 )
|
||||
{
|
||||
IS_KOMODO_NOTARY = 1;
|
||||
KOMODO_MININGTHREADS = 1;
|
||||
mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS);
|
||||
IS_STAKED_NOTARY = -1;
|
||||
fprintf(stderr,"running as notary.%d %s\n",i,notaries_elected[kmd_season][NUM_KMD_NOTARIES][0]);
|
||||
fprintf(stderr,"running as notary.%d %s\n",i,notaries_elected[kmd_season-1][i][0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( IS_STAKED_NOTARY != -1 && IS_KOMODO_NOTARY == true ) {
|
||||
@@ -1767,7 +1769,7 @@ void komodo_args(char *argv0)
|
||||
{
|
||||
int32_t ecode = ccEnablesHeight[i];
|
||||
int32_t ht = ccEnablesHeight[i+1];
|
||||
if ( ecode > 256 )
|
||||
if ( ecode > 255 || ecode < 0 )
|
||||
fprintf(stderr, "ac_ccactivateht: invalid evalcode.%i must be between 0 and 256.\n", ecode);
|
||||
else if ( ht > 0 )
|
||||
{
|
||||
|
||||
28
src/main.cpp
28
src/main.cpp
@@ -147,10 +147,28 @@ namespace {
|
||||
|
||||
struct CBlockIndexWorkComparator
|
||||
{
|
||||
bool operator()(CBlockIndex *pa, CBlockIndex *pb) const {
|
||||
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const {
|
||||
// First sort by most total work, ...
|
||||
if (pa->chainPower > pb->chainPower) return false;
|
||||
if (pa->chainPower < pb->chainPower) return true;
|
||||
|
||||
if (ASSETCHAINS_LWMAPOS) {
|
||||
|
||||
/* Decker:
|
||||
|
||||
seems we had CChainPower classes compare here from Verus, it's slow, bcz of hard
|
||||
arith_uint256 math in bool operator<(const CChainPower &p1, const CChainPower &p2),
|
||||
this slows down setBlockIndexCandidates.insert operations in LoadBlockIndexDB(),
|
||||
so, for faster block index db loading we will use check from Verus only for LWMAPOS
|
||||
enabled chains.
|
||||
*/
|
||||
|
||||
if (pa->chainPower > pb->chainPower) return false;
|
||||
if (pa->chainPower < pb->chainPower) return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pa->chainPower.chainWork > pb->chainPower.chainWork) return false;
|
||||
if (pa->chainPower.chainWork < pb->chainPower.chainWork) return true;
|
||||
}
|
||||
|
||||
// ... then by earliest time received, ...
|
||||
if (pa->nSequenceId < pb->nSequenceId) return false;
|
||||
@@ -173,8 +191,10 @@ namespace {
|
||||
* as good as our current tip or better. Entries may be failed, though, and pruning nodes may be
|
||||
* missing the data for the block.
|
||||
*/
|
||||
|
||||
//set<CBlockIndex*, CBlockIndexWorkComparator, std::allocator<CBlockIndex*>> setBlockIndexCandidates;
|
||||
set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexCandidates;
|
||||
|
||||
|
||||
/** Number of nodes with fSyncStarted. */
|
||||
int nSyncStarted = 0;
|
||||
|
||||
|
||||
@@ -222,9 +222,13 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
||||
boost::optional<CTransaction> cheatSpend;
|
||||
|
||||
uint256 cbHash;
|
||||
|
||||
|
||||
boost::this_thread::interruption_point(); // exit thread before entering locks.
|
||||
|
||||
CBlockIndex* pindexPrev = 0;
|
||||
{
|
||||
// this should stop create block ever exiting until it has returned something.
|
||||
boost::this_thread::disable_interruption();
|
||||
ENTER_CRITICAL_SECTION(cs_main);
|
||||
ENTER_CRITICAL_SECTION(mempool.cs);
|
||||
pindexPrev = chainActive.LastTip();
|
||||
@@ -815,7 +819,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
||||
LEAVE_CRITICAL_SECTION(cs_main);
|
||||
LEAVE_CRITICAL_SECTION(mempool.cs);
|
||||
}
|
||||
throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed");
|
||||
//throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed"); // crashes the node, moved to GetBlockTemplate and issue return.
|
||||
return(0);
|
||||
}
|
||||
//fprintf(stderr,"valid\n");
|
||||
}
|
||||
|
||||
@@ -745,7 +745,8 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
#endif
|
||||
ENTER_CRITICAL_SECTION(cs_main);
|
||||
if (!pblocktemplate)
|
||||
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory or no available utxo for staking");
|
||||
throw std::runtime_error("CreateNewBlock(): create block failed");
|
||||
//throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory or no available utxo for staking");
|
||||
|
||||
// Need to update only after we know CreateNewBlockWithKey succeeded
|
||||
pindexPrev = pindexPrevNew;
|
||||
|
||||
@@ -460,6 +460,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "oracles", "oraclesregister", &oraclesregister, true },
|
||||
{ "oracles", "oraclessubscribe", &oraclessubscribe, true },
|
||||
{ "oracles", "oraclesdata", &oraclesdata, true },
|
||||
{ "oracles", "oraclessample", &oraclessample, true },
|
||||
{ "oracles", "oraclessamples", &oraclessamples, true },
|
||||
|
||||
// Prices
|
||||
|
||||
@@ -271,6 +271,7 @@ extern UniValue oraclesfund(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclesregister(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclessubscribe(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclesdata(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclessample(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclessamples(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue priceslist(const UniValue& params, bool fHelp);
|
||||
|
||||
@@ -89,6 +89,65 @@ std::string DecodeDumpString(const std::string &str) {
|
||||
return ret.str();
|
||||
}
|
||||
|
||||
UniValue convertpassphrase(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 1)
|
||||
throw runtime_error(
|
||||
"convertpassphrase \"agamapassphrase\"\n"
|
||||
"\nConverts Agama passphrase to a private key and WIF (for import with importprivkey).\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"agamapassphrase\" (string, required) Agama passphrase\n"
|
||||
"\nResult:\n"
|
||||
"\"agamapassphrase\": \"agamapassphrase\", (string) Agama passphrase you entered\n"
|
||||
"\"address\": \"komodoaddress\", (string) Address corresponding to your passphrase\n"
|
||||
"\"pubkey\": \"publickeyhex\", (string) The hex value of the raw public key\n"
|
||||
"\"privkey\": \"privatekeyhex\", (string) The hex value of the raw private key\n"
|
||||
"\"wif\": \"wif\" (string) The private key in WIF format to use with 'importprivkey'\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("convertpassphrase", "\"agamapassphrase\"")
|
||||
+ HelpExampleRpc("convertpassphrase", "\"agamapassphrase\"")
|
||||
);
|
||||
|
||||
bool fCompressed = true;
|
||||
string strAgamaPassphrase = params[0].get_str();
|
||||
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
ret.push_back(Pair("agamapassphrase", strAgamaPassphrase));
|
||||
|
||||
CKey tempkey = DecodeSecret(strAgamaPassphrase);
|
||||
/* first we should check if user pass wif to method, instead of passphrase */
|
||||
if (!tempkey.IsValid()) {
|
||||
/* it's a passphrase, not wif */
|
||||
uint256 sha256;
|
||||
CSHA256().Write((const unsigned char *)strAgamaPassphrase.c_str(), strAgamaPassphrase.length()).Finalize(sha256.begin());
|
||||
std::vector<unsigned char> privkey(sha256.begin(), sha256.begin() + sha256.size());
|
||||
privkey.front() &= 0xf8;
|
||||
privkey.back() &= 0x7f;
|
||||
privkey.back() |= 0x40;
|
||||
CKey key;
|
||||
key.Set(privkey.begin(),privkey.end(), fCompressed);
|
||||
CPubKey pubkey = key.GetPubKey();
|
||||
assert(key.VerifyPubKey(pubkey));
|
||||
CKeyID vchAddress = pubkey.GetID();
|
||||
|
||||
ret.push_back(Pair("address", EncodeDestination(vchAddress)));
|
||||
ret.push_back(Pair("pubkey", HexStr(pubkey)));
|
||||
ret.push_back(Pair("privkey", HexStr(privkey)));
|
||||
ret.push_back(Pair("wif", EncodeSecret(key)));
|
||||
} else {
|
||||
/* seems it's a wif */
|
||||
CPubKey pubkey = tempkey.GetPubKey();
|
||||
assert(tempkey.VerifyPubKey(pubkey));
|
||||
CKeyID vchAddress = pubkey.GetID();
|
||||
ret.push_back(Pair("address", EncodeDestination(vchAddress)));
|
||||
ret.push_back(Pair("pubkey", HexStr(pubkey)));
|
||||
ret.push_back(Pair("privkey", HexStr(tempkey)));
|
||||
ret.push_back(Pair("wif", strAgamaPassphrase));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
UniValue importprivkey(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
|
||||
@@ -5564,6 +5564,8 @@ UniValue cclibinfo(const UniValue& params, bool fHelp)
|
||||
UniValue cclib(const UniValue& params, bool fHelp)
|
||||
{
|
||||
struct CCcontract_info *cp,C; char *method,*jsonstr=0; uint8_t evalcode = EVAL_FIRSTUSER;
|
||||
std::string vobjJsonSerialized;
|
||||
|
||||
if ( fHelp || params.size() > 3 )
|
||||
throw runtime_error("cclib method [evalcode] [JSON params]\n");
|
||||
if ( ASSETCHAINS_CCLIB.size() == 0 )
|
||||
@@ -5583,7 +5585,12 @@ UniValue cclib(const UniValue& params, bool fHelp)
|
||||
}
|
||||
if ( params.size() == 3 )
|
||||
{
|
||||
jsonstr = (char *)params[2].get_str().c_str();
|
||||
if (params[2].getType() == UniValue::VOBJ) {
|
||||
vobjJsonSerialized = params[2].write(0, 0);
|
||||
jsonstr = (char *)vobjJsonSerialized.c_str();
|
||||
}
|
||||
else // VSTR assumed
|
||||
jsonstr = (char *)params[2].get_str().c_str();
|
||||
//fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),jsonstr);
|
||||
}
|
||||
}
|
||||
@@ -6830,6 +6837,20 @@ UniValue oraclessubscribe(const UniValue& params, bool fHelp)
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue oraclessample(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint256 oracletxid,txid; int32_t num; char *batonaddr;
|
||||
if ( fHelp || params.size() != 2 )
|
||||
throw runtime_error("oraclessample oracletxid txid\n");
|
||||
if ( ensure_CCrequirements(EVAL_ORACLES) < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
oracletxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
txid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
return(OracleDataSample(oracletxid,txid));
|
||||
}
|
||||
|
||||
UniValue oraclessamples(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ); uint256 txid; int32_t num; char *batonaddr;
|
||||
@@ -7956,6 +7977,7 @@ UniValue heirlist(const UniValue& params, bool fHelp)
|
||||
|
||||
|
||||
extern UniValue dumpprivkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
|
||||
extern UniValue convertpassphrase(const UniValue& params, bool fHelp);
|
||||
extern UniValue importprivkey(const UniValue& params, bool fHelp);
|
||||
extern UniValue importaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue dumpwallet(const UniValue& params, bool fHelp);
|
||||
@@ -7991,6 +8013,7 @@ static const CRPCCommand commands[] =
|
||||
{ "wallet", "gettransaction", &gettransaction, false },
|
||||
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, false },
|
||||
{ "wallet", "getwalletinfo", &getwalletinfo, false },
|
||||
{ "wallet", "convertpassphrase", &convertpassphrase, true },
|
||||
{ "wallet", "importprivkey", &importprivkey, true },
|
||||
{ "wallet", "importwallet", &importwallet, true },
|
||||
{ "wallet", "importaddress", &importaddress, true },
|
||||
|
||||
Reference in New Issue
Block a user