From 2d030b6bc6fd1c1874539680e9e3ebf88c015ced Mon Sep 17 00:00:00 2001 From: timemarkovqtum Date: Wed, 21 Feb 2024 15:59:03 +0100 Subject: [PATCH] Port interfaces --- src/interfaces/chain.h | 54 ++++++++ src/interfaces/node.h | 33 +++++ src/interfaces/wallet.h | 198 +++++++++++++++++++++++++++ src/node/interfaces.cpp | 118 ++++++++++++++++ src/wallet/interfaces.cpp | 277 ++++++++++++++++++++++++++++++++++++++ src/wallet/wallet.h | 30 +++++ 6 files changed, 710 insertions(+) diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index ec25858383..6d575fffc6 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -8,6 +8,7 @@ #include #include #include // For CTransactionRef +#include // For ConnectionDirection #include #include @@ -16,6 +17,11 @@ #include #include #include +#include + +#if defined(HAVE_CONFIG_H) +#include +#endif class ArgsManager; class CBlock; @@ -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 { @@ -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. @@ -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; @@ -197,6 +209,9 @@ class Chain const FoundBlock& block1_out={}, const FoundBlock& block2_out={}) = 0; + //! Get map of the immature stakes. + virtual std::map 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. @@ -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; @@ -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; @@ -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 getContractRPCCommands() = 0; + + //! get mining RPC commands. + virtual Span 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 diff --git a/src/interfaces/node.h b/src/interfaces/node.h index 3f8df57124..0419a95e1f 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -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; @@ -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; @@ -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; virtual std::unique_ptr handleInitMessage(InitMessageFn fn) = 0; diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index 32bf19c722..d1988335c1 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -241,6 +241,15 @@ class Wallet //! Return credit amount if transaction input belongs to wallet. virtual CAmount getCredit(const CTxOut& txout, wallet::isminefilter filter) = 0; + //! Check if address have unspent coins + virtual bool isUnspentAddress(const std::string& address) = 0; + + //! Check if address is mine + virtual bool isMineAddress(const std::string &strAddress) = 0; + + //! Try get available coins addresses + virtual bool tryGetAvailableAddresses(std::vector &spendableAddresses, std::vector &allAddresses, bool &includeZeroValue) = 0; + //! Return AvailableCoins + LockedCoins grouped by wallet address. //! (put change in one group with wallet address) using CoinsList = std::map>>; @@ -276,6 +285,9 @@ class Wallet // Return whether wallet uses an external signer. virtual bool hasExternalSigner() = 0; + // Return whether wallet uses descriptors. + virtual bool hasDescriptors() = 0; + // Get default address type. virtual OutputType getDefaultAddressType() = 0; @@ -288,6 +300,165 @@ class Wallet //! Return whether is a legacy wallet virtual bool isLegacy() = 0; + //! Add wallet token entry. + virtual bool addTokenEntry(const TokenInfo &token) = 0; + + //! Add wallet token transaction entry. + virtual bool addTokenTxEntry(const TokenTx& tokenTx, bool fFlushOnClose=true) = 0; + + //! Check if exist wallet token entry. + virtual bool existTokenEntry(const TokenInfo &token) = 0; + + //! Remove wallet token entry. + virtual bool removeTokenEntry(const std::string &sHash) = 0; + + //! Get invalid wallet tokens + virtual std::vector getInvalidTokens() = 0; + + //! Get token transaction information. + virtual TokenTx getTokenTx(const uint256& txid) = 0; + + //! Get list of all wallet token transactions. + virtual std::vector getTokenTxs() = 0; + + //! Get token information. + virtual TokenInfo getToken(const uint256& id) = 0; + + //! Get list of all tokens. + virtual std::vector getTokens() = 0; + + //! Try to get updated status for a particular token transaction, if possible without blocking. + virtual bool tryGetTokenTxStatus(const uint256& txid, int& block_number, bool& in_mempool, int& num_blocks) = 0; + + //! Get updated status for a particular token transaction. + virtual bool getTokenTxStatus(const uint256& txid, int& block_number, bool& in_mempool, int& num_blocks) = 0; + + //! Get token transaction details + virtual bool getTokenTxDetails(const TokenTx &wtx, uint256& credit, uint256& debit, std::string& tokenSymbol, uint8_t& decimals) = 0; + + //! Clean token transaction entries in the wallet + virtual bool cleanTokenTxEntries() = 0; + + //! Check if token transaction is mine + virtual bool isTokenTxMine(const TokenTx &wtx) = 0; + + //! Get contract book data. + virtual ContractBookData getContractBook(const std::string& address) = 0; + + //! Get list of all contract book data. + virtual std::vector getContractBooks() = 0; + + //! Check if exist contract book. + virtual bool existContractBook(const std::string& address) = 0; + + //! Delete contract book data. + virtual bool delContractBook(const std::string& address) = 0; + + //! Set contract book data. + virtual bool setContractBook(const std::string& address, const std::string& name, const std::string& abi) = 0; + + //! Restore wallet delegations. + virtual uint32_t restoreDelegations() = 0; + + //! Add wallet delegation entry. + virtual bool addDelegationEntry(const DelegationInfo &delegation) = 0; + + //! Check if exist wallet delegation entry. + virtual bool existDelegationEntry(const DelegationInfo &delegation) = 0; + + //! Get delegation information. + virtual DelegationInfo getDelegation(const uint256& id) = 0; + + //! Get delegation information from contract. + virtual DelegationInfo getDelegationContract(const std::string &sHash, bool& validated, bool& contractRet) = 0; + + //! Get delegation details for address. + virtual DelegationDetails getDelegationDetails(const std::string &sAddress) = 0; + + //! Get list of all delegations. + virtual std::vector getDelegations() = 0; + + //! Remove wallet delegation entry. + virtual bool removeDelegationEntry(const std::string &sHash) = 0; + + //! Set delegation entry removed. + virtual bool setDelegationRemoved(const std::string &sHash, const std::string &sTxid) = 0; + + //! Restore wallet super stakers. + virtual uint32_t restoreSuperStakers() = 0; + + //! Exist super staker. + virtual bool existSuperStaker(const std::string &sAddress) = 0; + + //! Get super staker information. + virtual SuperStakerInfo getSuperStaker(const uint256& id) = 0; + + //! Get super staker recommended config. + virtual SuperStakerInfo getSuperStakerRecommendedConfig() = 0; + + //! Get list of all super stakers. + virtual std::vector getSuperStakers() = 0; + + //! Add wallet super staker entry. + virtual bool addSuperStakerEntry(const SuperStakerInfo &superStaker) = 0; + + //! Remove wallet super staker entry. + virtual bool removeSuperStakerEntry(const std::string &sHash) = 0; + + //! Get the super staker weight + virtual uint64_t getSuperStakerWeight(const uint256& id) = 0; + + //! Is super staker staking + virtual bool isSuperStakerStaking(const uint256& id, CAmount& delegationsWeight) = 0; + + //! Try get the stake weight + virtual bool tryGetStakeWeight(uint64_t& nWeight) = 0; + + //! Get the stake weight + virtual uint64_t getStakeWeight() = 0; + + //! Get last coin stake search interval + virtual int64_t getLastCoinStakeSearchInterval() = 0; + + //! Get wallet unlock for staking only + virtual bool getWalletUnlockStakingOnly() = 0; + + //! Set wallet unlock for staking only + virtual void setWalletUnlockStakingOnly(bool unlock) = 0; + + //! Set wallet enabled for staking + virtual void setEnabledStaking(bool enabled) = 0; + + //! Get wallet enabled for staking + virtual bool getEnabledStaking() = 0; + + //! Get wallet enabled for super staking + virtual bool getEnabledSuperStaking() = 0; + + //! Get a delegation from super staker. + virtual DelegationStakerInfo getDelegationStaker(const uint160& id) = 0; + + //! Get list of all delegations for super stakers. + virtual std::vector getDelegationsStakers() = 0; + + //! Get staker address balance. + virtual bool getStakerAddressBalance(const std::string& staker, CAmount& balance, CAmount& stake, CAmount& weight) = 0; + + //! Get add delegation data to sign. + virtual bool getAddDelegationData(const std::string& psbt, std::map& signData, std::string& error) = 0; + + //! Set signed add delegation data. + virtual bool setAddDelegationData(std::string& psbt, const std::map& signData, std::string& error) = 0; + + //! Set staker ledger id. + virtual void setStakerLedgerId(const std::string& ledgerId) = 0; + + //! Get staker ledger id. + virtual std::string getStakerLedgerId() = 0; + + //! Get HD key path + virtual bool getHDKeyPath(const CTxDestination& dest, std::string& hdkeypath) = 0; + //! Register handler for unload message. using UnloadFn = std::function; virtual std::unique_ptr handleUnload(UnloadFn fn) = 0; @@ -312,6 +483,14 @@ class Wallet using TransactionChangedFn = std::function; virtual std::unique_ptr handleTransactionChanged(TransactionChangedFn fn) = 0; + //! Register handler for token transaction changed messages. + using TokenTransactionChangedFn = std::function; + virtual std::unique_ptr handleTokenTransactionChanged(TokenTransactionChangedFn fn) = 0; + + //! Register handler for token changed messages. + using TokenChangedFn = std::function; + virtual std::unique_ptr handleTokenChanged(TokenChangedFn fn) = 0; + //! Register handler for watchonly changed messages. using WatchOnlyChangedFn = std::function; virtual std::unique_ptr handleWatchOnlyChanged(WatchOnlyChangedFn fn) = 0; @@ -320,6 +499,25 @@ class Wallet using CanGetAddressesChangedFn = std::function; virtual std::unique_ptr handleCanGetAddressesChanged(CanGetAddressesChangedFn fn) = 0; + //! Register handler for contract book changed messages. + using ContractBookChangedFn = std::function; + virtual std::unique_ptr handleContractBookChanged(ContractBookChangedFn fn) = 0; + + //! Register handler for delegation changed messages. + using DelegationChangedFn = std::function; + virtual std::unique_ptr handleDelegationChanged(DelegationChangedFn fn) = 0; + + //! Register handler for super staker changed messages. + using SuperStakerChangedFn = std::function; + virtual std::unique_ptr handleSuperStakerChanged(SuperStakerChangedFn fn) = 0; + + //! Register handler for delegations staker changed messages. + using DelegationsStakerChangedFn = std::function; + virtual std::unique_ptr handleDelegationsStakerChanged(DelegationsStakerChangedFn fn) = 0; + //! Return pointer to internal wallet class, useful for testing. virtual wallet::CWallet* wallet() { return nullptr; } }; diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index fda950aa9e..fbbb523ac9 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -299,6 +300,18 @@ class NodeImpl : public Node } return chainman().GetParams().GenesisBlock().GetBlockTime(); // Genesis block's time of current network } + uint256 getBlockHash(int blockNumber) override + { + LOCK(::cs_main); + CBlockIndex* index = chainman().ActiveChain()[blockNumber]; + return index ? index->GetBlockHash() : uint256(); + } + int64_t getBlockTime(int blockNumber) override + { + LOCK(::cs_main); + CBlockIndex* index = chainman().ActiveChain()[blockNumber]; + return index ? index->GetBlockTime() : 0; + } double getVerificationProgress() override { return GuessVerificationProgress(chainman().GetParams().TxData(), WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip())); @@ -307,6 +320,7 @@ class NodeImpl : public Node { return chainman().IsInitialBlockDownload(); } + bool isAddressTypeSet() override { return !::gArgs.GetArg("-addresstype", "").empty(); } bool isLoadingBlocks() override { return chainman().m_blockman.LoadingBlocks(); } void setNetworkActive(bool active) override { @@ -345,6 +359,55 @@ class NodeImpl : public Node { return *Assert(m_context->wallet_loader); } + void getGasInfo(uint64_t& blockGasLimit, uint64_t& minGasPrice, uint64_t& nGasPrice) override + { + } + void getSyncInfo(int& numBlocks, bool& isSyncing) override + { + LOCK(::cs_main); + // Get node synchronization information with minimal locks + numBlocks = chainman().ActiveChain().Height(); + int64_t blockTime = chainman().ActiveChain().Tip() ? chainman().ActiveChain().Tip()->GetBlockTime() : + Params().GenesisBlock().GetBlockTime(); + int64_t secs = GetTime() - blockTime; + isSyncing = secs >= 90*60 ? true : false; + } + bool tryGetSyncInfo(int& numBlocks, bool& isSyncing) override + { + TRY_LOCK(::cs_main, lockMain); + if (lockMain) { + // Get node synchronization information with minimal locks + numBlocks = chainman().ActiveChain().Height(); + int64_t blockTime = chainman().ActiveChain().Tip() ? chainman().ActiveChain().Tip()->GetBlockTime() : + Params().GenesisBlock().GetBlockTime(); + int64_t secs = GetTime() - blockTime; + isSyncing = secs >= 90*60 ? true : false; + return true; + } + + return false; + } + int64_t getBlockSubsidy(int nHeight) override + { + return {}; + } + uint64_t getNetworkStakeWeight() override + { + return {}; + } + double getEstimatedAnnualROI() override + { + return {}; + } + int64_t getMoneySupply() override + { + auto best_header = chainman().m_best_header; + return best_header ? best_header->nMoneySupply : 0; + } + double getPoSKernelPS() override + { + return {}; + } std::unique_ptr handleInitMessage(InitMessageFn fn) override { return MakeSignalHandler(::uiInterface.InitMessage_connect(fn)); @@ -413,6 +476,7 @@ bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLockGetBlockTime(); if (block.m_max_time) *block.m_max_time = index->GetBlockTimeMax(); if (block.m_mtp_time) *block.m_mtp_time = index->GetMedianTimePast(); + if (block.m_has_delegation) *block.m_has_delegation = index->HasProofOfDelegation(); if (block.m_in_active_chain) *block.m_in_active_chain = active[index->nHeight] == index; if (block.m_locator) { *block.m_locator = GetLocator(index); } if (block.m_next_block) FillBlock(active[index->nHeight] == index ? active[index->nHeight + 1] : nullptr, *block.m_next_block, lock, active, blockman); @@ -545,6 +609,10 @@ class ChainImpl : public Chain const CBlockIndex* index = chainman().m_blockman.LookupBlockIndex(block_hash); return GetLocator(index); } + std::map getImmatureStakes() override + { + return {}; + } std::optional findLocatorFork(const CBlockLocator& locator) override { LOCK(::cs_main); @@ -745,12 +813,14 @@ class ChainImpl : public Chain LOCK(::cs_main); return chainman().m_blockman.m_have_pruned; } + bool isLoadingBlocks() override { return chainman().m_blockman.LoadingBlocks(); } bool isReadyToBroadcast() override { return !chainman().m_blockman.LoadingBlocks() && !isInitialBlockDownload(); } bool isInitialBlockDownload() override { return chainman().IsInitialBlockDownload(); } bool shutdownRequested() override { return ShutdownRequested(); } + int64_t getAdjustedTime() override { return TicksSinceEpoch(GetAdjustedTime()); } void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); } void initWarning(const bilingual_str& message) override { InitWarning(message); } void initError(const bilingual_str& message) override { InitError(message); } @@ -823,15 +893,63 @@ class ChainImpl : public Chain ArgsManager& args() { return *Assert(m_node.args); } ChainstateManager& chainman() override { return *Assert(m_node.chainman); } const CTxMemPool& mempool() override { return *Assert(m_node.mempool); } + + CBlockIndex* getTip() const override + { + LOCK(::cs_main); + CBlockIndex* tip = Assert(m_node.chainman)->ActiveChain().Tip(); + return tip; + } + bool getUnspentOutput(const COutPoint& output, Coin& coin) override + { + LOCK(::cs_main); + return chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin); + } + CCoinsViewCache& getCoinsTip() override + { + LOCK(::cs_main); + return chainman().ActiveChainstate().CoinsTip(); + } + size_t getNodeCount(ConnectionDirection flags) override + { + return Assert(m_node.connman) ? m_node.connman->GetNodeCount(flags) : 0; + } CAmount getTxGasFee(const CMutableTransaction& tx) override { return GetTxGasFee(tx, mempool(), chainman().ActiveChainstate()); } #ifdef ENABLE_WALLET + void startStake(wallet::CWallet& wallet) override + { + } void stopStake(wallet::CWallet& wallet) override { } + uint64_t getStakeWeight(const wallet::CWallet& wallet, uint64_t* pStakerWeight, uint64_t* pDelegateWeight) override + { + return {}; + } + void refreshDelegates(wallet::CWallet *pwallet, bool myDelegates, bool stakerDelegates) override + { + } + Span getContractRPCCommands() override + { + return {}; + } + Span getMiningRPCCommands() override + { + return {}; + } #endif + bool getDelegation(const uint160& address, Delegation& delegation) override + { + return {}; + } + bool verifyDelegation(const uint160& address, const Delegation& delegation) override + { + return {}; + } + NodeContext& m_node; }; } // namespace diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp index 65285187f4..e83ec20203 100644 --- a/src/wallet/interfaces.cpp +++ b/src/wallet/interfaces.cpp @@ -27,11 +27,15 @@ #include #include #include +#include +#include +#include #include #include #include #include +#include using interfaces::Chain; using interfaces::FoundBlock; @@ -47,6 +51,15 @@ using interfaces::WalletTx; using interfaces::WalletTxOut; using interfaces::WalletTxStatus; using interfaces::WalletValueMap; +using interfaces::TokenInfo; +using interfaces::TokenTx; +using interfaces::ContractBookData; +using interfaces::DelegationInfo; +using interfaces::DelegationDetails; +using interfaces::SuperStakerInfo; +using interfaces::DelegationStakerInfo; +using interfaces::SuperStakerAddressList; +using interfaces::SignDelegation; namespace wallet { // All members of the classes in this namespace are intentionally public, as the @@ -101,6 +114,7 @@ WalletTxStatus MakeWalletTxStatus(const CWallet& wallet, const CWalletTx& wtx) result.is_abandoned = wtx.isAbandoned(); result.is_coinbase = wtx.IsCoinBase(); result.is_in_main_chain = wallet.IsTxInMainChain(wtx); + result.is_coinstake = wtx.IsCoinStake(); return result; } @@ -404,11 +418,13 @@ class WalletImpl : public Wallet result.balance = bal.m_mine_trusted; result.unconfirmed_balance = bal.m_mine_untrusted_pending; result.immature_balance = bal.m_mine_immature; + result.stake = bal.m_mine_stake; result.have_watch_only = haveWatchOnly(); if (result.have_watch_only) { result.watch_only_balance = bal.m_watchonly_trusted; result.unconfirmed_watch_only_balance = bal.m_watchonly_untrusted_pending; result.immature_watch_only_balance = bal.m_watchonly_immature; + result.watch_only_stake = bal.m_watchonly_stake; } return result; } @@ -464,6 +480,22 @@ class WalletImpl : public Wallet LOCK(m_wallet->cs_wallet); return OutputGetCredit(*m_wallet, txout, filter); } + bool isUnspentAddress(const std::string &qtumAddress) override + { + return {}; + } + bool isMineAddress(const std::string &strAddress) override + { + return {}; + } + std::vector availableAddresses(bool fIncludeZeroValue) EXCLUSIVE_LOCKS_REQUIRED(m_wallet->cs_wallet) + { + return {}; + } + bool tryGetAvailableAddresses(std::vector &spendableAddresses, std::vector &allAddresses, bool &includeZeroValue) override + { + return {}; + } CoinsList listCoins() override { LOCK(m_wallet->cs_wallet); @@ -517,6 +549,7 @@ class WalletImpl : public Wallet auto spk_man = m_wallet->GetScriptPubKeyMan(OutputType::BECH32M, /*internal=*/false); return spk_man != nullptr; } + bool hasDescriptors() override { return m_wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS); } OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; } CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; } void remove() override @@ -524,6 +557,219 @@ class WalletImpl : public Wallet RemoveWallet(m_context, m_wallet, /*load_on_start=*/false); } bool isLegacy() override { return m_wallet->IsLegacy(); } + bool addTokenEntry(const TokenInfo &token) override + { + } + bool addTokenTxEntry(const TokenTx& tokenTx, bool fFlushOnClose) override + { + } + bool existTokenEntry(const TokenInfo &token) override + { + return {}; + } + bool removeTokenEntry(const std::string &sHash) override + { + return {}; + } + std::vector getInvalidTokens() override + { + return {}; + } + TokenTx getTokenTx(const uint256& txid) override + { + return {}; + } + std::vector getTokenTxs() override + { + return {}; + } + TokenInfo getToken(const uint256& id) override + { + return {}; + } + std::vector getTokens() override + { + return {}; + } + bool tryGetTokenTxStatus(const uint256& txid, int& block_number, bool& in_mempool, int& num_blocks) override + { + return {}; + } + bool getTokenTxStatus(const uint256& txid, int& block_number, bool& in_mempool, int& num_blocks) override + { + return {}; + } + bool getTokenTxDetails(const TokenTx &wtx, uint256& credit, uint256& debit, std::string& tokenSymbol, uint8_t& decimals) override + { + return {}; + } + bool isTokenTxMine(const TokenTx &wtx) override + { + return {}; + } + ContractBookData getContractBook(const std::string& id) override + { + return {}; + } + std::vector getContractBooks() override + { + return {}; + } + bool existContractBook(const std::string& id) override + { + return {}; + } + bool delContractBook(const std::string& id) override + { + return {}; + } + bool setContractBook(const std::string& id, const std::string& name, const std::string& abi) override + { + return {}; + } + uint32_t restoreDelegations() override + { + return {}; + } + bool addDelegationEntry(const DelegationInfo &delegation) override + { + return {}; + } + bool existDelegationEntry(const DelegationInfo &delegation) override + { + return {}; + } + DelegationInfo getDelegation(const uint256& id) override + { + return {}; + } + DelegationInfo getDelegationContract(const std::string &sHash, bool& validated, bool& contractRet) override + { + return {}; + } + DelegationDetails getDelegationDetails(const std::string &sAddress) override + { + return {}; + } + std::vector getDelegations() override + { + return {}; + } + bool removeDelegationEntry(const std::string &sHash) override + { + return {}; + } + bool setDelegationRemoved(const std::string &sHash, const std::string &sTxid) override + { + return {}; + } + uint32_t restoreSuperStakers() override + { + return {}; + } + bool existSuperStaker(const std::string &sAddress) override + { + return {}; + } + SuperStakerInfo getSuperStaker(const uint256& id) override + { + return {}; + } + SuperStakerInfo getSuperStakerRecommendedConfig() override + { + return {}; + } + std::vector getSuperStakers() override + { + return {}; + } + bool addSuperStakerEntry(const SuperStakerInfo &superStaker) override + { + return {}; + } + bool removeSuperStakerEntry(const std::string &sHash) override + { + return {}; + } + bool tryGetStakeWeight(uint64_t& nWeight) override + { + return {}; + } + uint64_t getStakeWeight() override + { + return {}; + } + int64_t getLastCoinStakeSearchInterval() override + { + return m_wallet->m_last_coin_stake_search_interval; + } + bool getWalletUnlockStakingOnly() override + { + return m_wallet->m_wallet_unlock_staking_only; + } + void setWalletUnlockStakingOnly(bool unlock) override + { + m_wallet->m_wallet_unlock_staking_only = unlock; + } + bool cleanTokenTxEntries() override + { + return {}; + } + void setEnabledStaking(bool enabled) override + { + m_wallet->m_enabled_staking = enabled; + } + bool getEnabledStaking() override + { + return m_wallet->m_enabled_staking; + } + bool getEnabledSuperStaking() override + { + bool fSuperStake = gArgs.GetBoolArg("-superstaking", node::DEFAULT_SUPER_STAKE); + return fSuperStake; + } + DelegationStakerInfo getDelegationStaker(const uint160& id) override + { + return {}; + } + std::vector getDelegationsStakers() override + { + return {}; + } + uint64_t getSuperStakerWeight(const uint256& id) override + { + return {}; + } + bool isSuperStakerStaking(const uint256& id, CAmount& delegationsWeight) override + { + return {}; + } + bool getStakerAddressBalance(const std::string& staker, CAmount& balance, CAmount& stake, CAmount& weight) override + { + return {}; + } + bool getAddDelegationData(const std::string& psbt, std::map& signData, std::string& error) override + { + return {}; + } + bool setAddDelegationData(std::string& psbt, const std::map& signData, std::string& error) override + { + return {}; + } + void setStakerLedgerId(const std::string& ledgerId) override + { + LOCK(m_wallet->cs_wallet); + m_wallet->m_ledger_id = ledgerId; + } + std::string getStakerLedgerId() override + { + LOCK(m_wallet->cs_wallet); + return m_wallet->m_ledger_id; + } + bool getHDKeyPath(const CTxDestination& dest, std::string& hdkeypath) override + { + return {}; + } std::unique_ptr handleUnload(UnloadFn fn) override { return MakeSignalHandler(m_wallet->NotifyUnload.connect(fn)); @@ -547,6 +793,16 @@ class WalletImpl : public Wallet return MakeSignalHandler(m_wallet->NotifyTransactionChanged.connect( [fn](const uint256& txid, ChangeType status) { fn(txid, status); })); } + std::unique_ptr handleTokenTransactionChanged(TokenTransactionChangedFn fn) override + { + return MakeSignalHandler(m_wallet->NotifyTokenTransactionChanged.connect( + [fn](CWallet*, const uint256& id, ChangeType status) { fn(id, status); })); + } + std::unique_ptr handleTokenChanged(TokenChangedFn fn) override + { + return MakeSignalHandler(m_wallet->NotifyTokenChanged.connect( + [fn](CWallet*, const uint256& id, ChangeType status) { fn(id, status); })); + } std::unique_ptr handleWatchOnlyChanged(WatchOnlyChangedFn fn) override { return MakeSignalHandler(m_wallet->NotifyWatchonlyChanged.connect(fn)); @@ -555,6 +811,27 @@ class WalletImpl : public Wallet { return MakeSignalHandler(m_wallet->NotifyCanGetAddressesChanged.connect(fn)); } + std::unique_ptr handleContractBookChanged(ContractBookChangedFn fn) override + { + return MakeSignalHandler(m_wallet->NotifyContractBookChanged.connect( + [fn](CWallet*, const std::string& address, const std::string& label, + const std::string& abi, ChangeType status) { fn(address, label, abi, status); })); + } + std::unique_ptr handleDelegationChanged(DelegationChangedFn fn) override + { + return MakeSignalHandler(m_wallet->NotifyDelegationChanged.connect( + [fn](CWallet*, const uint256& id, ChangeType status) { fn(id, status); })); + } + std::unique_ptr handleSuperStakerChanged(SuperStakerChangedFn fn) override + { + return MakeSignalHandler(m_wallet->NotifySuperStakerChanged.connect( + [fn](CWallet*, const uint256& id, ChangeType status) { fn(id, status); })); + } + std::unique_ptr handleDelegationsStakerChanged(DelegationsStakerChangedFn fn) override + { + return MakeSignalHandler(m_wallet->NotifyDelegationsStakerChanged.connect( + [fn](CWallet*, const uint160& id, ChangeType status) { fn(id, status); })); + } CWallet* wallet() override { return m_wallet.get(); } WalletContext& m_context; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 681b713933..42a5d0029f 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -875,6 +875,13 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati */ boost::signals2::signal NotifyTransactionChanged; + /** + * Wallet token transaction added, removed or updated. + * @note called with lock cs_wallet held. + */ + boost::signals2::signal NotifyTokenTransactionChanged; + /** Show progress e.g. for rescan */ boost::signals2::signal ShowProgress; @@ -890,6 +897,27 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati */ boost::signals2::signal NotifyStatusChanged; + /** Wallet transaction added, removed or updated. */ + boost::signals2::signal NotifyTokenChanged; + + /** Contract book entry changed. */ + boost::signals2::signal NotifyContractBookChanged; + + /** Wallet delegation added, removed or updated. */ + boost::signals2::signal NotifyDelegationChanged; + + /** Wallet super staker added, removed or updated. */ + boost::signals2::signal NotifySuperStakerChanged; + + /** Wallet delegations staker added, removed or updated. */ + boost::signals2::signal NotifyDelegationsStakerChanged; + /** Inquire whether this wallet broadcasts transactions. */ bool GetBroadcastTransactions() const { return fBroadcastTransactions; } /** Set whether this wallet broadcasts transactions. */ @@ -1078,6 +1106,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati /* Stop staking qtums */ void StopStake(); + + std::string m_ledger_id; }; /**