diff --git a/bin/src/wallet.rs b/bin/src/wallet.rs index 4a7b2ef..9001aab 100644 --- a/bin/src/wallet.rs +++ b/bin/src/wallet.rs @@ -151,24 +151,41 @@ async fn main() { let (poll_job, sign_processor) = create_job_pair( graphql_endpoint.clone(), String::from(token.clone()), + String::from("matrix"), Duration::from_millis(POLL_TRANSACTION_MS), Arc::clone(&wallet_pair), TRANSACTION_PAGE_SIZE.try_into().unwrap(), ); let (poll_wallet_job, derive_wallet_processor) = create_wallet_job_pair( - graphql_endpoint, + graphql_endpoint.clone(), String::from(token.clone()), Duration::from_millis(POLL_ACCOUNT_MS), Arc::clone(&wallet_pair), ACCOUNT_PAGE_SIZE.try_into().unwrap(), ); + let (relay_pair, graphql, auth) = + load_relay_wallet::(load_config().clone()).await; + let relay_pair = Arc::new(relay_pair); + + let (relay_poll_job, relay_sign_processor) = create_job_pair( + graphql.clone(), + String::from(auth.clone()), + String::from("relay"), + Duration::from_millis(POLL_TRANSACTION_MS), + Arc::clone(&relay_pair), + TRANSACTION_PAGE_SIZE.try_into().unwrap(), + ); + poll_job.start_job(); sign_processor.start_job(); poll_wallet_job.start_job(); derive_wallet_processor.start_job(); + relay_poll_job.start_job(); + relay_sign_processor.start_job(); + signal::ctrl_c().await.expect("Failed to listen for ctrl c"); } diff --git a/lib/src/config_loader.rs b/lib/src/config_loader.rs index 04f73b8..c342bff 100644 --- a/lib/src/config_loader.rs +++ b/lib/src/config_loader.rs @@ -184,7 +184,6 @@ fn get_password(env_name: &str) -> SecretString { let password = SecretString::new( env::var(env_name).unwrap_or_else(|_| panic!("Password {} not loaded in memory", env_name)), ); - env::remove_var(env_name); password } @@ -228,6 +227,33 @@ where load_wallet_with_connections(config, context_provider, connection).await } +pub async fn load_relay_wallet( + config: Configuration, +) -> ( + WalletConnectionPair, ChainConnector>, + String, + String, +) +where + T: subxt::Config + Sync + Send, + T::Signature: From<::Signature> + Verify + From, + ::Signer: + From<::Public> + IdentifyAccount, + T::AccountId: Into<::Address> + + std::fmt::Display + + From, + T::Address: From + Send + Sync, + T::Extrinsic: Send, + T::BlockNumber: Into, +{ + let context_provider = Arc::new(Connector::, String, subxt::BasicError>::new( + config.relay_node.to_owned(), + )); + let connection = Arc::clone(&context_provider); + + load_wallet_with_connections(config, context_provider, connection).await +} + pub(crate) async fn load_wallet_with_connections( config: Configuration, context_provider: Arc, diff --git a/lib/src/graphql_schemas/mark_and_list_pending_transactions.graphql b/lib/src/graphql_schemas/mark_and_list_pending_transactions.graphql index a36a414..271c2f3 100644 --- a/lib/src/graphql_schemas/mark_and_list_pending_transactions.graphql +++ b/lib/src/graphql_schemas/mark_and_list_pending_transactions.graphql @@ -1,5 +1,9 @@ -mutation MarkAndListPendingTransactions($after: String, $first: Int) { - MarkAndListPendingTransactions(after: $after, first: $first) { +mutation MarkAndListPendingTransactions($network: String, $after: String, $first: Int) { + MarkAndListPendingTransactions( + network: $network + after: $after + first: $first + ) { edges { cursor node { diff --git a/lib/src/graphql_schemas/schema.graphql b/lib/src/graphql_schemas/schema.graphql index da0c591..95af81b 100644 --- a/lib/src/graphql_schemas/schema.graphql +++ b/lib/src/graphql_schemas/schema.graphql @@ -67,7 +67,8 @@ type Query { } type Mutation { - MarkAndListPendingTransactions(after: String, first: Int): TransactionConnection + + MarkAndListPendingTransactions(network: String, after: String, first: Int): TransactionConnection UpdateTransaction( id: Int! diff --git a/lib/src/jobs.rs b/lib/src/jobs.rs index 38c5cb0..b344c90 100644 --- a/lib/src/jobs.rs +++ b/lib/src/jobs.rs @@ -334,6 +334,8 @@ pub struct PollJob { url: Arc, /// Static token for authorization token: Arc, + /// + network: Arc, /// Page size(pagination) limit: i64, } @@ -343,6 +345,7 @@ pub struct PollJob { pub fn create_job_pair( graphql_endpoint: String, token: String, + network: String, delay: Duration, wallet_connection_pair: Arc, ChainConnector>>, page_size: i64, @@ -364,6 +367,7 @@ pub fn create_job_pair( create_job_pair_with_executor( graphql_endpoint, token, + network, delay, wallet_connection_pair, page_size, @@ -375,6 +379,7 @@ pub fn create_job_pair( pub(crate) fn create_job_pair_with_executor( graphql_endpoint: String, token: String, + network: String, delay: Duration, wallet_connection_pair: Arc>, page_size: i64, @@ -413,9 +418,12 @@ pub(crate) fn create_job_pair_with_executor) -> Request { + let network = &*self.network; let request_body = MarkAndListPendingTransactions::build_query( mark_and_list_pending_transactions::Variables { + network: Some(network.clone().to_string()), after: None, first: limit, }, @@ -460,6 +470,7 @@ where pub fn new( url: Arc, token: Arc, + network: Arc, delay: Duration, tx: Sender>, client: Arc, @@ -473,6 +484,7 @@ where tx, url, token, + network, limit, } } @@ -1169,8 +1181,8 @@ where let transaction = transaction.clone(); let wallet = &wallet_connection_pair.wallet; - /// This can be improved by making the daemon process the transactions in sequence - /// Since it process in parallel and we can have a transaction that deletes the account + // This can be improved by making the daemon process the transactions in sequence + // Since it process in parallel and we can have a transaction that deletes the account Self::reset_wallet_nonce(wallet, &external_id).await; let connection = &wallet_connection_pair.connection; @@ -1288,7 +1300,7 @@ for SignRequest .encoded_data .split('x') .nth(1) - .ok_or("No '0x' at the beggining")?; + .ok_or("No '0x' at the beginning")?; let transaction = hex::decode(data).map_err(|e| { tracing::error!("Error decoding: {:?}", e); e @@ -1350,12 +1362,13 @@ pub struct PaginationInput { /// /// ## The query (Can be found in the `query_path`) /// ```ignore -/// mutation MarkAndListPendingTransactions($after: String, $first: Int) { -/// MarkAndListPendingTransactions(after: $after, first: $first) { +/// mutation MarkAndListPendingTransactions($network: String, $after: String, $first: Int) { +/// MarkAndListPendingTransactions(network: $network, after: $after, first: $first) { /// edges { /// node { -/// encodedData /// id +/// encodedData +/// network /// wallet { /// externalId /// managed @@ -1373,7 +1386,7 @@ pub struct PaginationInput { )] pub struct MarkAndListPendingTransactions; -/// GraphQL mutation to submit the received txHash. +/// GraphQL's mutation to submit the received txHash. /// /// ## The query /// ```ignore @@ -1395,7 +1408,7 @@ pub struct MarkAndListPendingTransactions; )] pub struct UpdateTransaction; -/// GraphQL mutation to submit the received txHash. +/// GraphQL's mutation to submit the received txHash. /// /// ## The query /// ```ignore diff --git a/lib/src/lib.rs b/lib/src/lib.rs index d3e5f23..776798c 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -51,7 +51,7 @@ pub(crate) use connection::{chain_connection, client_connection, connection_hand pub(crate) use types::{SignedExtra, UncheckedExtrinsic}; pub use crate::wallet_trait::EfinityWallet; -pub use config_loader::{load_config, load_wallet}; +pub use config_loader::{load_config, load_relay_wallet, load_wallet}; pub use jobs::{ create_job_pair, create_wallet_job_pair, DeriveWalletProcessor, PollJob, PollWalletJob, SignProcessor,