- Hides
AccountInfo
fields behind methods
- Decouples
AccountInfo
from a specific prefix. address()
and id()
will derive the respective values on demand given a prefix &str
.
- Puts an
AccountInfo
's private key behind an Arc<T>
so that it can be Clone
. This makes the type much more ergonomic.
- Adds
TryFrom<SigningKey>
and TryFrom<Arc<SigningKey>>
impl constructors for AccountInfo
. Importantly, it checks that an AccountId
can be derived from the associated public key and returns an error otherwise. This allows us to assert that the AccountId
derivations will not error and therefore don't need to return a Result
. EDIT: changed to From<T>
Example
// Get an account's address from a key in a keystore
let account = keystore.get_account("my_account")?;
let address = account.address("cosmos")?;
// Create a new private key and derive the account
let sender_mnemonic = keyring
.create_cosmos_key("my_new_account", "", true)
.unwrap();
let seed = mnemonic.to_seed("");
let private_key: SigningKey = SigningKey::from_bytes(
&bip32::XPrv::derive_from_path(seed, path)
.expect("Could not create key.")
.private_key()
.to_bytes() as &[u8],
)
.unwrap();
let account = AccountInfo::from(private_key);
EDIT: examples after updates