Skip to content

Commit

Permalink
move trait refactoring TODOs to trait definitions instead of siacoin …
Browse files Browse the repository at this point in the history
…impl
  • Loading branch information
Alrighttt committed Oct 13, 2024
1 parent 8bdfa60 commit 5721b91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
19 changes: 19 additions & 0 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1947,10 +1947,19 @@ pub trait MarketCoinOps {

async fn get_public_key(&self) -> Result<String, MmError<UnexpectedDerivationMethod>>;

// TODO Alright: should be separated into a "OptionalDispatcherOps" trait.
// This trait can handle all methods that are only used by dispatcher methods.
// this is literally only used by sign_message impls and doesn't need to be a method
fn sign_message_hash(&self, _message: &str) -> Option<[u8; 32]>;

// TODO Alright: should be separated into a "OptionalDispatcherOps" trait.
// This trait can handle all methods that are only used by dispatcher methods.
// only used by "sign_message" rpc method
fn sign_message(&self, _message: &str) -> SignatureResult<String>;

// TODO Alright: should be separated into a "OptionalDispatcherOps" trait.
// This trait can handle all methods that are only used by dispatcher methods.
// only used by "verify_message" rpc method
fn verify_message(&self, _signature: &str, _message: &str, _address: &str) -> VerificationResult<bool>;

fn get_non_zero_balance(&self) -> NonZeroBalanceFut<MmNumber> {
Expand Down Expand Up @@ -3304,16 +3313,26 @@ pub trait MmCoin:

fn withdraw(&self, req: WithdrawRequest) -> WithdrawFut;

// TODO Alright: should be separated into a "OptionalDispatcherOps" trait.
// This trait can handle all methods that are only used by dispatcher methods.
// only used by "get_raw_transaction" dispatcher method.
fn get_raw_transaction(&self, req: RawTransactionRequest) -> RawTransactionFut;

// TODO Alright: this method is only applicable to Watcher logic and could be moved to WatcherOps
fn get_tx_hex_by_hash(&self, tx_hash: Vec<u8>) -> RawTransactionFut;

/// Maximum number of digits after decimal point used to denominate integer coin units (satoshis, wei, etc.)
fn decimals(&self) -> u8;

/// Convert input address to the specified address format.
// TODO Alright: should be separated into a "OptionalDispatcherOps" trait.
// This trait can handle all methods that are only used by dispatcher methods.
fn convert_to_address(&self, from: &str, to_address_format: Json) -> Result<String, String>;

// TODO Alright: could be separated into a "OptionalDispatcherOps" trait.
// only used by "verify_message" and "validate_address" dispatcher methods.
// Consider using traits to track which methods are neccesary for which UIs
// eg, "KomodoWalletOps" for the Komodo wallet, "ReactWalletOps" for the react wallet, etc.
fn validate_address(&self, address: &str) -> ValidateAddressResult;

/// Loop collecting coin transaction history and saving it to local DB
Expand Down
15 changes: 1 addition & 14 deletions mm2src/coins/siacoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ pub struct SiaFeeDetails {
impl MmCoin for SiaCoin {
fn spawner(&self) -> CoinFutSpawner { CoinFutSpawner::new(&self.abortable_system) }

// TODO Alright: should be separated into a "OptionalDispatcherOps" trait.
// This trait can handle all methods that are only used by dispatcher methods.
fn get_raw_transaction(&self, _req: RawTransactionRequest) -> RawTransactionFut { unimplemented!() }

fn get_tx_hex_by_hash(&self, _tx_hash: Vec<u8>) -> RawTransactionFut { unimplemented!() }
Expand All @@ -231,8 +229,6 @@ impl MmCoin for SiaCoin {

fn decimals(&self) -> u8 { 24 }

// TODO Alright: should be separated into a "OptionalDispatcherOps" trait.
// This trait can handle all methods that are only used by dispatcher methods.
fn convert_to_address(&self, _from: &str, _to_address_format: Json) -> Result<String, String> { unimplemented!() }

fn validate_address(&self, address: &str) -> ValidateAddressResult {
Expand Down Expand Up @@ -583,19 +579,10 @@ impl MarketCoinOps for SiaCoin {
Ok(public_key.to_string())
}

// TODO Alright: should be separated into a "OptionalDispatcherOps" trait.
// This trait can handle all methods that are only used by dispatcher methods.
// this is literally only used by sign_message impls and doesn't need to be a method
fn sign_message_hash(&self, _message: &str) -> Option<[u8; 32]> { unimplemented!() }

// TODO Alright: should be separated into a "OptionalDispatcherOps" trait.
// This trait can handle all methods that are only used by dispatcher methods.
// only used by "sign_message" rpc method
fn sign_message(&self, _message: &str) -> SignatureResult<String> { unimplemented!() }

// TODO Alright: should be separated into a "OptionalDispatcherOps" trait.
// This trait can handle all methods that are only used by dispatcher methods.
// only used by "verify_message" rpc method
fn verify_message(&self, _signature: &str, _message: &str, _address: &str) -> VerificationResult<bool> {
unimplemented!()
}
Expand Down Expand Up @@ -834,7 +821,7 @@ impl MakerSwapTakerCoin for SiaCoin {
}

// TODO ideally we would not have to implement this trait for SiaCoin
// requires significant refactoring
// requires significant refactoring because of WatcherOps trait bound on MmCoin
#[async_trait]
impl WatcherOps for SiaCoin {
fn send_maker_payment_spend_preimage(&self, _input: SendMakerPaymentSpendPreimageInput) -> TransactionFut {
Expand Down

0 comments on commit 5721b91

Please sign in to comment.