@@ -46,6 +46,7 @@ module Cardano.Wallet.API.V1.Types (
46
46
, NewExternalWallet (.. )
47
47
, WalletAndTxHistory (.. )
48
48
-- * Addresses
49
+ , AddressOwnership (.. )
49
50
, AddressIndex
50
51
, AddressValidity (.. )
51
52
, AddressAsBase58
@@ -183,7 +184,7 @@ import Cardano.Wallet.API.V1.Swagger.Example (Example, example,
183
184
genExample )
184
185
import Cardano.Wallet.Orphans.Aeson ()
185
186
import Cardano.Wallet.Types.UtxoStatistics
186
- import Cardano.Wallet.Util (showApiUtcTime )
187
+ import Cardano.Wallet.Util (mkJsonKey , showApiUtcTime )
187
188
188
189
import qualified Pos.Binary.Class as Bi
189
190
import qualified Pos.Chain.Txp as Txp
@@ -265,6 +266,11 @@ genericSchemaDroppingPrefix prfx extraDoc proxy = do
265
266
_ -> err
266
267
267
268
269
+ optsADTCamelCase :: A. Options
270
+ optsADTCamelCase =
271
+ defaultOptions { A. constructorTagModifier = mkJsonKey }
272
+
273
+
268
274
--
269
275
-- Versioning
270
276
--
@@ -1202,6 +1208,35 @@ instance BuildableSafeGen AddressValidity where
1202
1208
buildSafeGen _ AddressValidity {.. } =
1203
1209
bprint (" { valid=" % build% " }" ) isValid
1204
1210
1211
+ -- | An address is either recognised as "ours" or not. An address that is not
1212
+ -- recognised may still be ours e.g. an address generated by another wallet instance
1213
+ -- will not be considered "ours" until the relevant transaction is confirmed.
1214
+ --
1215
+ -- In other words, `AddressAmbiguousOwnership` makes an inconclusive statement about
1216
+ -- an address, whereas `AddressOwnership` is unambiguous.
1217
+ data AddressOwnership
1218
+ = AddressIsOurs
1219
+ | AddressAmbiguousOwnership
1220
+ deriving (Show , Eq , Generic , Ord )
1221
+
1222
+ instance ToJSON (V1 AddressOwnership ) where
1223
+ toJSON = genericToJSON optsADTCamelCase . unV1
1224
+
1225
+ instance FromJSON (V1 AddressOwnership ) where
1226
+ parseJSON = fmap V1 . genericParseJSON optsADTCamelCase
1227
+
1228
+ instance ToSchema (V1 AddressOwnership ) where
1229
+ declareNamedSchema _ =
1230
+ pure $ NamedSchema (Just " V1AddressOwnership" ) $ mempty
1231
+ & type_ .~ SwaggerString
1232
+ & enum_ ?~ [" isOurs" , " ambiguousOwnership" ]
1233
+
1234
+ instance Arbitrary (V1 AddressOwnership ) where
1235
+ arbitrary = fmap V1 $ oneof
1236
+ [ pure AddressIsOurs
1237
+ , pure AddressAmbiguousOwnership
1238
+ ]
1239
+
1205
1240
--------------------------------------------------------------------------------
1206
1241
-- Accounts
1207
1242
--------------------------------------------------------------------------------
@@ -1211,6 +1246,7 @@ data WalletAddress = WalletAddress
1211
1246
{ addrId :: ! (V1 Core. Address )
1212
1247
, addrUsed :: ! Bool
1213
1248
, addrChangeAddress :: ! Bool
1249
+ , addrOwnership :: ! (V1 AddressOwnership )
1214
1250
} deriving (Show , Eq , Generic , Ord )
1215
1251
1216
1252
deriveJSON Serokell. defaultOptions ''WalletAddress
@@ -1221,12 +1257,14 @@ instance ToSchema WalletAddress where
1221
1257
& (" id" --^ " Actual address." )
1222
1258
& (" used" --^ " True if this address has been used." )
1223
1259
& (" changeAddress" --^ " True if this address stores change from a previous transaction." )
1260
+ & (" ownership" --^ " 'isOurs' if this address is recognised as ours, 'ambiguousOwnership' if the node doesn't have information to make a unambiguous statement." )
1224
1261
)
1225
1262
1226
1263
instance Arbitrary WalletAddress where
1227
1264
arbitrary = WalletAddress <$> arbitrary
1228
1265
<*> arbitrary
1229
1266
<*> arbitrary
1267
+ <*> arbitrary
1230
1268
1231
1269
newtype AccountIndex = AccountIndex { getAccIndex :: Word32 }
1232
1270
deriving (Show , Eq , Ord , Generic )
0 commit comments