From: MASM fan Date: Wed, 5 Feb 2014 19:02:22 +0000 (+0400) Subject: Merge RPC and wallet updates from 0.4.4.7 X-Git-Tag: v0.4.4.6-nvc-update1^0 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=b9c711308fc96540c0a22c7aba0707d90460c0a1 Merge RPC and wallet updates from 0.4.4.7 --- diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index f67e45e..6610390 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -245,6 +245,7 @@ static const CRPCCommand vRPCCommands[] = { "getpeerinfo", &getpeerinfo, true, false }, { "getdifficulty", &getdifficulty, true, false }, { "getinfo", &getinfo, true, false }, + { "getsubsidy", &getsubsidy, true, false }, { "getmininginfo", &getmininginfo, true, false }, { "getnewaddress", &getnewaddress, true, false }, { "getnewpubkey", &getnewpubkey, true, false }, diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 736f362..afb41f7 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -153,6 +153,7 @@ extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool f extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getsubsidy(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getwork(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getworkex(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 94d3671..e374c1d 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -13,6 +13,28 @@ using namespace json_spirit; using namespace std; +Value getsubsidy(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 1) + throw runtime_error( + "getsubsidy [nTarget]\n" + "Returns proof-of-work subsidy value for the specified value of target."); + + unsigned int nBits = 0; + + if (params.size() != 0) + { + CBigNum bnTarget(uint256(params[0].get_str())); + nBits = bnTarget.GetCompact(); + } + else + { + nBits = GetNextTargetRequired(pindexBest, false); + } + + return (uint64_t)GetProofOfWorkReward(nBits); +} + Value getmininginfo(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) @@ -23,20 +45,26 @@ Value getmininginfo(const Array& params, bool fHelp) uint64 nMinWeight = 0, nMaxWeight = 0, nWeight = 0; pwalletMain->GetStakeWeight(*pwalletMain, nMinWeight, nMaxWeight, nWeight); - Object obj; + Object obj, diff, weight; obj.push_back(Pair("blocks", (int)nBestHeight)); obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize)); obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx)); - obj.push_back(Pair("difficulty", (double)GetDifficulty())); + + diff.push_back(Pair("proof-of-work", GetDifficulty())); + diff.push_back(Pair("proof-of-stake", GetDifficulty(GetLastBlockIndex(pindexBest, true)))); + diff.push_back(Pair("search-interval", (int)nLastCoinStakeSearchInterval)); + obj.push_back(Pair("difficulty", diff)); + obj.push_back(Pair("blockvalue", (uint64_t)GetProofOfWorkReward(GetLastBlockIndex(pindexBest, false)->nBits))); obj.push_back(Pair("netmhashps", GetPoWMHashPS())); obj.push_back(Pair("netstakeweight", GetPoSKernelPS())); obj.push_back(Pair("errors", GetWarnings("statusbar"))); obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); - obj.push_back(Pair("stakeweight", (uint64_t)nWeight)); - obj.push_back(Pair("minweight", (uint64_t)nMinWeight)); - obj.push_back(Pair("maxweight", (uint64_t)nMaxWeight)); + weight.push_back(Pair("minimum", (uint64_t)nMinWeight)); + weight.push_back(Pair("maximum", (uint64_t)nMaxWeight)); + weight.push_back(Pair("combined", (uint64_t)nWeight)); + obj.push_back(Pair("stakeweight", weight)); obj.push_back(Pair("stakeinterest", (uint64_t)GetProofOfStakeReward(0, GetLastBlockIndex(pindexBest, true)->nBits, GetLastBlockIndex(pindexBest, true)->nTime, true))); obj.push_back(Pair("testnet", fTestNet)); diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index cdbc5d4..a14c44f 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -69,7 +69,7 @@ Value getinfo(const Array& params, bool fHelp) proxyType proxy; GetProxy(NET_IPV4, proxy); - Object obj; + Object obj, diff; obj.push_back(Pair("version", FormatFullVersion())); obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION)); obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); @@ -82,7 +82,11 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); obj.push_back(Pair("ip", addrSeenByPeer.ToStringIP())); - obj.push_back(Pair("difficulty", (double)GetDifficulty())); + + diff.push_back(Pair("proof-of-work", GetDifficulty())); + diff.push_back(Pair("proof-of-stake", GetDifficulty(GetLastBlockIndex(pindexBest, true)))); + obj.push_back(Pair("difficulty", diff)); + obj.push_back(Pair("testnet", fTestNet)); obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); obj.push_back(Pair("keypoolsize", (int)pwalletMain->GetKeyPoolSize())); diff --git a/src/version.h b/src/version.h index e53f179..382fba7 100644 --- a/src/version.h +++ b/src/version.h @@ -24,13 +24,13 @@ extern const std::string CLIENT_DATE; // // database format versioning // -static const int DATABASE_VERSION = 70505; +static const int DATABASE_VERSION = 70507; // // network protocol versioning // -static const int PROTOCOL_VERSION = 60011; +static const int PROTOCOL_VERSION = 60012; // earlier versions not supported as of Feb 2012, and are disconnected static const int MIN_PROTO_VERSION = 209; diff --git a/src/wallet.cpp b/src/wallet.cpp index ca33136..0f00b4d 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -354,7 +354,7 @@ CWallet::TxItems CWallet::OrderedTxItems(std::list& acentries, return txOrdered; } -void CWallet::WalletUpdateSpent(const CTransaction &tx) +void CWallet::WalletUpdateSpent(const CTransaction &tx, bool fBlock) { // Anytime a signature is successfully verified, it's proof the outpoint is spent. // Update the wallet spent flag if it doesn't know due to wallet.dat being @@ -378,6 +378,24 @@ void CWallet::WalletUpdateSpent(const CTransaction &tx) } } } + + if (fBlock) + { + uint256 hash = tx.GetHash(); + map::iterator mi = mapWallet.find(hash); + CWalletTx& wtx = (*mi).second; + + BOOST_FOREACH(const CTxOut& txout, tx.vout) + { + if (IsMine(txout)) + { + wtx.MarkUnspent(&txout - &tx.vout[0]); + wtx.WriteToDisk(); + NotifyTransactionChanged(this, hash, CT_UPDATED); + } + } + } + } } @@ -500,7 +518,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) } #endif // since AddToWallet is called directly for self-originating transactions, check for consumption of own coins - WalletUpdateSpent(wtx); + WalletUpdateSpent(wtx, (wtxIn.hashBlock != 0)); // Notify UI of new or updated transaction NotifyTransactionChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED); diff --git a/src/wallet.h b/src/wallet.h index 26c1a2a..6f5ff57 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -173,7 +173,7 @@ public: bool AddToWallet(const CWalletTx& wtxIn); bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false, bool fFindBlock = false); bool EraseFromWallet(uint256 hash); - void WalletUpdateSpent(const CTransaction& prevout); + void WalletUpdateSpent(const CTransaction& prevout, bool fBlock = false); int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); int ScanForWalletTransaction(const uint256& hashTx); void ReacceptWalletTransactions();