Skip to content

Commit

Permalink
Remove contract_type() from SwapCoin trait
Browse files Browse the repository at this point in the history
I think this style is too OOP and not enough rustic. Now that
we have separate structs Incoming/OutgoingSwapCoin we can more
simply say that Outgoing = timelock and Incoming = hashlock
  • Loading branch information
chris-belcher committed Aug 25, 2021
1 parent 5a4bf1c commit 570fd8a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
13 changes: 0 additions & 13 deletions src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ pub trait SwapCoin {
fn verify_contract_tx_receiver_sig(&self, sig: &Signature) -> bool;
fn verify_contract_tx_sender_sig(&self, sig: &Signature) -> bool;
fn apply_privkey(&mut self, privkey: SecretKey) -> Result<(), Error>;
fn contract_type(&self) -> &str;
fn is_known(&self) -> bool;
}

Expand Down Expand Up @@ -506,10 +505,6 @@ impl SwapCoin for IncomingSwapCoin {
Ok(())
}

fn contract_type(&self) -> &str {
self.type_string()
}

fn is_known(&self) -> bool {
self.contract_privkey_is_known()
}
Expand Down Expand Up @@ -560,10 +555,6 @@ impl SwapCoin for OutgoingSwapCoin {
}
}

fn contract_type(&self) -> &str {
self.type_string()
}

fn is_known(&self) -> bool {
self.contract_privkey_is_known()
}
Expand Down Expand Up @@ -656,10 +647,6 @@ impl SwapCoin for WatchOnlySwapCoin {
}
}

fn contract_type(&self) -> &str {
"watchonly"
}

fn is_known(&self) -> bool {
false
}
Expand Down
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern crate bitcoincore_rpc;

use dirs::home_dir;
use std::io;
use std::iter::repeat;
use std::path::PathBuf;
use std::sync::{Arc, RwLock};

Expand Down Expand Up @@ -186,13 +187,16 @@ fn display_wallet_balance(wallet_file_name: &PathBuf, long_form: Option<bool>) {
"{:16} {:8} {:8} {:<15} {:<7} value",
"outpoint", "type", "preimage", "locktime/blocks", "conf",
);
for (utxo, swapcoin) in utxo_incoming_swapcoins

for ((utxo, swapcoin), contract_type) in utxo_incoming_swapcoins
.iter()
.map(|(l, i)| (l, (*i as &dyn SwapCoin)))
.zip(repeat("hashlock"))
.chain(
utxo_outgoing_swapcoins
.iter()
.map(|(l, o)| (l, (*o as &dyn SwapCoin))),
.map(|(l, o)| (l, (*o as &dyn SwapCoin)))
.zip(repeat("timelock")),
)
{
let txid = utxo.txid.to_hex();
Expand All @@ -203,7 +207,7 @@ fn display_wallet_balance(wallet_file_name: &PathBuf, long_form: Option<bool>) {
if long_form { "" } else { ".." },
if long_form { &"" } else { &txid[58..64] },
utxo.vout,
swapcoin.contract_type(),
contract_type,
if swapcoin.is_known() { "known" } else { "unknown" },
read_locktime_from_contract(&swapcoin.get_contract_redeemscript())
.expect("unable to read locktime from contract"),
Expand Down
8 changes: 0 additions & 8 deletions src/wallet_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ impl IncomingSwapCoin {
}
}

pub fn type_string(&self) -> &str {
"hashlock"
}

pub fn contract_privkey_is_known(&self) -> bool {
self.other_privkey.is_some() || self.hash_preimage.is_some()
}
Expand Down Expand Up @@ -193,10 +189,6 @@ impl OutgoingSwapCoin {
}
}

pub fn type_string(&self) -> &str {
"timelock"
}

pub fn contract_privkey_is_known(&self) -> bool {
self.hash_preimage.is_some()
}
Expand Down

0 comments on commit 570fd8a

Please sign in to comment.