Loading saved pairs
Adding accounts is good. Having access to these accounts when added via const { pair } = keyring.addUr(...)
is better, but being able to access these to iterate over at a later point (even after reload), is magic. Here we will try to add some magic to your experience, allowing you to retrieve accounts as well as subscribe to changes as they happen.
#
Loading all availableAs we've seen in the keyring init section, when we can loadAll
, it loads all added added - this includes those added via addUri(...)
which transparently saves to the provided storage. Loading means it is available in the keyring, to get a list of the accounts, we can then do -
The above interface was probably not quite what you have been expecting, rather you would have expected to get back a list of the pairs, but rather you received a list of the account descriptors. Some rationale for this approach - since we have getAccounts()
, getAddresses()
(for contacts) and getContracts()
the consistent interface here is applicable. Instead based on an address, you can then retrieve a specific pair -
Similarly we have a getPairs()
that mirrors getAccounts()
, but retrieves the list of available pairs - which is the output you probably expected from the initial getAccounts()
call.
#
Subscriptions (Optional)In addition to the retrieving of accounts on demand, we can actually subscribe to accounts for the keyring. This subscription returns a list of all accounts as they are updated, i.e. when a new account is added it will callback with a list of all the account, including the new one, when an account is removed, it will callback with a list of accounts, excluding the removed member.
As with the get{Accounts|Addresses|Contracts}()
functions, similarly we have in addition to keyring.accounts.subject
the keyring.addresses.subject
and keyring.contracts.subject
subscriptions available, with the same generic result set.