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
Show file tree
Hide file tree
Changes from 2 commits
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
13 changes: 10 additions & 3 deletions sdk/examples/wallet/spammer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use iota_sdk::{
request_funds_from_faucet,
secret::{mnemonic::MnemonicSecretManager, SecretManager},
},
types::block::{address::Bech32Address, output::BasicOutput, payload::transaction::TransactionId},
wallet::{account::FilterOptions, Account, ClientOptions, Result, SendParams, Wallet},
types::block::{address::{Bech32Address, Address}, output::BasicOutput, payload::transaction::TransactionId},
wallet::{account::FilterOptions, Account, ClientOptions, Result, SendParams, Wallet}, crypto::keys::bip44::Bip44,
};

// The account alias used in this example.
Expand All @@ -39,12 +39,19 @@ async fn main() -> Result<()> {
// Restore wallet from a mnemonic phrase.
let client_options = ClientOptions::new().with_node(&std::env::var("NODE_URL").unwrap())?;
let secret_manager = MnemonicSecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?;

todo!("generate and set address");

let wallet = Wallet::builder()
.with_alias(ACCOUNT_ALIAS)
// .with_address(Address::Ed25519(...))
.with_bip44(Bip44::new(SHIMMER_COIN_TYPE))
.with_secret_manager(SecretManager::Mnemonic(secret_manager))
.with_client_options(client_options)
.with_coin_type(SHIMMER_COIN_TYPE)
.finish()
.await?;

todo!("remove this");
let account = wallet.get_or_create_account(ACCOUNT_ALIAS).await?;

let recv_address = *account.addresses().await?[0].address();
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/client/node_api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl ClientInner {
/// Returns the information of committee members at the given epoch index. If epoch index is not provided, the
/// current committee members are returned.
/// GET /api/core/v3/committee/?epochIndex
pub async fn get_committee(&self, epoch_index: impl Into<Option<EpochIndex>>) -> Result<CommitteeResponse> {
pub async fn get_committee(&self, epoch_index: impl Into<Option<EpochIndex>> + Send) -> Result<CommitteeResponse> {
const PATH: &str = "api/core/v3/committee";

let epoch_index = epoch_index.into().map(|i| format!("epochIndex={i}"));
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]
// TODO missing_docs
#![deny(clippy::nursery, rust_2018_idioms, /* warnings, */ unreachable_pub)]
#![deny(clippy::nursery, rust_2018_idioms, /* warnings, unreachable_pub */)]
#![allow(
clippy::redundant_pub_crate,
clippy::missing_const_for_fn,
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/core/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ pub(crate) mod dto {
});
}

Ok(BlockWrapper::new(
Ok(Self::new(
&protocol_params,
dto.issuing_time,
dto.slot_commitment_id,
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/slot/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl SlotIndex {

/// Gets the slot index of a unix timestamp.
/// Slots are counted starting from `1` with `0` being reserved for times before the genesis.
pub fn from_timestamp(timestamp: u64, genesis_unix_timestamp: u64, slot_duration_in_seconds: u8) -> SlotIndex {
pub fn from_timestamp(timestamp: u64, genesis_unix_timestamp: u64, slot_duration_in_seconds: u8) -> Self {
timestamp
.checked_sub(genesis_unix_timestamp as u64)
.map(|diff| (diff / slot_duration_in_seconds as u64) + 1)
Expand Down
165 changes: 85 additions & 80 deletions sdk/src/wallet/account/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,87 +59,90 @@ where
/// Also generates the first address of the account and if it's not the first account, the address for the first
/// account will also be generated and compared, so no accounts get generated with different seeds
pub async fn finish(&mut self) -> crate::wallet::Result<Account<S>> {
let mut accounts = self.wallet.accounts.write().await;
let account_index = accounts.len() as u32;
// If no alias is provided, the account index will be set as alias
let account_alias = self.alias.clone().unwrap_or_else(|| account_index.to_string());
log::debug!(
"[ACCOUNT BUILDER] creating new account {} with index {}",
account_alias,
account_index
);

// Check that the alias isn't already used for another account
for account in accounts.iter() {
let account = account.details().await;
if account.alias().to_lowercase() == account_alias.to_lowercase() {
return Err(Error::AccountAliasAlreadyExists(account_alias));
}
}

let coin_type = self.wallet.coin_type.load(core::sync::atomic::Ordering::Relaxed);

// If addresses are provided we will use them directly without the additional checks, because then we assume
// that it's for offline signing and the secretManager can't be used
let addresses = match &self.addresses {
Some(addresses) => addresses.clone(),
None => {
let mut bech32_hrp = self.bech32_hrp;
if let Some(first_account) = accounts.first() {
let first_account_coin_type = *first_account.details().await.coin_type();
// Generate the first address of the first account and compare it to the stored address from the
// first account to prevent having multiple accounts created with different
// seeds
let first_account_public_address =
get_first_public_address(&self.wallet.secret_manager, first_account_coin_type, 0).await?;
let first_account_addresses = first_account.public_addresses().await;

if Address::Ed25519(first_account_public_address)
!= first_account_addresses
.first()
.ok_or(Error::FailedToGetRemainder)?
.address
.inner
{
return Err(Error::InvalidMnemonic(
"first account address used another seed".to_string(),
));
}

// Get bech32_hrp from address
if let Some(address) = first_account_addresses.first() {
if bech32_hrp.is_none() {
bech32_hrp = Some(address.address.hrp);
}
}
}

// get bech32_hrp
let bech32_hrp = {
match bech32_hrp {
Some(bech32_hrp) => bech32_hrp,
None => self.wallet.client().get_bech32_hrp().await?,
}
};

let first_public_address =
get_first_public_address(&self.wallet.secret_manager, coin_type, account_index).await?;

let first_public_account_address = Bip44Address {
address: Bech32Address::new(bech32_hrp, first_public_address),
key_index: 0,
internal: false,
};

vec![first_public_account_address]
}
};
let mut wallet_data = self.wallet.data.write().await;

// let account_index = wallet_data.len() as u32;
// // If no alias is provided, the account index will be set as alias
// let account_alias = self.alias.clone().unwrap_or_else(|| account_index.to_string());
// log::debug!(
// "[ACCOUNT BUILDER] creating new account {} with index {}",
// account_alias,
// account_index
// );

// // Check that the alias isn't already used for another account
// for account in wallet_data.iter() {
// let account = account.details().await;
// if account.alias().to_lowercase() == account_alias.to_lowercase() {
// return Err(Error::AccountAliasAlreadyExists(account_alias));
// }
// }

// let coin_type = self.wallet.coin_type.load(core::sync::atomic::Ordering::Relaxed);

// // If addresses are provided we will use them directly without the additional checks, because then we assume
// // that it's for offline signing and the secretManager can't be used
// let addresses = match &self.addresses {
// Some(addresses) => addresses.clone(),
// None => {
// let mut bech32_hrp = self.bech32_hrp;
// if let Some(first_account) = wallet_data.first() {
// let first_account_coin_type = *first_account.details().await.coin_type();
// // Generate the first address of the first account and compare it to the stored address from the
// // first account to prevent having multiple accounts created with different
// // seeds
// let first_account_public_address =
// get_first_public_address(&self.wallet.secret_manager, first_account_coin_type, 0).await?;
// let first_account_addresses = first_account.public_addresses().await;

// if Address::Ed25519(first_account_public_address)
// != first_account_addresses
// .first()
// .ok_or(Error::FailedToGetRemainder)?
// .address
// .inner
// {
// return Err(Error::InvalidMnemonic(
// "first account address used another seed".to_string(),
// ));
// }

// // Get bech32_hrp from address
// if let Some(address) = first_account_addresses.first() {
// if bech32_hrp.is_none() {
// bech32_hrp = Some(address.address.hrp);
// }
// }
// }

// // get bech32_hrp
// let bech32_hrp = {
// match bech32_hrp {
// Some(bech32_hrp) => bech32_hrp,
// None => self.wallet.client().get_bech32_hrp().await?,
// }
// };

// let first_public_address =
// get_first_public_address(&self.wallet.secret_manager, coin_type, account_index).await?;

// let first_public_account_address = Bip44Address {
// address: Bech32Address::new(bech32_hrp, first_public_address),
// key_index: 0,
// internal: false,
// };

// vec![first_public_account_address]
// }
// };

todo!();

let account = AccountDetails {
index: account_index,
coin_type,
alias: account_alias,
public_addresses: addresses,
index: 0,
coin_type: todo!("coin_type"),
alias: todo!("account alias"),
public_addresses: todo!("addresses"),
internal_addresses: Vec::new(),
addresses_with_unspent_outputs: Vec::new(),
outputs: HashMap::new(),
Expand All @@ -155,7 +158,9 @@ where
let account = Account::new(account, self.wallet.inner.clone()).await?;
#[cfg(feature = "storage")]
account.save(None).await?;
accounts.push(account.clone());

todo!("set instead of push");
// wallet_data.push(account.clone());

Ok(account)
}
Expand Down
Loading
Loading