Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose client and listen methods on Wallet #182

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rosetta-client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(missing_docs)]
use crate::crypto::address::Address;
use crate::crypto::PublicKey;
use crate::types::{
Expand All @@ -21,6 +22,7 @@ use serde_json::Value;
use std::pin::Pin;
use std::str::FromStr;

/// Generic Client
pub enum GenericClient {
Bitcoin(BitcoinClient),
Ethereum(EthereumClient),
Expand Down Expand Up @@ -73,6 +75,7 @@ impl GenericClient {
}
}

/// Generic Blockchain Params
#[derive(Deserialize, Serialize, From)]
pub enum GenericMetadataParams {
Bitcoin(BitcoinMetadataParams),
Expand All @@ -81,6 +84,7 @@ pub enum GenericMetadataParams {
Polkadot(PolkadotMetadataParams),
}

/// Generic Blockchain Metadata
#[derive(Deserialize, Serialize, From)]
pub enum GenericMetadata {
Bitcoin(BitcoinMetadata),
Expand Down
3 changes: 2 additions & 1 deletion rosetta-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use anyhow::Result;
pub use crate::wallet::Wallet;
pub use rosetta_core::{crypto, types, BlockchainConfig};

mod client;
/// Clients that communicates to different blockchains
pub mod client;
mod mnemonic;
mod signer;
mod tx_builder;
Expand Down
10 changes: 9 additions & 1 deletion rosetta-client/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use std::path::Path;

/// The wallet provides the main entry point to this crate.
pub struct Wallet {
client: GenericClient,
/// GenericClient instance
pub client: GenericClient,
account: AccountIdentifier,
secret_key: DerivedSecretKey,
public_key: PublicKey,
Expand Down Expand Up @@ -116,6 +117,13 @@ impl Wallet {
})
}

/// Return a stream of events, return None if the blockchain doesn't support events.
pub async fn listen(
&self,
) -> Result<Option<<GenericClient as BlockchainClient>::EventStream<'_>>> {
self.client.listen().await
}

/// Returns block data
/// Takes PartialBlockIdentifier
pub async fn block(&self, data: PartialBlockIdentifier) -> Result<Block> {
Expand Down
Loading