-
Notifications
You must be signed in to change notification settings - Fork 220
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
[ADP-3372] Deposit Wallet - json roundtrips for types #4710
Conversation
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.
Good, thank you! 😊 However, I have a request — please do not move the Customer
type, it's not part of the Read
hierarchy and also not an abstract data type. See comments for more info.
, Customer | ||
, fromRawCustomer | ||
|
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.
, Customer | |
, fromRawCustomer |
Wait — the concern of the Read
modules is to read data as specified in the ledger specification, and as it appears on the blockchain, but Customer
is not part of that. 😅 (The name Deposit
is accidental, I want to merge this module with Cardano.Wallet.Read
but had to choose a different name here in order to avoid a name clash.)
Could you leave the Customer
type where it is, and instead solve the Word32 → Customer
conversion directly in the Cardano.Wallet.Deposit.HTTP.JSON.JSONSpec
module? 🤓
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.
got it - reverted the commit
|
||
prop_jsonRoundtrip :: (Eq a, Show a, FromJSON a, ToJSON a) => a -> Property | ||
prop_jsonRoundtrip val = | ||
decode (encode val) === Just val |
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.
👍 😊
|
||
instance Arbitrary (ApiT Customer) where | ||
arbitrary = | ||
ApiT . fromRawCustomer <$> arbitrary |
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.
ApiT . fromRawCustomer <$> arbitrary | |
ApiT <$> chooseBoundedIntegral |
🤓 On the matter of the Word32 → Customer
conversion: Somewhat unusually, I have chose to make Customer
a concrete type rather than an abstract data type — specifically, I have defined Customer = Word31
. In other words, the deposit wallet will only support customer IDs in the range 0 … 2^31-1
!
This is intentional, and due to the BIP-32 address derivation, where the index for one derivation step is exactly a Word31
. I could have used longer indices, but I decided to keep this limit for compatibility with hardware wallets; I don't want to explain derivations with arbitrary length. Hence, Customer = Word31
is baked into the Deposit Wallet.
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.
introduced fromRawCustomer
that creates Customer
from Word31
and added Arbitrary Word31
.
listLen <- chooseInt (0, 100) | ||
let genPair = (,) <$> (unApiT <$> arbitrary) <*> (unApiT <$> arbitrary) | ||
ApiT <$> vectorOf listLen genPair |
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.
listLen <- chooseInt (0, 100) | |
let genPair = (,) <$> (unApiT <$> arbitrary) <*> (unApiT <$> arbitrary) | |
ApiT <$> vectorOf listLen genPair | |
let genPair = (,) <$> (unApiT <$> arbitrary) <*> (unApiT <$> arbitrary) | |
ApiT <$> listOf genPair |
Perhaps? listOf
depends on the QuickCheck size
parameter, which usually composes better. But since we don't care about composability here, vectorOf
is also fine. I leave this up to you.
bffed90
to
d72ceda
Compare
d72ceda
to
959531b
Compare
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.
Excellent, thank you! 😊
Minor request on the definition of fromRawCustomer
remaining.
(Also, could you squash the commits a little bit? I.e. work post revert changes
into the earlier commits.)
@@ -135,6 +136,9 @@ isCustomerAddress :: Address -> WalletState -> Bool | |||
isCustomerAddress address = | |||
flip Address.isCustomerAddress (Read.toRawAddress address) . addresses | |||
|
|||
fromRawCustomer :: Word31 -> Customer | |||
fromRawCustomer = fromIntegral |
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.
fromRawCustomer = fromIntegral | |
fromRawCustomer = id |
As much as I love abstract data types — this one is positively a type synonym. 🤓
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.
indeed! done
Customer
type relocationApiT Address
ApiT Customer
ApiT CustomerList
Comments
Issue Number
adp-3372