addAddress method

Future<Address> addAddress (
  1. Address x,
  2. {bool store: true,
  3. bool load: true,
  4. Transaction txn}
)
override

Store Address and _filterNetworkFor it.

Implementation

Future<Address> addAddress(Address x,
    {bool store = true, bool load = true, sembast.Transaction txn}) async {
  if (preferences != null &&
      preferences.verifyAddressEveryLoad &&
      !x.verify()) {
    throw FormatException('${x.publicKey.toJson()} verify failed');
  }
  addresses[x.publicKey.toJson()] = x;
  if (store) await _storeAddress(x, txn);
  if (hdWallet) {
    if (x.state == AddressState.reserve) {
      account.reserveAddress[x.chainIndex] = x;
    }
    if (x.chainIndex >= account.nextIndex) {
      account.nextIndex = x.chainIndex + 1;
      await _storeAccount(account, txn);
    }
  }
  if (load) unawaited(_filterNetworkFor(x));
  return x;
}