-
Notifications
You must be signed in to change notification settings - Fork 217
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
Add derivation path to api address #2598
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ module Cardano.Wallet.Primitive.AddressDiscovery.Random | |
, RndStateLike | ||
, mkRndState | ||
, DerivationPath | ||
, toDerivationIndexes | ||
|
||
-- ** Low-level API | ||
, importAddress | ||
|
@@ -334,9 +335,14 @@ instance CompareDiscovery (RndState n) where | |
|
||
instance KnownAddresses (RndState n) where | ||
knownAddresses s = mconcat | ||
[ Map.elems (discoveredAddresses s) | ||
, Map.elems ((,Unused) <$> pendingAddresses s) | ||
[ retrieveAddrsWithPaPath (discoveredAddresses s) | ||
, retrieveAddrsWithPaPath ((,Unused) <$> pendingAddresses s) | ||
] | ||
where | ||
constructAddrWithPath path (addr,state) acc = | ||
(addr, state, toDerivationIndexes path):acc | ||
retrieveAddrsWithPaPath = | ||
Map.foldrWithKey constructAddrWithPath [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion to avoid the extra traversal on pending addresses and also, make the function a bit more symmetric to more clearly see how the output is constructed: instance KnownAddresses (RndState n) where
knownAddresses s = mconcat
[ toListWithPath (\path (addr, state) -> (addr, state, path))
(discoveredAddresses s)
, toListWithPath (\path addr -> (addr, Unused, path))
(pendingAddresses s)
]
where
toListWithPath
:: (NonEmpty DerivationIndex -> v -> result)
-> Map DerivationPath v
-> [result]
toListWithPath mk =
Map.foldrWithKey
(\path v result -> mk (toDerivationIndexes path) v : result)
[] |
||
|
||
-------------------------------------------------------------------------------- | ||
-- | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -378,15 +378,23 @@ role = fromMaybe (error $ "role: unmatched type" <> show (typeRep @c)) | |
-- | ||
-- > mkAddressPool key g cc (addresses pool) == pool | ||
addresses | ||
:: forall c k. () | ||
:: forall c k. Typeable c | ||
=> (KeyFingerprint "payment" k -> Address) | ||
-> AddressPool c k | ||
-> [(Address, AddressState)] | ||
-> [(Address, AddressState, NonEmpty DerivationIndex)] | ||
addresses mkAddress = | ||
map (\(k, (_, st)) -> (mkAddress k, st)) | ||
map (\(k, (ix, st)) -> (mkAddress k, st, toDerivationPath ix)) | ||
. L.sortOn (fst . snd) | ||
. Map.toList | ||
. indexedKeys | ||
where | ||
toDerivationPath ix = NE.fromList $ map DerivationIndex | ||
[ getIndex purposeBIP44 | ||
, getIndex purposeCIP1852 | ||
, 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay-ish because we assume the first account. I'd however rather leave a note as comment explaining this hard-coded value. |
||
, fromIntegral $ fromEnum $ role @c | ||
, getIndex ix | ||
] | ||
|
||
-- | Create a new Address pool from a list of addresses. Note that, the list is | ||
-- expected to be ordered in sequence (first indexes, first in the list). | ||
|
@@ -913,7 +921,7 @@ instance | |
addresses (liftPaymentAddress @n @k) (internalPool s) | ||
|
||
usedChangeAddresses = | ||
filter ((== Used) . snd) changeAddresses | ||
filter (\(_, state, _) -> state == Used) changeAddresses | ||
|
||
-- pick as many unused change addresses as there are pending | ||
-- transactions. Note: the last `internalGap` addresses are all | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍