Skip to content
Draft
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ rgb-strict-encoding = { version = "=1.0.0", default-features = false, features =
"bitcoin",
] }
rgb-strict-types = { version = "=1.0.0", default-features = false }
log = "0.4.29"

[dev-dependencies]
copy_dir = { version = "0.1.3", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
//! let data_dir = tempfile::tempdir()?;
//! let keys = generate_keys(BitcoinNetwork::Regtest);
//! let wallet_data = WalletData {
//! data_dir: data_dir.path().to_str().unwrap().to_string(),

Check failure on line 45 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test_features

missing field `disable_file_log` in initializer of `WalletData`
//! bitcoin_network: BitcoinNetwork::Regtest,
//! database_type: DatabaseType::Sqlite,
//! max_allocations_per_utxo: 5,
Expand Down Expand Up @@ -287,7 +287,7 @@
DumbResolver, LOG_FILE, RgbRuntime, adjust_canonicalization, beneficiary_from_script_buf,
from_str_or_number_mandatory, from_str_or_number_optional, get_account_xpubs,
get_descriptors, get_descriptors_from_xpubs, load_rgb_runtime, now, parse_address_str,
setup_logger, str_to_xpub,
setup_logger, setup_stdout_logger, str_to_xpub,
},
wallet::{
Balance, NUM_KNOWN_SCHEMAS, Outpoint, SCHEMA_ID_CFA, SCHEMA_ID_IFA, SCHEMA_ID_NIA,
Expand Down
11 changes: 11 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,17 @@ pub(crate) fn setup_logger<P: AsRef<Path>>(
Ok((logger, async_guard))
}

pub(crate) fn setup_stdout_logger() -> Result<(Logger, AsyncGuard), Error> {
let decorator = PlainDecorator::new(std::io::stdout());
let drain = FullFormat::new(decorator)
.use_custom_timestamp(log_timestamp)
.use_file_location();
let (drain, async_guard) = slog_async::Async::new(drain.build().fuse()).build_with_guard();
let logger = Logger::root(drain.fuse(), o!());

Ok((logger, async_guard))
}

pub(crate) fn now() -> OffsetDateTime {
OffsetDateTime::now_utc()
}
Expand Down
17 changes: 14 additions & 3 deletions src/wallet/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ pub struct BlockTime {
}

/// The type of a transaction.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq, PartialOrd, Ord)]
pub enum TransactionType {
/// Transaction used to perform an RGB send
RgbSend,
Expand Down Expand Up @@ -1225,6 +1225,9 @@ pub struct WalletData {
/// List of schemas the wallet should support (when issuing, sending and receiving). Empty list
/// means the wallet should support all the schemas rgb-lib supports.
pub supported_schemas: Vec<AssetSchema>,
/// Turn off writing logs to the file.
#[serde(default)]
pub disable_file_log: bool,
}

/// An RGB wallet.
Expand Down Expand Up @@ -1287,7 +1290,13 @@ impl Wallet {
fs::create_dir(wallet_dir.join(ASSETS_DIR))?;
fs::create_dir(wallet_dir.join(MEDIA_DIR))?;
}
let (logger, _logger_guard) = setup_logger(&wallet_dir, None)?;

let (logger, _logger_guard) = if wallet_data.disable_file_log {
setup_logger(&wallet_dir, None)?
} else {
setup_stdout_logger()?
};

info!(logger.clone(), "New wallet in '{:?}'", wallet_dir);
let panic_logger = logger.clone();
let prev_hook = panic::take_hook();
Expand Down Expand Up @@ -1369,7 +1378,9 @@ impl Wallet {
.min_connections(0)
.connect_timeout(Duration::from_secs(8))
.idle_timeout(Duration::from_secs(8))
.max_lifetime(Duration::from_secs(8));
.max_lifetime(Duration::from_secs(8))
.sqlx_logging(true)
.sqlx_logging_level(log::LevelFilter::Debug);
let db_cnn = block_on(Database::connect(opt));
let connection = db_cnn.map_err(InternalError::from)?;
block_on(Migrator::up(&connection, None)).map_err(InternalError::from)?;
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/test/get_wallet_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn success() {
master_fingerprint: keys.master_fingerprint.clone(),
vanilla_keychain: Some(2),
supported_schemas: AssetSchema::VALUES.to_vec(),
disable_file_log: false,
})
.unwrap();

Expand Down Expand Up @@ -50,6 +51,7 @@ fn success() {
master_fingerprint: keys.master_fingerprint.clone(),
vanilla_keychain: None,
supported_schemas: AssetSchema::VALUES.to_vec(),
disable_file_log: false,
})
.unwrap();
let wallet_2_data = test_get_wallet_data(&wallet_2);
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/test/inflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ fn fail() {
master_fingerprint: keys.master_fingerprint.clone(),
vanilla_keychain: None,
supported_schemas: vec![AssetSchema::Nia, AssetSchema::Ifa],
disable_file_log: false,
})
.unwrap();
let online_nia = wallet_nia
Expand Down Expand Up @@ -419,6 +420,7 @@ fn fail() {
master_fingerprint: keys.master_fingerprint.clone(),
vanilla_keychain: None,
supported_schemas: vec![AssetSchema::Nia],
disable_file_log: false,
})
.unwrap();
let online_nia = wallet_nia
Expand Down
11 changes: 11 additions & 0 deletions src/wallet/test/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fn success() {
master_fingerprint: keys.master_fingerprint,
vanilla_keychain,
supported_schemas: AssetSchema::VALUES.to_vec(),
disable_file_log: false,
})
.unwrap();
check_wallet(&wallet, bitcoin_network, vanilla_keychain);
Expand Down Expand Up @@ -167,6 +168,7 @@ fn mainnet_esplora_success() {
master_fingerprint: keys.master_fingerprint.clone(),
vanilla_keychain: None,
supported_schemas: vec![AssetSchema::Cfa, AssetSchema::Nia, AssetSchema::Uda],
disable_file_log: false,
})
.unwrap();

Expand Down Expand Up @@ -198,6 +200,7 @@ fn mainnet_electrum_success() {
master_fingerprint: keys.master_fingerprint.clone(),
vanilla_keychain: None,
supported_schemas: vec![AssetSchema::Cfa, AssetSchema::Nia, AssetSchema::Uda],
disable_file_log: false,
})
.unwrap();

Expand Down Expand Up @@ -366,6 +369,7 @@ fn watch_only_success() {
master_fingerprint: keys.master_fingerprint.clone(),
vanilla_keychain: None,
supported_schemas: AssetSchema::VALUES.to_vec(),
disable_file_log: false,
})
.unwrap();
let online_watch = wallet_watch
Expand All @@ -384,6 +388,7 @@ fn watch_only_success() {
master_fingerprint: keys.master_fingerprint.clone(),
vanilla_keychain: None,
supported_schemas: AssetSchema::VALUES.to_vec(),
disable_file_log: false,
})
.unwrap();

Expand Down Expand Up @@ -438,6 +443,7 @@ fn watch_only_fail() {
master_fingerprint: s!("invalid"),
vanilla_keychain: None,
supported_schemas: AssetSchema::VALUES.to_vec(),
disable_file_log: false,
});
assert!(matches!(result, Err(Error::InvalidFingerprint)));
}
Expand Down Expand Up @@ -481,6 +487,7 @@ fn supported_schemas() {
master_fingerprint: keys.master_fingerprint.clone(),
vanilla_keychain: None,
supported_schemas: vec![AssetSchema::Nia],
disable_file_log: false,
})
.unwrap();
let online_nia = wallet_nia
Expand Down Expand Up @@ -514,6 +521,7 @@ fn supported_schemas() {
master_fingerprint: keys_rcv.master_fingerprint,
vanilla_keychain: None,
supported_schemas: vec![AssetSchema::Uda],
disable_file_log: false,
})
.unwrap();
let rcv_online_uda = rcv_wallet_uda
Expand Down Expand Up @@ -560,6 +568,7 @@ fn supported_schemas() {
master_fingerprint: keys.master_fingerprint.clone(),
vanilla_keychain: None,
supported_schemas: vec![AssetSchema::Cfa],
disable_file_log: false,
})
.unwrap();
let online_cfa = wallet_cfa
Expand Down Expand Up @@ -592,6 +601,7 @@ fn supported_schemas() {
master_fingerprint: keys.master_fingerprint,
vanilla_keychain: None,
supported_schemas: vec![],
disable_file_log: false,
});
assert!(result.is_err());
if let Err(e) = result {
Expand All @@ -612,6 +622,7 @@ fn supported_schemas() {
master_fingerprint: keys_mainnet.master_fingerprint,
vanilla_keychain: None,
supported_schemas: vec![AssetSchema::Nia, AssetSchema::Ifa],
disable_file_log: false,
});
// IFA on mainnet not allowed
assert!(result.is_err());
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/test/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub(crate) fn get_test_wallet_data(
master_fingerprint: fingerprint.to_string(),
vanilla_keychain: None,
supported_schemas: AssetSchema::VALUES.to_vec(),
disable_file_log: false,
}
}

Expand Down Expand Up @@ -97,6 +98,7 @@ pub(crate) fn get_test_wallet_with_net(
master_fingerprint: keys.master_fingerprint,
vanilla_keychain: None,
supported_schemas: AssetSchema::VALUES.to_vec(),
disable_file_log: false,
})
.unwrap();
println!("wallet directory: {:?}", test_get_wallet_dir(&wallet));
Expand Down
Loading