Skip to content

Commit

Permalink
Refactor: Use core's Blockchain instead of syncer's Coin type
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCharlatan committed Jul 27, 2022
1 parent 9fabb42 commit 77ed695
Show file tree
Hide file tree
Showing 20 changed files with 249 additions and 263 deletions.
4 changes: 2 additions & 2 deletions shell/_swap-cli
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ _arguments "${_arguments_options[@]}" \
'--ctl-socket=[ZMQ socket name/address for daemon control interface]:CTL_SOCKET:_files' \
'-h[Print help information]' \
'--help[Print help information]' \
':coin -- The coin funding required needs to be checked against:' \
':blockchain -- The blockchain funding required needs to be checked against:' \
&& ret=0
;;
(sweep-bitcoin-address)
Expand Down Expand Up @@ -334,7 +334,7 @@ _swap-cli_commands() {
'revoke-offer:Revoke offer accepts an offer and revokes it within the runtime' \
'abort-swap:Abort a swap if it has not locked yet' \
'progress:Request swap progress report' \
'needs-funding:Returns addresses and amounts that require funding for coin' \
'needs-funding:Returns addresses and amounts that require funding for blockchain' \
'sweep-bitcoin-address:Attempts to sweep any funds on a given bitcoin funding address' \
'sweep-monero-address:Attempts to sweep any funds on a given monero funding address' \
'help:Print this message or the help of the given subcommand(s)' \
Expand Down
2 changes: 1 addition & 1 deletion shell/_swap-cli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Register-ArgumentCompleter -Native -CommandName 'swap-cli' -ScriptBlock {
[CompletionResult]::new('revoke-offer', 'revoke-offer', [CompletionResultType]::ParameterValue, 'Revoke offer accepts an offer and revokes it within the runtime')
[CompletionResult]::new('abort-swap', 'abort-swap', [CompletionResultType]::ParameterValue, 'Abort a swap if it has not locked yet')
[CompletionResult]::new('progress', 'progress', [CompletionResultType]::ParameterValue, 'Request swap progress report')
[CompletionResult]::new('needs-funding', 'needs-funding', [CompletionResultType]::ParameterValue, 'Returns addresses and amounts that require funding for coin')
[CompletionResult]::new('needs-funding', 'needs-funding', [CompletionResultType]::ParameterValue, 'Returns addresses and amounts that require funding for blockchain')
[CompletionResult]::new('sweep-bitcoin-address', 'sweep-bitcoin-address', [CompletionResultType]::ParameterValue, 'Attempts to sweep any funds on a given bitcoin funding address')
[CompletionResult]::new('sweep-monero-address', 'sweep-monero-address', [CompletionResultType]::ParameterValue, 'Attempts to sweep any funds on a given monero funding address')
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
Expand Down
2 changes: 1 addition & 1 deletion shell/swap-cli.bash
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ _swap-cli() {
return 0
;;
swap__cli__needs__funding)
opts="-h -d -T -m -x --help --data-dir --tor-proxy --msg-socket --ctl-socket <COIN>"
opts="-h -d -T -m -x --help --data-dir --tor-proxy --msg-socket --ctl-socket <BLOCKCHAIN>"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
11 changes: 4 additions & 7 deletions src/cli/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@ use internet2::addr::{InetSocketAddr, NodeAddr};
use microservices::shell::Exec;

use farcaster_core::{
blockchain::Network,
blockchain::{Blockchain, Network},
negotiation::PublicOffer,
role::{SwapRole, TradeRole},
swap::SwapId,
};
use strict_encoding::ReadExt;

use super::Command;
use crate::{
rpc::{request, Client, Request},
syncerd::Coin,
};
use crate::rpc::{request, Client, Request};
use crate::{Error, LogStyle, ServiceId};

impl Exec for Command {
Expand Down Expand Up @@ -255,8 +252,8 @@ impl Exec for Command {
}
}

Command::NeedsFunding { coin } => {
runtime.request(ServiceId::Farcasterd, Request::NeedsFunding(coin))?;
Command::NeedsFunding { blockchain } => {
runtime.request(ServiceId::Farcasterd, Request::NeedsFunding(blockchain))?;
runtime.report_response_or_fail()?;
}

Expand Down
10 changes: 4 additions & 6 deletions src/cli/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ use farcaster_core::{
swap::{btcxmr::PublicOffer, SwapId},
};

use crate::syncerd::Coin;

/// Command-line tool for working with Farcaster node
#[derive(Parser, Clone, PartialEq, Eq, Debug)]
#[clap(name = "swap-cli", bin_name = "swap-cli", author, version)]
Expand Down Expand Up @@ -227,11 +225,11 @@ pub enum Command {
follow: bool,
},

/// Returns addresses and amounts that require funding for coin.
#[display("needs-funding<{coin}>")]
/// Returns addresses and amounts that require funding for blockchain.
#[display("needs-funding<{blockchain}>")]
NeedsFunding {
/// The coin funding required needs to be checked against.
coin: Coin,
/// The blockchain funding required needs to be checked against.
blockchain: Blockchain,
},

/// Attempts to sweep any funds on a given bitcoin funding address
Expand Down
6 changes: 3 additions & 3 deletions src/databased/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::databased::runtime::request::{
Address, OfferStatus, OfferStatusPair, OfferStatusSelector,
};
use crate::farcaster_core::consensus::Encodable;
use crate::syncerd::opts::Coin;
use crate::walletd::runtime::{CheckpointWallet, Wallet};
use farcaster_core::blockchain::Blockchain;
use farcaster_core::swap::btcxmr::PublicOffer;
use farcaster_core::swap::SwapId;
use lmdb::{Cursor, Transaction as LMDBTransaction};
Expand Down Expand Up @@ -306,7 +306,7 @@ impl Runtime {
}
}

Request::GetAddresses(Coin::Bitcoin) => {
Request::GetAddresses(Blockchain::Bitcoin) => {
let addresses = self.database.get_all_bitcoin_addresses()?;
endpoints.send_to(
ServiceBus::Ctl,
Expand Down Expand Up @@ -359,7 +359,7 @@ impl Runtime {
}
}

Request::GetAddresses(Coin::Monero) => {
Request::GetAddresses(Blockchain::Monero) => {
let addresses = self.database.get_all_monero_addresses()?;
endpoints.send_to(
ServiceBus::Ctl,
Expand Down
Loading

0 comments on commit 77ed695

Please sign in to comment.