diff --git a/sn_node/src/error.rs b/sn_node/src/error.rs index 25b02e659f..a9db1cd6a4 100644 --- a/sn_node/src/error.rs +++ b/sn_node/src/error.rs @@ -87,4 +87,7 @@ pub enum Error { /// Error occurred in an async thread #[error("Error occured in async thread: {0}")] JoinErrorInAsyncThread(String), + + #[error("Unsupported payment method: {0}")] + UnsupportedPaymentMethod(String), } diff --git a/sn_node/src/put_validation.rs b/sn_node/src/put_validation.rs index 95fbc89c57..a65361dc95 100644 --- a/sn_node/src/put_validation.rs +++ b/sn_node/src/put_validation.rs @@ -18,8 +18,8 @@ use sn_protocol::{ }; use sn_registers::SignedRegister; use sn_transfers::{ - calculate_royalties_fee, CashNote, CashNoteRedemption, HotWallet, NanoTokens, Payment, - SignedSpend, Transfer, TransferError, UniquePubkey, WalletError, NETWORK_ROYALTIES_PK, + calculate_royalties_fee, CashNote, CashNoteRedemption, HotWallet, NanoTokens, NativePayment, + Payment, SignedSpend, Transfer, TransferError, UniquePubkey, WalletError, NETWORK_ROYALTIES_PK, }; use std::collections::BTreeSet; use tokio::task::JoinSet; @@ -522,15 +522,13 @@ impl Node { } } - /// Perform validations on the provided `Record`. - async fn payment_for_us_exists_and_is_still_valid( + async fn check_native_payment( &self, address: &NetworkAddress, - payment: Payment, + payment: NativePayment, ) -> Result<()> { let key = address.to_record_key(); let pretty_key = PrettyPrintRecordKey::from(&key).into_owned(); - debug!("Validating record payment for {pretty_key}"); // load wallet let mut wallet = HotWallet::load_from(self.network().root_dir_path())?; @@ -613,6 +611,23 @@ impl Node { Ok(()) } + /// Perform validations on the provided `Record`. + async fn payment_for_us_exists_and_is_still_valid( + &self, + address: &NetworkAddress, + payment: Payment, + ) -> Result<()> { + let key = address.to_record_key(); + let pretty_key = PrettyPrintRecordKey::from(&key).into_owned(); + debug!("Validating record payment for {pretty_key}"); + + match payment { + Payment::Native(payment) => self.check_native_payment(address, payment).await, + Payment::Erc20 => Err(Error::UnsupportedPaymentMethod("Erc20".to_string())), + Payment::Bitcoin => Err(Error::UnsupportedPaymentMethod("Bitcoin".to_string())), + } + } + async fn register_validation( &self, register: &SignedRegister, diff --git a/sn_transfers/src/lib.rs b/sn_transfers/src/lib.rs index 5ea6cbd789..a20b36f494 100644 --- a/sn_transfers/src/lib.rs +++ b/sn_transfers/src/lib.rs @@ -30,8 +30,8 @@ pub use genesis::{ }; pub use transfers::{CashNoteRedemption, SignedTransaction, Transfer, UnsignedTransaction}; pub use wallet::{ - bls_secret_from_hex, wallet_lockfile_name, Error as WalletError, HotWallet, Payment, - PaymentQuote, QuotingMetrics, Result as WalletResult, WalletApi, WatchOnlyWallet, + bls_secret_from_hex, wallet_lockfile_name, Error as WalletError, HotWallet, NativePayment, + Payment, PaymentQuote, QuotingMetrics, Result as WalletResult, WalletApi, WatchOnlyWallet, QUOTE_EXPIRATION_SECS, WALLET_DIR_NAME, }; diff --git a/sn_transfers/src/wallet.rs b/sn_transfers/src/wallet.rs index 2296d62768..58adb233da 100644 --- a/sn_transfers/src/wallet.rs +++ b/sn_transfers/src/wallet.rs @@ -64,7 +64,7 @@ mod watch_only; pub use self::{ api::{WalletApi, WALLET_DIR_NAME}, - data_payments::{Payment, PaymentQuote, QuotingMetrics, QUOTE_EXPIRATION_SECS}, + data_payments::{NativePayment, Payment, PaymentQuote, QuotingMetrics, QUOTE_EXPIRATION_SECS}, error::{Error, Result}, hot_wallet::HotWallet, keys::bls_secret_from_hex, diff --git a/sn_transfers/src/wallet/data_payments.rs b/sn_transfers/src/wallet/data_payments.rs index 90e05e179c..1de8bdb98d 100644 --- a/sn_transfers/src/wallet/data_payments.rs +++ b/sn_transfers/src/wallet/data_payments.rs @@ -18,8 +18,20 @@ pub const QUOTE_EXPIRATION_SECS: u64 = 3600; /// The margin allowed for live_time const LIVE_TIME_MARGIN: u64 = 10; +/// A generic data payment type supporting multiple payment methods +#[derive(Clone, Serialize, Deserialize, Eq, PartialEq, Debug)] +pub enum Payment { + /// The autonomy network native payment method using ANT (Autonomy Network Token) + Native(NativePayment), + /// The ERC20 payment method + Erc20, + /// The Bitcoin payment method + Bitcoin, +} + +/// The autonomy network native payment method using ANT (Autonomy Network Token) #[derive(Clone, Serialize, Deserialize, Eq, PartialEq, custom_debug::Debug)] -pub struct Payment { +pub struct NativePayment { /// The transfers we make #[debug(skip)] pub transfers: Vec, @@ -47,10 +59,10 @@ pub struct PaymentDetails { impl PaymentDetails { /// create a Payment for a PaymentDetails pub fn to_payment(&self) -> Payment { - Payment { + Payment::Native(NativePayment { transfers: vec![self.transfer.0.clone(), self.royalties.0.clone()], quote: self.quote.clone(), - } + }) } }