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

Single account wallet #1279

Merged
merged 116 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
48a698d
start impl
Alex6323 Sep 21, 2023
cfb6589
walk the line 1
Alex6323 Sep 21, 2023
cc2bb0c
walk the line 2
Alex6323 Sep 21, 2023
ec94415
walk the line 3
Alex6323 Sep 22, 2023
7032453
update examples
Alex6323 Sep 25, 2023
03a5844
update tests
Alex6323 Sep 25, 2023
91c83e8
more
Alex6323 Sep 25, 2023
adc2965
update cli
Alex6323 Sep 25, 2023
75c6f11
update wallet builder
Alex6323 Sep 26, 2023
6d7d282
remove redundant event wrapper
Alex6323 Sep 27, 2023
088281f
fix remaining todos 1
Alex6323 Sep 27, 2023
199a6fe
fix remaining todos 2
Alex6323 Sep 27, 2023
e1aa5e9
fix remaining todos 3
Alex6323 Sep 27, 2023
402e4a9
fix remaining todos 4
Alex6323 Sep 27, 2023
250500d
Merge branch '2.0' into refactor/wallet-account
Alex6323 Sep 27, 2023
62029f5
clean up cli
Alex6323 Sep 27, 2023
c799a38
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 2, 2023
751ad14
fix test 1
Alex6323 Sep 27, 2023
9abd625
fix test 2
Alex6323 Sep 27, 2023
ae8a04c
optional wallet alias
Alex6323 Oct 4, 2023
ed7731b
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 4, 2023
12e796a
get rid of some warnings; nits
Alex6323 Oct 4, 2023
28db840
nits
Alex6323 Oct 4, 2023
1426c40
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 4, 2023
a295337
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 11, 2023
93f96ed
fix some todos
Alex6323 Oct 11, 2023
e6cae42
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 11, 2023
7ce754d
remove account backgroudn syncing stuff
Alex6323 Oct 11, 2023
5b3dcc2
merge fix 1
Alex6323 Oct 12, 2023
11ee307
merge fix 2
Alex6323 Oct 12, 2023
c0856cf
remove account parent module
Alex6323 Oct 12, 2023
a36edf1
update core bindings
Alex6323 Oct 12, 2023
8d04532
rename
Alex6323 Oct 12, 2023
7fe9601
PR suggestions 1
Alex6323 Oct 12, 2023
6ec326e
PR suggestions 2
Alex6323 Oct 12, 2023
a5dbcba
fix common features sets [wallet, stronghold]
Alex6323 Oct 12, 2023
54101e1
remove account related tests and examples
Alex6323 Oct 12, 2023
b294636
rename stuff
Alex6323 Oct 16, 2023
160829d
remove oopsies
Alex6323 Oct 16, 2023
f0a3dde
use bip path
Alex6323 Oct 16, 2023
cf8f994
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 16, 2023
edd32e1
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 18, 2023
3aedbc4
rename operation to command
Alex6323 Oct 17, 2023
4178b15
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 18, 2023
8ca8e39
doc fixes
Alex6323 Oct 18, 2023
2e4e3d9
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 24, 2023
63635b7
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 24, 2023
e39542e
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 24, 2023
30a6dfb
nits
Alex6323 Oct 24, 2023
f1b8d31
nits 2
Alex6323 Oct 24, 2023
e35f9bf
nits 3
Alex6323 Oct 24, 2023
e862d2d
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 25, 2023
2d12273
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 26, 2023
1fbbbca
kill Alice ... sooory
Alex6323 Oct 26, 2023
529e1d8
re-enable tests 1
Alex6323 Oct 26, 2023
c7aad63
optional bip path
Alex6323 Oct 26, 2023
5c4cdab
remove verifiy_accounts test
Alex6323 Oct 26, 2023
f63463d
re-enable wallet error serialization test
Alex6323 Oct 26, 2023
53b8bd0
cli: optional bip path
Alex6323 Oct 26, 2023
724b0bb
remove
Alex6323 Oct 26, 2023
5ad2136
more remove
Alex6323 Oct 26, 2023
753e60e
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 26, 2023
efe7e7c
rm dupl imports
Alex6323 Oct 26, 2023
7f625c6
Merge branch '2.0' into refactor/wallet-account
thibault-martinez Oct 27, 2023
76af2a6
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 30, 2023
ac8255e
remove remaining account mentioning in prints
Alex6323 Oct 30, 2023
cd78a60
revert fn rename
Alex6323 Oct 30, 2023
df7a04d
update todo
Alex6323 Oct 30, 2023
a6328b1
update todo 2
Alex6323 Oct 30, 2023
389570a
remove more wallet/account alias mentioning
Alex6323 Oct 30, 2023
e8bba3e
remove more account mentioning
Alex6323 Oct 30, 2023
2aab93c
more renames
Alex6323 Oct 31, 2023
f71d140
custom error serializations
Alex6323 Oct 31, 2023
3680b9d
weird that's still there
Alex6323 Oct 31, 2023
496ae58
more renames
Alex6323 Oct 31, 2023
e927b45
remove more
Alex6323 Oct 31, 2023
b72c04b
Rename alias to account sync options
Alex6323 Oct 31, 2023
1bfa266
default alias
Alex6323 Oct 31, 2023
73eecbc
more
Alex6323 Oct 31, 2023
4a1f95e
and more
Alex6323 Oct 31, 2023
5a5f262
also some that thibault overlooked. how come?
Alex6323 Oct 31, 2023
35de853
more renames ^2
Alex6323 Oct 31, 2023
84a39bc
Rename to wallet-sync-options
Alex6323 Oct 31, 2023
44568d1
Rename secret manager key
Alex6323 Oct 31, 2023
cd4d1c2
Merge branch '2.0' into refactor/wallet-account
Alex6323 Oct 31, 2023
2802b19
nits
Alex6323 Oct 31, 2023
ecd3dbe
nits 2
Alex6323 Oct 31, 2023
6dc16fc
remove whooopsie
Alex6323 Oct 31, 2023
51153f3
optional alias
Alex6323 Oct 31, 2023
f503dec
error tests
Alex6323 Nov 1, 2023
d5060ae
harmony
Alex6323 Nov 1, 2023
0fdcb9e
Merge branch '2.0' into refactor/wallet-account
Alex6323 Nov 1, 2023
8096151
nursery
Alex6323 Nov 1, 2023
f860f06
deny restore with outputs
Alex6323 Nov 1, 2023
abbe274
Rename file
thibault-martinez Nov 1, 2023
a5fe126
Remove inner
thibault-martinez Nov 1, 2023
ae20ba2
More changes
thibault-martinez Nov 1, 2023
9446b12
Merge branch '2.0' into refactor/wallet-account
thibault-martinez Nov 1, 2023
d4cba3f
Comment failing tests
thibault-martinez Nov 1, 2023
73ecd7e
Nit
thibault-martinez Nov 1, 2023
c2d32cf
More nits
thibault-martinez Nov 1, 2023
b958150
Update sdk/src/wallet/core/operations/background_syncing.rs
thibault-martinez Nov 1, 2023
70a3b38
Merge branch '2.0' into refactor/wallet-account
thibault-martinez Nov 1, 2023
619e8b1
Fix a test
thibault-martinez Nov 1, 2023
c691b2c
Bring back assert
thibault-martinez Nov 1, 2023
80addf9
Fix response type
thibault-martinez Nov 1, 2023
c0ea729
Fix another response type
thibault-martinez Nov 1, 2023
c481880
Remove useless added inner() calls
thibault-martinez Nov 1, 2023
9607353
Bring back faucet address
thibault-martinez Nov 1, 2023
c2da899
Fix comment
thibault-martinez Nov 1, 2023
85a116e
Not need to use format
thibault-martinez Nov 1, 2023
860f4ff
TODO
thibault-martinez Nov 1, 2023
3a0752a
update_after_sync
thibault-martinez Nov 1, 2023
9565d7a
Fix log
thibault-martinez Nov 1, 2023
a21a32d
TODO
thibault-martinez Nov 1, 2023
c42b8d8
Improve comment?
thibault-martinez Nov 1, 2023
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
Prev Previous commit
Next Next commit
optional wallet alias
Alex6323 committed Oct 4, 2023
commit ae8a04c4abc2f9f4ce860b014b440aba7ade4944
9 changes: 7 additions & 2 deletions cli/src/wallet_cli.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ use iota_sdk::{
utils::Password,
},
crypto::keys::bip44::Bip44,
types::block::address::{Bech32Address, Hrp},
types::block::address::Bech32Address,
wallet::{ClientOptions, Wallet},
};
use log::LevelFilter;
@@ -249,7 +249,12 @@ pub async fn init_command(
secret_manager.store_mnemonic(mnemonic).await?;
let secret_manager = SecretManager::Stronghold(secret_manager);

let alias = get_alias("New wallet alias").await?;
let alias = if get_decision("Do you want to assign an alias to your wallet?")? {
Some(get_alias("New wallet alias").await?)
} else {
None
};

let address = init_params
.address
.map(|addr| Bech32Address::from_str(&addr))
53 changes: 16 additions & 37 deletions sdk/src/wallet/core/builder.rs
Original file line number Diff line number Diff line change
@@ -85,8 +85,8 @@ where
}

/// Set the alias of the wallet.
pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
self.alias = Some(alias.into());
pub fn with_alias(mut self, alias: impl Into<Option<String>>) -> Self {
self.alias = alias.into();
self
}

@@ -147,17 +147,9 @@ where
if self.bip_path.is_none() {
return Err(crate::wallet::Error::MissingParameter("bip_path"));
}
if self.alias.is_none() {
return Err(crate::wallet::Error::MissingParameter("alias"));
}
if self.client_options.is_none() {
return Err(crate::wallet::Error::MissingParameter("client_options"));
}

// // TODO: consider not requiring a secret manager
// if self.secret_manager.is_none() {
// return Err(crate::wallet::Error::MissingParameter("secret_manager"));
// }
}

#[cfg(all(feature = "rocksdb", feature = "storage"))]
@@ -214,38 +206,22 @@ where
let alias = loaded_wallet_builder
.as_ref()
.and_then(|builder| builder.alias.clone())
.ok_or(crate::wallet::Error::MissingParameter("alias"))?;
.unwrap_or_else(|| storage_options.path().to_string_lossy().to_string());

self.alias = Some(alias);
}
// Panic: can be safely unwrapped now
let alias = self.alias.as_ref().unwrap().clone();
DaughterOfMars marked this conversation as resolved.
Show resolved Hide resolved

let bech32_hrp = self
.client_options
.as_ref()
.unwrap()
.network_info
.protocol_parameters
.bech32_hrp;

// May use a previously stored wallet address if it wasn't provided
if self.address.is_none() {
let address = loaded_wallet_builder.as_ref().and_then(|builder| builder.address);

self.address = address;
self.address = loaded_wallet_builder.as_ref().and_then(|builder| builder.address);
}

// May create a default Ed25519 wallet address if there's a secret manager.
if self.address.is_none() {
if self.secret_manager.is_some() {
let secret_manager = &**self.secret_manager.as_ref().unwrap();
let bip_path = *self.bip_path.as_ref().unwrap();
// TODO: remove
// let coin_type = bip_path.coin_type;
// let account_index = bip_path.account;
let address = self.create_default_wallet_address(bech32_hrp, bip_path).await?;

let address = self.create_default_wallet_address().await?;
self.address = Some(address);
} else {
return Err(crate::wallet::Error::MissingParameter("address"));
@@ -272,8 +248,6 @@ where
}
}

// TODO: check address against the BIP account index and address index

// Store the wallet builder (for convenience reasons)
#[cfg(feature = "storage")]
self.save(&storage_manager).await?;
@@ -327,13 +301,18 @@ where
}

/// Generate the wallet address.
pub(crate) async fn create_default_wallet_address(
&self,
hrp: Hrp,
bip_path: Bip44,
) -> crate::wallet::Result<Bech32Address> {
pub(crate) async fn create_default_wallet_address(&self) -> crate::wallet::Result<Bech32Address> {
let bech32_hrp = self
.client_options
.as_ref()
.unwrap()
.network_info
.protocol_parameters
.bech32_hrp;
let bip_path = self.bip_path.as_ref().unwrap();

Ok(Bech32Address::new(
hrp,
bech32_hrp,
Address::Ed25519(
self.secret_manager
.as_ref()
12 changes: 6 additions & 6 deletions sdk/tests/wallet/balance.rs
Original file line number Diff line number Diff line change
@@ -99,9 +99,9 @@ async fn balance_expiration() -> Result<()> {
setup(storage_path_1)?;
setup(storage_path_2)?;

let wallet_0 = make_wallet(storage_path_0, None, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None, None).await?;
let wallet_2 = make_wallet(storage_path_2, None, None, None).await?;
let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None).await?;
let wallet_2 = make_wallet(storage_path_2, None, None).await?;

request_funds(&wallet_0).await?;

@@ -182,8 +182,8 @@ async fn balance_transfer() -> Result<()> {
setup(storage_path_0)?;
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, None, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None, None).await?;
let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None).await?;

request_funds(&wallet_0).await?;

@@ -229,7 +229,7 @@ async fn balance_voting_power() -> Result<()> {
let storage_path = "test-storage/balance_voting_power";
setup(storage_path)?;

let wallet = make_wallet(storage_path, None, None, None).await?;
let wallet = make_wallet(storage_path, None, None).await?;

request_funds(&wallet).await?;

4 changes: 2 additions & 2 deletions sdk/tests/wallet/bech32_hrp_validation.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ async fn bech32_hrp_send_amount() -> Result<()> {
let storage_path = "test-storage/bech32_hrp_send_amount";
setup(storage_path)?;

let wallet = make_wallet(storage_path, None, None, None).await?;
let wallet = make_wallet(storage_path, None, None).await?;

let error = wallet
.send_with_params(
@@ -50,7 +50,7 @@ async fn bech32_hrp_prepare_output() -> Result<()> {
let storage_path = "test-storage/bech32_hrp_prepare_output";
setup(storage_path)?;

let wallet = make_wallet(storage_path, None, None, None).await?;
let wallet = make_wallet(storage_path, None, None).await?;

let error = wallet
.prepare_output(
12 changes: 6 additions & 6 deletions sdk/tests/wallet/burn_outputs.rs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ async fn mint_and_burn_nft() -> Result<()> {
let storage_path = "test-storage/mint_and_burn_outputs";
setup(storage_path)?;

let wallet = make_wallet(storage_path, None, None, None).await?;
let wallet = make_wallet(storage_path, None, None).await?;
request_funds(&wallet).await?;

let nft_options = [MintNftParams::new()
@@ -59,8 +59,8 @@ async fn mint_and_burn_expired_nft() -> Result<()> {
let storage_path = "test-storage/mint_and_burn_expired_nft";
setup(storage_path)?;

let wallet_0 = make_wallet(storage_path, None, None, None).await?;
let wallet_1 = make_wallet(storage_path, None, None, None).await?;
let wallet_0 = make_wallet(storage_path, None, None).await?;
let wallet_1 = make_wallet(storage_path, None, None).await?;
request_funds(&wallet_0).await?;

let token_supply = wallet_0.client().get_token_supply().await?;
@@ -100,7 +100,7 @@ async fn create_and_melt_native_token() -> Result<()> {
let storage_path = "test-storage/create_and_melt_native_token";
setup(storage_path)?;

let wallet = make_wallet(storage_path, None, None, None).await?;
let wallet = make_wallet(storage_path, None, None).await?;
request_funds(&wallet).await?;

// First create an account output, this needs to be done only once, because an account can have many foundry outputs
@@ -229,7 +229,7 @@ async fn create_and_burn_native_tokens() -> Result<()> {
let storage_path = "test-storage/create_and_burn_native_tokens";
setup(storage_path)?;

let wallet = make_wallet(storage_path, None, None, None).await?;
let wallet = make_wallet(storage_path, None, None).await?;

request_funds(&wallet).await?;

@@ -276,7 +276,7 @@ async fn mint_and_burn_nft_with_account() -> Result<()> {
let storage_path = "test-storage/mint_and_burn_nft_with_account";
setup(storage_path)?;

let wallet = make_wallet(storage_path, None, None, None).await?;
let wallet = make_wallet(storage_path, None, None).await?;
request_funds(&wallet).await?;

let tx = wallet.create_account_output(None, None).await?;
32 changes: 16 additions & 16 deletions sdk/tests/wallet/claim_outputs.rs
Original file line number Diff line number Diff line change
@@ -23,8 +23,8 @@ async fn claim_2_basic_micro_outputs() -> Result<()> {
setup(storage_path_0)?;
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, None, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None, None).await?;
let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None).await?;

request_funds(&wallet_0).await?;
request_funds(&wallet_1).await?;
@@ -80,8 +80,8 @@ async fn claim_1_of_2_basic_outputs() -> Result<()> {
setup(storage_path_0)?;
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, None, None, None).await?;
let wallet_1 = make_wallet(storage_path_0, None, None, None).await?;
let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_0, None, None).await?;

request_funds(&wallet_0).await?;
request_funds(&wallet_1).await?;
@@ -137,8 +137,8 @@ async fn claim_2_basic_outputs_no_outputs_in_claim_account() -> Result<()> {
setup(storage_path_0)?;
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, None, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None, None).await?;
let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None).await?;

request_funds(&wallet_0).await?;

@@ -194,8 +194,8 @@ async fn claim_2_native_tokens() -> Result<()> {
setup(storage_path_0)?;
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, None, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None, None).await?;
let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None).await?;

request_funds(&wallet_0).await?;
request_funds(&wallet_1).await?;
@@ -294,8 +294,8 @@ async fn claim_2_native_tokens_no_outputs_in_claim_account() -> Result<()> {
setup(storage_path_0)?;
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, None, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None, None).await?;
let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None).await?;

request_funds(&wallet_0).await?;

@@ -410,8 +410,8 @@ async fn claim_2_nft_outputs() -> Result<()> {
setup(storage_path_0)?;
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, None, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None, None).await?;
let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None).await?;

request_funds(&wallet_0).await?;
request_funds(&wallet_1).await?;
@@ -473,8 +473,8 @@ async fn claim_2_nft_outputs_no_outputs_in_claim_account() -> Result<()> {
setup(storage_path_0)?;
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, None, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None, None).await?;
let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None).await?;

request_funds(&wallet_0).await?;

@@ -535,8 +535,8 @@ async fn claim_basic_micro_output_error() -> Result<()> {
setup(storage_path_0)?;
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, None, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None, None).await?;
let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None).await?;

request_funds(&wallet_0).await?;

13 changes: 3 additions & 10 deletions sdk/tests/wallet/common/mod.rs
Original file line number Diff line number Diff line change
@@ -27,14 +27,9 @@ pub use self::constants::*;
///
/// Returns:
///
/// An Wallet
/// A Wallet
#[allow(dead_code, unused_variables)]
pub(crate) async fn make_wallet(
storage_path: &str,
mnemonic: Option<Mnemonic>,
node: Option<&str>,
alias: impl Into<Option<&'static str>>,
) -> Result<Wallet> {
pub(crate) async fn make_wallet(storage_path: &str, mnemonic: Option<Mnemonic>, node: Option<&str>) -> Result<Wallet> {
let client_options = ClientOptions::new().with_node(node.unwrap_or(NODE_LOCAL))?;
let secret_manager =
MnemonicSecretManager::try_from_mnemonic(mnemonic.unwrap_or(Client::generate_mnemonic().unwrap()))?;
@@ -45,9 +40,7 @@ pub(crate) async fn make_wallet(
.with_client_options(client_options)
.with_bip_path(Bip44::new(SHIMMER_COIN_TYPE));

if let Some(alias) = alias.into() {
wallet_builder = wallet_builder.with_alias(alias);
}
wallet_builder = wallet_builder.with_alias(storage_path);

#[cfg(feature = "storage")]
{
4 changes: 2 additions & 2 deletions sdk/tests/wallet/consolidation.rs
Original file line number Diff line number Diff line change
@@ -13,8 +13,8 @@ async fn consolidation() -> Result<()> {
setup(storage_path_0)?;
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, None, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None, None).await?;
let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None).await?;

request_funds(&wallet_0).await?;

Loading