Skip to content

Commit

Permalink
Port interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Feb 21, 2024
1 parent e565352 commit 2d030b6
Show file tree
Hide file tree
Showing 6 changed files with 710 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <blockfilter.h>
#include <common/settings.h>
#include <primitives/transaction.h> // For CTransactionRef
#include <netbase.h> // For ConnectionDirection

#include <functional>
#include <memory>
Expand All @@ -16,6 +17,11 @@
#include <stdint.h>
#include <string>
#include <vector>
#include <map>

#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif

class ArgsManager;
class CBlock;
Expand All @@ -36,12 +42,15 @@ struct NodeContext;
} // namespace node
class ChainstateManager;
class CTxMemPool;
class CBlockIndex;
class CCoinsViewCache;

#ifdef ENABLE_WALLET
namespace wallet {
class CWallet;
} // namespace wallet
#endif
struct Delegation;

namespace interfaces {

Expand All @@ -65,6 +74,8 @@ class FoundBlock
FoundBlock& time(int64_t& time) { m_time = &time; return *this; }
FoundBlock& maxTime(int64_t& max_time) { m_max_time = &max_time; return *this; }
FoundBlock& mtpTime(int64_t& mtp_time) { m_mtp_time = &mtp_time; return *this; }
//! Return whether block has delagation.
FoundBlock& hasDelegation(bool& has_delegation) { m_has_delegation = &has_delegation; return *this; }
//! Return whether block is in the active (most-work) chain.
FoundBlock& inActiveChain(bool& in_active_chain) { m_in_active_chain = &in_active_chain; return *this; }
//! Return locator if block is in the active chain.
Expand All @@ -80,6 +91,7 @@ class FoundBlock
int64_t* m_time = nullptr;
int64_t* m_max_time = nullptr;
int64_t* m_mtp_time = nullptr;
bool* m_has_delegation = nullptr;
bool* m_in_active_chain = nullptr;
CBlockLocator* m_locator = nullptr;
const FoundBlock* m_next_block = nullptr;
Expand Down Expand Up @@ -197,6 +209,9 @@ class Chain
const FoundBlock& block1_out={},
const FoundBlock& block2_out={}) = 0;

//! Get map of the immature stakes.
virtual std::map<COutPoint, uint32_t> getImmatureStakes() = 0;

//! Look up unspent output information. Returns coins in the mempool and in
//! the current chain UTXO set. Iterates through all the keys in the map and
//! populates the values.
Expand Down Expand Up @@ -297,6 +312,9 @@ class Chain
//! Check if any block has been pruned.
virtual bool havePruned() = 0;

//! Is loading blocks.
virtual bool isLoadingBlocks() = 0;

//! Check if the node is ready to broadcast transactions.
virtual bool isReadyToBroadcast() = 0;

Expand All @@ -306,6 +324,9 @@ class Chain
//! Check if shutdown requested.
virtual bool shutdownRequested() = 0;

//! Get adjusted time.
virtual int64_t getAdjustedTime() = 0;

//! Send init message.
virtual void initMessage(const std::string& message) = 0;

Expand Down Expand Up @@ -381,13 +402,46 @@ class Chain
//! accessible across processes.
virtual node::NodeContext* context() { return nullptr; }

//! Get chain tip
virtual CBlockIndex* getTip() const = 0;

//! Get unspent outputs associated with a transaction.
virtual bool getUnspentOutput(const COutPoint& output, Coin& coin) = 0;

//! Get coins tip.
virtual CCoinsViewCache& getCoinsTip() = 0;

//! Get number of connections.
virtual size_t getNodeCount(ConnectionDirection flags) = 0;

//! Get transaction gas fee.
virtual CAmount getTxGasFee(const CMutableTransaction& tx) = 0;

#ifdef ENABLE_WALLET
//! Start staking qtums.
virtual void startStake(wallet::CWallet& wallet) = 0;

//! Stop staking qtums.
virtual void stopStake(wallet::CWallet& wallet) = 0;

//! get stake weight.
virtual uint64_t getStakeWeight(const wallet::CWallet& wallet, uint64_t* pStakerWeight = nullptr, uint64_t* pDelegateWeight = nullptr) = 0;

//! refresh delegates.
virtual void refreshDelegates(wallet::CWallet *pwallet, bool myDelegates, bool stakerDelegates) = 0;

//! get contract RPC commands.
virtual Span<const CRPCCommand> getContractRPCCommands() = 0;

//! get mining RPC commands.
virtual Span<const CRPCCommand> getMiningRPCCommands() = 0;
#endif

//! get delegation for an address.
virtual bool getDelegation(const uint160& address, Delegation& delegation) = 0;

//! verify delegation for an address.
virtual bool verifyDelegation(const uint160& address, const Delegation& delegation) = 0;
};

//! Interface to let node manage chain clients (wallets, or maybe tools for
Expand Down
33 changes: 33 additions & 0 deletions src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,21 @@ class Node
//! Get last block time.
virtual int64_t getLastBlockTime() = 0;

//! Get block hash.
virtual uint256 getBlockHash(int blockNumber) = 0;

//! Get block time.
virtual int64_t getBlockTime(int blockNumber) = 0;

//! Get verification progress.
virtual double getVerificationProgress() = 0;

//! Is initial block download.
virtual bool isInitialBlockDownload() = 0;

//! Is -addresstype set.
virtual bool isAddressTypeSet() = 0;

//! Is loading blocks.
virtual bool isLoadingBlocks() = 0;

Expand All @@ -189,6 +198,12 @@ class Node
//! Get network active.
virtual bool getNetworkActive() = 0;

//! Get node synchronization information.
virtual void getSyncInfo(int& numBlocks, bool& isSyncing) = 0;

//! Try get node synchronization information.
virtual bool tryGetSyncInfo(int& numBlocks, bool& isSyncing) = 0;

//! Get dust relay fee.
virtual CFeeRate getDustRelayFee() = 0;

Expand All @@ -213,6 +228,24 @@ class Node
//! Get wallet loader.
virtual WalletLoader& walletLoader() = 0;

//! Get the information about the needed gas
virtual void getGasInfo(uint64_t& blockGasLimit, uint64_t& minGasPrice, uint64_t& nGasPrice) = 0;

//! Get the reward for the block at some specific height
virtual int64_t getBlockSubsidy(int nHeight) = 0;

//! Get the network stake weight
virtual uint64_t getNetworkStakeWeight() = 0;

//! Get the estimated annual roi
virtual double getEstimatedAnnualROI() = 0;

//! Get the money supply
virtual int64_t getMoneySupply() = 0;

//! Get PoS kernel PS
virtual double getPoSKernelPS() = 0;

//! Register handler for init messages.
using InitMessageFn = std::function<void(const std::string& message)>;
virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
Expand Down
Loading

0 comments on commit 2d030b6

Please sign in to comment.