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

chore!: wallet refactoring #1620

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open

Conversation

segfault-magnet
Copy link
Contributor

@segfault-magnet segfault-magnet commented Mar 10, 2025

Release notes

Wallets are now unified in a single type generic over the signer.

In this release, we:

  • Unified all the existing wallets in the SDK into a single wallet type holding a signer.

Summary

Breaking Changes

ImpersonatedAccount is removed

To achieve the same functionality instantiate a `FakeSigner:

    let impersonator = Wallet::new(FakeSigner::new(address), provider.clone());

AwsKmsSigner and GoogleKmsSigner moved

under fuels::accounts::signers::kms::aws and fuels::accounts::signers::kms::google, respectfully.

KmsWallet removed

use an ordinary Wallet now with a kms signer (aws or google)

WalletUnlocked and Wallet substituted by Wallet<Unlocked<S = PrivateKeySigner>> or Wallet<Locked>

The provider is now mandatory for Wallet::new.

Common operations in the new API:

Creating a random wallet:

a) Two step (useful when you haven't started the node but need the address)

    // Create a random private key signer
    let signer = PrivateKeySigner::random(&mut rng);
    let coins = setup_single_asset_coins(signer.address(), asset_id, 1, DEFAULT_COIN_AMOUNT);
    let provider = setup_test_provider(coins.clone(), vec![], None, None).await?;
    let wallet = Wallet::new(signer, provider);

b) One step (when you already have a provider)

    let wallet = Wallet::random(&mut rng, provider.clone());
Locking a wallet
    let locked_wallet = wallet.lock();
Creating a locked wallet
    let wallet = Wallet::new_locked(addr, provider.clone());
Wallets no longer sign

You use one of the signers for that. Or, if your wallet is unlocked, get its signer by calling wallet.signer().

ViewOnlyAccount no longer requires core::fmt::Debug and core::clone::Clone as supertraits.

Wallet no longer handles encrypting keys for disk storage

Use the fuels::accounts::Keystore for that (feature-gated under accounts-keystore)

AWS/Google kms feature flags changed

They're now accounts-signer-aws-kms and accounts-signer-google-kms.

Checklist

  • All changes are covered by tests (or not applicable)
  • All changes are documented (or not applicable)
  • I reviewed the entire PR myself (preferably, on GH UI)
  • I described all Breaking Changes (or there's none)

@segfault-magnet segfault-magnet self-assigned this Mar 10, 2025
@segfault-magnet segfault-magnet marked this pull request as ready for review March 11, 2025 08:25
@@ -9,7 +9,7 @@ publish = false
repository = { workspace = true }
description = "Fuel Rust SDK contract examples."

[dev-dependencies]
[dependencies]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples didn't build under newer rust versions because you cannot (still) enable features on dev deps via feature flags of your own (and it seems we tried to do that in the past but failed silently... until now).

#[cfg(feature = "signer-google-kms")]
pub mod google;

mod signature_utils {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes, just moved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorted it and added a few words.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify wallets
1 participant