-
Notifications
You must be signed in to change notification settings - Fork 631
[CBR-401] For the validate-address API endpoint, add an IsOurs field … #3646
Changes from all 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 |
---|---|---|
|
@@ -46,6 +46,7 @@ module Cardano.Wallet.API.V1.Types ( | |
, NewExternalWallet (..) | ||
, WalletAndTxHistory (..) | ||
-- * Addresses | ||
, AddressOwnership (..) | ||
, AddressIndex | ||
, AddressValidity (..) | ||
, AddressAsBase58 | ||
|
@@ -183,7 +184,7 @@ import Cardano.Wallet.API.V1.Swagger.Example (Example, example, | |
genExample) | ||
import Cardano.Wallet.Orphans.Aeson () | ||
import Cardano.Wallet.Types.UtxoStatistics | ||
import Cardano.Wallet.Util (showApiUtcTime) | ||
import Cardano.Wallet.Util (mkJsonKey, showApiUtcTime) | ||
|
||
import qualified Pos.Binary.Class as Bi | ||
import qualified Pos.Chain.Txp as Txp | ||
|
@@ -265,6 +266,11 @@ genericSchemaDroppingPrefix prfx extraDoc proxy = do | |
_ -> err | ||
|
||
|
||
optsADTCamelCase :: A.Options | ||
optsADTCamelCase = | ||
defaultOptions { A.constructorTagModifier = mkJsonKey } | ||
|
||
|
||
-- | ||
-- Versioning | ||
-- | ||
|
@@ -1202,6 +1208,35 @@ instance BuildableSafeGen AddressValidity where | |
buildSafeGen _ AddressValidity{..} = | ||
bprint ("{ valid="%build%" }") isValid | ||
|
||
-- | An address is either recognised as "ours" or not. An address that is not | ||
-- recognised may still be ours e.g. an address generated by another wallet instance | ||
-- will not be considered "ours" until the relevant transaction is confirmed. | ||
-- | ||
-- In other words, `AddressAmbiguousOwnership` makes an inconclusive statement about | ||
-- an address, whereas `AddressOwnership` is unambiguous. | ||
data AddressOwnership | ||
= AddressIsOurs | ||
| AddressAmbiguousOwnership | ||
deriving (Show, Eq, Generic, Ord) | ||
|
||
instance ToJSON (V1 AddressOwnership) where | ||
toJSON = genericToJSON optsADTCamelCase . unV1 | ||
|
||
instance FromJSON (V1 AddressOwnership) where | ||
parseJSON = fmap V1 . genericParseJSON optsADTCamelCase | ||
|
||
instance ToSchema (V1 AddressOwnership) where | ||
declareNamedSchema _ = | ||
pure $ NamedSchema (Just "V1AddressOwnership") $ mempty | ||
& type_ .~ SwaggerString | ||
& enum_ ?~ ["isOurs", "ambiguousOwnership"] | ||
|
||
instance Arbitrary (V1 AddressOwnership) where | ||
arbitrary = fmap V1 $ oneof | ||
[ pure AddressIsOurs | ||
, pure AddressAmbiguousOwnership | ||
] | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Accounts | ||
-------------------------------------------------------------------------------- | ||
|
@@ -1211,6 +1246,7 @@ data WalletAddress = WalletAddress | |
{ addrId :: !(V1 Core.Address) | ||
, addrUsed :: !Bool | ||
, addrChangeAddress :: !Bool | ||
, addrOwnership :: !(V1 AddressOwnership) | ||
} deriving (Show, Eq, Generic, Ord) | ||
|
||
deriveJSON Serokell.defaultOptions ''WalletAddress | ||
|
@@ -1221,12 +1257,14 @@ instance ToSchema WalletAddress where | |
& ("id" --^ "Actual address.") | ||
& ("used" --^ "True if this address has been used.") | ||
& ("changeAddress" --^ "True if this address stores change from a previous transaction.") | ||
& ("ownership" --^ "'isOurs' if this address is recognised as ours, 'ambiguousOwnership' if the node doesn't have information to make a unambiguous statement.") | ||
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. to make an unambiguous statement? 🤔 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. Oui 🇫🇷 |
||
) | ||
|
||
instance Arbitrary WalletAddress where | ||
arbitrary = WalletAddress <$> arbitrary | ||
<*> arbitrary | ||
<*> arbitrary | ||
<*> arbitrary | ||
|
||
newtype AccountIndex = AccountIndex { getAccIndex :: Word32 } | ||
deriving (Show, Eq, Ord, Generic) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ headToLower [] = Nothing | |
headToLower (x:xs) = Just $ toLower x : xs | ||
|
||
stripFieldPrefix :: String -> String | ||
stripFieldPrefix = dropWhile (not . isUpper) | ||
stripFieldPrefix = dropWhile (not . isUpper) . drop 1 | ||
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. NOTE: I took some freedom in adjusting the way I think it should work. It was dead-code until now though, not used anywhere, so this change is free of any impact 👍 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. Was just going to ask, cheers for clarifying 😁 |
||
|
||
mkJsonKey :: String -> String | ||
mkJsonKey s = fromMaybe s . headToLower $ stripFieldPrefix s | ||
|
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.
Noice 👍