cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2021 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Cardano.Wallet.Address.Pool

Description

An address pool caches a collection of addresses. The purpose of this data structure is to aid in BIP-44 style address discovery with an address gap.

Synopsis

Documentation

data Pool addr ix Source #

An address pool caches a collection of addresses (type addr ) which are derived from a numeric index (type ix ).

Instances

Instances details
( Show addr, Show ix) => Show ( Pool addr ix) Source #
Instance details

Defined in Cardano.Wallet.Address.Pool

Generic ( Pool addr ix) Source #
Instance details

Defined in Cardano.Wallet.Address.Pool

Associated Types

type Rep ( Pool addr ix) :: Type -> Type Source #

Methods

from :: Pool addr ix -> Rep ( Pool addr ix) x Source #

to :: Rep ( Pool addr ix) x -> Pool addr ix Source #

( NFData addr, NFData ix) => NFData ( Pool addr ix) Source #
Instance details

Defined in Cardano.Wallet.Address.Pool

Methods

rnf :: Pool addr ix -> () Source #

Buildable ( Pool addr ix) Source #
Instance details

Defined in Cardano.Wallet.Address.Pool

type Rep ( Pool addr ix) Source #
Instance details

Defined in Cardano.Wallet.Address.Pool

addressFromIx :: Pool addr ix -> ix -> addr Source #

Mapping from a numeric index to its corresponding address.

This mapping is supposed to be (practically) a one-way function: Given an addr , it is impossible to compute the preimage ix in practice. The purpose of the Pool data structure is to help inverting this function regardless. The idea is that addresses with small indices 0,1,… are Used before addresses with larger indices; specifically, only less than gap many addresses in sequence may be Unused before the next Used address. This usage scheme restricts the search space considerably and allows us to practically invert the addressFromIx function.

addresses :: Pool addr ix -> Map addr (ix, AddressState ) Source #

Partial, cached inverse of the addressFromIx . This map contains all cached addresses addr , their corresponding indices ix , and whether they are Used or Unused . See prop_sequence .

usedAddresses :: Pool addr ix -> [addr] Source #

Sorted list of all addresses that are marked Used in the pool.

gap :: Pool addr ix -> Int Source #

The pool gap determines how Used and Unused have to be distributed. See prop_gap and prop_fresh .

lookup :: Ord addr => addr -> Pool addr ix -> Maybe ix Source #

Look up an address in the pool.

size :: Pool addr ix -> Int Source #

Number of addresses cached in the pool.

successor :: Enum ix => Pool addr ix -> ix -> Maybe ix Source #

Given an index ix , return the enumerated successor Just (succ ix) as long as the address corresponding to this successor is still in the pool.

This function is useful for address discovery in a light client setting, where the discovery procedure is: Start with index ix = 0 , query the corresponding address in an explorer, update address pool and repeat with successor ix until the latter returns Nothing . According to the BIP-44 standard, the account may not contain any other addresses than the ones discovered.

This function is not useful for generating change addresses, as it does not take Used or Unused status into account.

new :: ( Ord addr, Enum ix) => (ix -> addr) -> Int -> Pool addr ix Source #

Create a new address pool.

load :: ( Ord addr, Ord ix, Enum ix) => Pool addr ix -> Map addr (ix, AddressState ) -> Maybe ( Pool addr ix) Source #

Replace the collection of addresses in a pool, but only if this collection satisfies the necessary invariants such as prop_sequence etc.

update :: ( Ord addr, Enum ix) => addr -> Pool addr ix -> Pool addr ix Source #

Update an address to the Used status and create new Unused addresses in order to satisfy prop_fresh .

Does nothing if the address was not in the pool.

clear :: ( Ord addr, Enum ix) => Pool addr ix -> Pool addr ix Source #

Remove all previously discovered addresses, i.e. create a new pool with the same addressFromIx and gap as the old pool.

Address Discovery

discover :: ( Enum ix, Ord addr, Monad m, Monoid txs, Eq txs) => (addr -> m txs) -> Pool addr ix -> m (txs, Pool addr ix) Source #

Discover transactions and addresses by using an efficient query addr -> m txs and an address pool.

Internal

loadUnsafe :: Pool addr ix -> Map addr (ix, AddressState ) -> Pool addr ix Source #

Replace the collection of addresses in a pool, but skips checking the invariants.

prop_sequence :: ( Ord ix, Enum ix) => Pool addr ix -> Bool Source #

Internal invariant: The indices of the addresses in a pool form a finite sequence beginning with fromEnum 0 .

prop_gap :: Ord ix => Pool addr ix -> Bool Source #

Internal invariant: If we order the addresses by their indices, then there are always less than gap many Unused addresses between two consecutive Used addresses, or before the first Used address.

prop_fresh :: Ord ix => Pool addr ix -> Bool Source #

Internal invariant: If we order the addresses by their indices, there are exactly gap many Unused addresses after the last Used address.

prop_fromIx :: Eq addr => Pool addr ix -> Bool Source #

Internal invariant: All addresses in the pool have been generated from their index via the pool addressFromIx .

prop_consistent :: ( Ord ix, Enum ix, Eq addr) => Pool addr ix -> Bool Source #

Internal invariant: The pool satisfies all invariants above.