Skip to content

Commit

Permalink
Add a new API Wallet::new_with_online().
Browse files Browse the repository at this point in the history
Signed-off-by: Masaki Muranaka <[email protected]>
  • Loading branch information
monaka committed Dec 16, 2022
1 parent 1028e9a commit 8650d6c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,11 @@ pub struct Wallet {
impl Wallet {
/// Create a new RGB wallet based on the provided [`WalletData`]
pub fn new(wallet_data: WalletData) -> Result<Self, Error> {
Self::new_with_online(wallet_data, None)
}

/// Create a new RGB wallet based on the provided [`WalletData`] and [`Option<Online>`]
pub fn new_with_online(wallet_data: WalletData, online: Option<Online>) -> Result<Self, Error> {
let wdata = wallet_data.clone();

// wallet directory and file logging setup
Expand Down Expand Up @@ -768,7 +773,7 @@ impl Wallet {
wallet_dir,
bdk_wallet,
rest_client,
online: None,
online,
bdk_blockchain: None,
electrum_client: None,
rgb_client: None,
Expand Down
25 changes: 25 additions & 0 deletions src/wallet/test/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,31 @@ fn mainnet_success() {
assert_eq!(wallet.wallet_data.mnemonic, Some(keys.mnemonic));
}

#[test]
fn mainnet_with_online_success() {
fs::create_dir_all(TEST_DATA_DIR).unwrap();

let bitcoin_network = BitcoinNetwork::Mainnet;
let keys = generate_keys(bitcoin_network);
let wallet = Wallet::new_with_online(WalletData {
data_dir: TEST_DATA_DIR.to_string(),
bitcoin_network,
database_type: DatabaseType::Sqlite,
pubkey: keys.xpub.clone(),
mnemonic: Some(keys.mnemonic.clone()),
}, Some(Online {
id: 1,
electrum_url: "".to_string(),
proxy_url: "".to_string(),
}))
.unwrap();
check_wallet(&wallet, DescriptorType::Wpkh, bitcoin_network);
assert!(!wallet.watch_only);
assert_eq!(wallet.wallet_data.pubkey, keys.xpub);
assert_eq!(wallet.wallet_data.mnemonic, Some(keys.mnemonic));
assert!(wallet.online.is_some());
}

#[test]
fn fail() {
initialize();
Expand Down

0 comments on commit 8650d6c

Please sign in to comment.