Merge pull request #30 from StakedChain/blackjok3r

merge blackjok3r branch and FSM fixes into master
This commit is contained in:
blackjok3rtt
2018-11-01 14:01:09 +08:00
committed by GitHub
15 changed files with 187 additions and 86 deletions

View File

@@ -49,6 +49,7 @@ extern int32_t ASSETCHAINS_STREAM;
extern UniValue TxJoinSplitToJSON(const CTransaction& tx);
extern uint8_t ASSETCHAINS_PRIVATE;
uint32_t komodo_segid32(char *coinaddr);
int32_t komodo_dpowconfs(int32_t height,int32_t numconfs);
int64_t nWalletUnlockTime;
static CCriticalSection cs_nWalletUnlockTime;
@@ -91,7 +92,8 @@ void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry)
{
//int32_t i,n,txheight; uint32_t locktime; uint64_t interest = 0;
int confirms = wtx.GetDepthInMainChain();
entry.push_back(Pair("confirmations", confirms));
entry.push_back(Pair("rawconfirmations", confirms));
entry.push_back(Pair("confirmations", komodo_dpowconfs((int32_t)mapBlockIndex[wtx.hashBlock]->nHeight,confirms)));
if (wtx.IsCoinBase())
entry.push_back(Pair("generated", true));
if (confirms > 0)
@@ -2700,7 +2702,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
CAmount nValue = out.tx->vout[out.i].nValue;
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
UniValue entry(UniValue::VOBJ);
UniValue entry(UniValue::VOBJ); int32_t txheight = 0;
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
entry.push_back(Pair("vout", out.i));
entry.push_back(Pair("generated", out.tx->IsCoinBase()));
@@ -2725,7 +2727,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
{
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
CBlockIndex *tipindex,*pindex = it->second;
uint64_t interest; uint32_t locktime; int32_t txheight;
uint64_t interest; uint32_t locktime;
if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 )
{
interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight);
@@ -2734,7 +2736,10 @@ UniValue listunspent(const UniValue& params, bool fHelp)
}
//fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->nHeight);
}
entry.push_back(Pair("confirmations",out.nDepth));
else if ( chainActive.LastTip() != 0 )
txheight = (chainActive.LastTip()->nHeight - out.nDepth - 1);
entry.push_back(Pair("rawconfirmations",out.nDepth));
entry.push_back(Pair("confirmations",komodo_dpowconfs(txheight,out.nDepth)));
entry.push_back(Pair("spendable", out.fSpendable));
results.push_back(entry);
}
@@ -5235,8 +5240,23 @@ UniValue channelsopen(const UniValue& params, bool fHelp)
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
destpub = ParseHex(params[0].get_str().c_str());
if (destpub.size()!= 33)
{
ERR_RESULT("invalid destination pubkey");
return result;
}
numpayments = atoi(params[1].get_str().c_str());
if (numpayments <1)
{
ERR_RESULT("invalid number of payments, must be greater than 0");
return result;
}
payment = atol(params[2].get_str().c_str());
if (payment <1)
{
ERR_RESULT("invalid payment amount, must be greater than 0");
return result;
}
hex = ChannelOpen(0,pubkey2pk(destpub),numpayments,payment);
if ( hex.size() > 0 )
{
@@ -5258,6 +5278,11 @@ UniValue channelspayment(const UniValue& params, bool fHelp)
LOCK2(cs_main, pwalletMain->cs_wallet);
opentxid = Parseuint256((char *)params[0].get_str().c_str());
amount = atoi((char *)params[1].get_str().c_str());
if (amount <1)
{
ERR_RESULT("invalid payment amount, must be greater than 0");
return result;
}
if (params.size() > 2 && !params[2].isNull() && !params[2].get_str().empty())
{
secret = Parseuint256((char *)params[2].get_str().c_str());
@@ -5798,6 +5823,24 @@ UniValue oraclescreate(const UniValue& params, bool fHelp)
ERR_RESULT("oracles format must be <= 4096 characters");
return(result);
}
// list of oracle valid formats from oracles.cpp -> oracle_format
const UniValue valid_formats[13] = {"s","S","d","D","c","C","t","T","i","I","l","L","h"};
const UniValue header_type = "Ihh";
// checking if oracle data type is valid
bool is_valid_format = false;
for ( int i = 0; i < 13; ++i ) {
if ( valid_formats[i].get_str() == format ) {
is_valid_format = true;
}
}
// additional check for special Ihh data type
if ( format == header_type.get_str() ) {
is_valid_format = true;
}
if ( !is_valid_format ) {
ERR_RESULT("oracles format not valid");
return(result);
}
hex = OracleCreate(0,name,description,format);
if ( hex.size() > 0 )
{