Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

### Added

- [#7555](https://github.com/ChainSafe/forest/issues/7555): Added `--as-default` to `forest-wallet import`.
- [#7414](https://github.com/ChainSafe/forest/issues/7414): New `drand_http_fetch_total` metric, counting the drand rounds that had to be fetched over HTTP rather than served from the in-memory cache.

### Changed
Expand Down
3 changes: 1 addition & 2 deletions scripts/devnet-forest-miner/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ services:
set -euxo pipefail
export TOKEN=$$(cat ${FOREST_DATA_DIR}/token.jwt)
export FULLNODE_API_INFO=$$TOKEN:/dns/forest/tcp/${FOREST_RPC_PORT}/http
ADDR=$$(forest-wallet --remote-wallet import ${LOTUS_DATA_DIR}/genesis-sectors/pre-seal-${MINER_ACTOR_ADDRESS}.key)
forest-wallet --remote-wallet set-default "$$ADDR"
forest-wallet --remote-wallet import --as-default ${LOTUS_DATA_DIR}/genesis-sectors/pre-seal-${MINER_ACTOR_ADDRESS}.key

# Lotus Miner: the block producer. Its full-node API points at FOREST, so it
# drives block production through Forest's RPC (this is the swap vs ../devnet).
Expand Down
3 changes: 1 addition & 2 deletions scripts/devnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ services:
set -euxo pipefail
export TOKEN=$$(cat ${FOREST_DATA_DIR}/token.jwt)
export FULLNODE_API_INFO=$$TOKEN:/dns/forest/tcp/${FOREST_RPC_PORT}/http
ADDR=$$(forest-wallet --remote-wallet import ${LOTUS_DATA_DIR}/genesis-sectors/pre-seal-${MINER_ACTOR_ADDRESS}.key)
forest-wallet --remote-wallet set-default "$$ADDR"
forest-wallet --remote-wallet import --as-default ${LOTUS_DATA_DIR}/genesis-sectors/pre-seal-${MINER_ACTOR_ADDRESS}.key

volumes:
# Shared proof parameter files. It is re-used by both Lotus and Forest.
Expand Down
29 changes: 29 additions & 0 deletions src/dev/subcommands/tests_cmd/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ fn tests() -> Vec<Trial> {
block_on(export_import_roundtrip(Backend::Remote));
Ok(())
}),
Trial::test("import_as_default_local", || {
block_on(import_as_default(Backend::Local));
Ok(())
}),
Trial::test("import_as_default_remote", || {
block_on(import_as_default(Backend::Remote));
Ok(())
}),
Trial::test("market_add_balance_message_on_chain", || {
block_on(market_add_balance_message_on_chain());
Ok(())
Expand Down Expand Up @@ -91,6 +99,27 @@ async fn export_import_roundtrip(backend: Backend) {
);
}

async fn import_as_default(backend: Backend) {
let addr = wallet(backend, &["new"]).unwrap();
let exported = export_to_temp_file(&addr, backend).unwrap();
let path = exported
.path()
.to_str()
.expect("temp path is not valid UTF-8");

let deleted = wallet(backend, &["delete", &addr]).unwrap();
eprintln!("delete output ({}): {deleted}", backend.label());

let imported = wallet(backend, &["import", "--as-default", path]).unwrap();
Comment thread
sudo-shashank marked this conversation as resolved.
assert_eq!(
imported,
addr,
"round-trip mismatch on {} backend: {imported} != {addr}",
backend.label(),
);
assert_eq!(wallet(backend, &["default"]).unwrap(), imported);
}

async fn market_add_balance_message_on_chain() {
const ATTO_FIL: &str = "23";
let result = rpc_call_with_retry(
Expand Down
8 changes: 7 additions & 1 deletion src/wallet/subcommands/wallet_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ pub enum WalletCommands {
Import {
/// The path to the private key
path: Option<String>,
/// Set the imported address as default
#[arg(long)]
as_default: bool,
},
/// List addresses of the wallet
List {
Expand Down Expand Up @@ -374,7 +377,7 @@ impl WalletCommands {
println!("deleted {address}.");
Ok(())
}
Self::Import { path } => {
Self::Import { path, as_default } => {
let key = match path {
Some(path) => std::fs::read_to_string(path)?,
_ => {
Expand Down Expand Up @@ -405,6 +408,9 @@ impl WalletCommands {
.context("invalid key format")?;

let key = backend.wallet_import(key_info).await?;
if as_default {
backend.wallet_set_default(Address::from_str(&key)?).await?;
Comment thread
sudo-shashank marked this conversation as resolved.
}

println!("{key}");
Ok(())
Expand Down
Loading