Skip to content

Commit

Permalink
rename dummy client to cold wallet client
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Jan 24, 2024
1 parent e2604d1 commit b4711fa
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 396 deletions.
4 changes: 2 additions & 2 deletions wallet/wallet-cli-lib/src/commands/helper_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub fn parse_token_amount<N: NodeInterface>(

#[cfg(test)]
mod tests {
use node_comm::rpc_client::MaybeDummyNode;
use node_comm::rpc_client::ColdWalletClient;
use rstest::rstest;
use test_utils::random::{make_seedable_rng, Seed};

Expand All @@ -242,7 +242,7 @@ mod tests {
#[case(Seed::from_entropy())]
fn test_parse_utxo_outpoint(#[case] seed: Seed) {
fn check(input: String, is_tx: bool, idx: u32, hash: H256) {
let utxo_outpoint = parse_utxo_outpoint::<MaybeDummyNode>(input).unwrap();
let utxo_outpoint = parse_utxo_outpoint::<ColdWalletClient>(input).unwrap();

match utxo_outpoint.source_id() {
OutPointSourceId::Transaction(id) => {
Expand Down
8 changes: 4 additions & 4 deletions wallet/wallet-cli-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use common::chain::{
use config::{CliArgs, Network};
use console::{ConsoleInput, ConsoleOutput};
use errors::WalletCliError;
use node_comm::rpc_client::MaybeDummyNode;
use node_comm::rpc_client::ColdWalletClient;
use rpc::RpcAuthData;
use tokio::sync::mpsc;
use utils::{cookie::COOKIE_FILENAME, default_data_dir::default_data_dir_for_chain};
Expand Down Expand Up @@ -59,7 +59,7 @@ pub async fn run(
None => match &args.network {
Some(Network::Regtest(regtest_options)) => Arc::new(
regtest_chain_config(&regtest_options.chain_config).map_err(|err| {
WalletCliError::<MaybeDummyNode>::InvalidConfig(err.to_string())
WalletCliError::<ColdWalletClient>::InvalidConfig(err.to_string())
})?,
),
_ => Arc::new(common::chain::config::Builder::new(chain_type).build()),
Expand All @@ -70,7 +70,7 @@ pub async fn run(

let mode = if let Some(file_path) = &cli_args.commands_file {
repl::non_interactive::log::init();
let file_input = console::FileInput::new::<MaybeDummyNode>(file_path.clone())?;
let file_input = console::FileInput::new::<ColdWalletClient>(file_path.clone())?;
Mode::CommandsList { file_input }
} else if input.is_tty() {
let logger = repl::interactive::log::InteractiveLogger::init();
Expand Down Expand Up @@ -126,7 +126,7 @@ async fn start_hot_wallet(
password: password.clone(),
},
_ => {
return Err(Box::new(WalletCliError::<MaybeDummyNode>::InvalidConfig(
return Err(Box::new(WalletCliError::<ColdWalletClient>::InvalidConfig(
"Invalid RPC cookie/username/password combination".to_owned(),
)))
}
Expand Down
4 changes: 2 additions & 2 deletions wallet/wallet-node-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub async fn make_rpc_client(
rpc_client::NodeRpcClient::new(remote_socket_address, rpc_auth).await
}

pub fn make_cold_wallet_rpc_client(chain_config: Arc<ChainConfig>) -> rpc_client::MaybeDummyNode {
rpc_client::MaybeDummyNode::new(None, chain_config)
pub fn make_cold_wallet_rpc_client(chain_config: Arc<ChainConfig>) -> rpc_client::ColdWalletClient {
rpc_client::ColdWalletClient::new(chain_config)
}

pub async fn make_handles_client(
Expand Down
209 changes: 209 additions & 0 deletions wallet/wallet-node-client/src/rpc_client/cold_wallet_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
// Copyright (c) 2023 RBB S.r.l
// [email protected]
// SPDX-License-Identifier: MIT
// Licensed under the MIT License;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use chainstate::ChainInfo;
use common::{
chain::{
tokens::{RPCTokenInfo, TokenId},
Block, DelegationId, GenBlock, PoolId, SignedTransaction, Transaction,
},
primitives::{Amount, BlockHeight, Id},
};
use consensus::GenerateBlockInputData;
use crypto::ephemeral_e2e::EndToEndPublicKey;
use mempool::{tx_accumulator::PackingStrategy, tx_options::TxOptionsOverrides, FeeRate};
use p2p::{
interface::types::ConnectedPeer,
types::{bannable_address::BannableAddress, ip_or_socket_address::IpOrSocketAddress, PeerId},
};

use crate::node_traits::NodeInterface;

use super::ColdWalletClient;

#[derive(thiserror::Error, Debug)]
pub enum ColdWalletRpcError {
#[error("Methods is not available in cold wallet mode")]
NotAvailable,
}

#[async_trait::async_trait]
impl NodeInterface for ColdWalletClient {
type Error = ColdWalletRpcError;

async fn chainstate_info(&self) -> Result<ChainInfo, Self::Error> {
let genesis = self.chain_config.genesis_block();
Ok(ChainInfo {
best_block_id: self.chain_config.genesis_block_id(),
best_block_height: BlockHeight::zero(),
best_block_timestamp: genesis.timestamp(),
median_time: genesis.timestamp(),
is_initial_block_download: false,
})
}

async fn get_block(&self, _block_id: Id<Block>) -> Result<Option<Block>, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn get_mainchain_blocks(
&self,
_from: BlockHeight,
_max_count: usize,
) -> Result<Vec<Block>, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn get_best_block_id(&self) -> Result<Id<GenBlock>, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn get_best_block_height(&self) -> Result<common::primitives::BlockHeight, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn get_block_id_at_height(
&self,
_height: BlockHeight,
) -> Result<Option<Id<GenBlock>>, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn get_last_common_ancestor(
&self,
_first_block: Id<GenBlock>,
_second_block: Id<GenBlock>,
) -> Result<Option<(Id<GenBlock>, BlockHeight)>, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn get_stake_pool_balance(
&self,
_pool_id: PoolId,
) -> Result<Option<Amount>, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn get_staker_balance(&self, _pool_id: PoolId) -> Result<Option<Amount>, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn get_delegation_share(
&self,
_pool_id: PoolId,
_delegation_id: DelegationId,
) -> Result<Option<Amount>, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn get_token_info(
&self,
_token_id: TokenId,
) -> Result<Option<RPCTokenInfo>, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn generate_block_e2e_public_key(&self) -> Result<EndToEndPublicKey, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn generate_block_e2e(
&self,
_encrypted_input_data: Vec<u8>,
_public_key: EndToEndPublicKey,
_transactions: Vec<SignedTransaction>,
_transaction_ids: Vec<Id<Transaction>>,
_packing_strategy: PackingStrategy,
) -> Result<Block, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn generate_block(
&self,
_input_data: GenerateBlockInputData,
_transactions: Vec<SignedTransaction>,
_transaction_ids: Vec<Id<Transaction>>,
_packing_strategy: PackingStrategy,
) -> Result<Block, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn submit_block(&self, _block: Block) -> Result<(), Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn submit_transaction(
&self,
_tx: SignedTransaction,
_options: TxOptionsOverrides,
) -> Result<(), Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn node_shutdown(&self) -> Result<(), Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn node_version(&self) -> Result<String, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn p2p_connect(&self, _address: IpOrSocketAddress) -> Result<(), Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn p2p_disconnect(&self, _peer_id: PeerId) -> Result<(), Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn p2p_list_banned(&self) -> Result<Vec<BannableAddress>, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn p2p_ban(&self, _address: BannableAddress) -> Result<(), Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn p2p_unban(&self, _address: BannableAddress) -> Result<(), Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn p2p_get_peer_count(&self) -> Result<usize, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn p2p_get_connected_peers(&self) -> Result<Vec<ConnectedPeer>, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn p2p_add_reserved_node(&self, _address: IpOrSocketAddress) -> Result<(), Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn p2p_remove_reserved_node(
&self,
_address: IpOrSocketAddress,
) -> Result<(), Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn mempool_get_fee_rate(&self, _in_top_x_mb: usize) -> Result<FeeRate, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}

async fn mempool_get_fee_rate_points(&self) -> Result<Vec<(usize, FeeRate)>, Self::Error> {
Err(ColdWalletRpcError::NotAvailable)
}
}
Loading

0 comments on commit b4711fa

Please sign in to comment.