This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Import evm wallet #251
Merged
Merged
Import evm wallet #251
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
// SPDX-License-Identifier: MIT | ||
//! Wallet import cli handler | ||
|
||
use anyhow::anyhow; | ||
use async_trait::async_trait; | ||
use clap::Args; | ||
use std::fmt::Debug; | ||
|
@@ -11,6 +12,9 @@ use crate::cli::commands::get_ipc_agent_url; | |
use crate::cli::{CommandLineHandler, GlobalArguments}; | ||
use crate::sdk::{IpcAgentClient, LotusJsonKeyType}; | ||
|
||
const FVM_WALLET: u8 = 0; | ||
const EVM_WALLET: u8 = 1; | ||
|
||
pub(crate) struct WalletImport; | ||
|
||
#[async_trait] | ||
|
@@ -28,11 +32,17 @@ impl CommandLineHandler for WalletImport { | |
return Err(anyhow::anyhow!("stdin not supported yet")); | ||
}; | ||
|
||
let key_type = LotusJsonKeyType::from_str(&keyinfo)?; | ||
let url = get_ipc_agent_url(&arguments.ipc_agent_url, global)?; | ||
|
||
let client = IpcAgentClient::default_from_url(url); | ||
let addr = client.import_lotus_json(key_type).await?; | ||
|
||
let addr = match arguments.network_type { | ||
FVM_WALLET => { | ||
let key_type = LotusJsonKeyType::from_str(&keyinfo)?; | ||
client.import_lotus_json(key_type).await? | ||
} | ||
EVM_WALLET => client.import_evm_private_key(keyinfo).await?, | ||
_ => return Err(anyhow!("invalid network type")), | ||
}; | ||
|
||
log::info!("imported wallet with address {:?}", addr); | ||
|
||
|
@@ -45,6 +55,12 @@ impl CommandLineHandler for WalletImport { | |
pub(crate) struct WalletImportArgs { | ||
#[arg(long, short, help = "The JSON RPC server url for ipc agent")] | ||
pub ipc_agent_url: Option<String>, | ||
#[arg( | ||
long, | ||
short, | ||
help = "The network the key belongs to, 0 for fvm, 1 for evm" | ||
)] | ||
pub network_type: u8, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to make it an enum or even two different boolean flags There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think bool is better, but not sure how we can enforce only one flag should be set. I can check it in code, but if we have more, then we need to update the code every time. |
||
#[arg(long, short, help = "Path of keyinfo file for the key to import")] | ||
pub path: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not an enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might not be able to pass enum to clap/cli, or at least not that easy. So use a number is just easier.