Skip to content

Commit

Permalink
API: Rename ttl -> timeToLive, use Quantity "second" newtype
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Oct 19, 2020
1 parent 731ad13 commit 77c03de
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
Expand Up @@ -2617,7 +2617,8 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do

addTxTTL :: Double -> Payload -> Payload
addTxTTL t (Json (Aeson.Object o)) = Json (Aeson.Object (o <> ttl))
where ttl = "ttl" .= Aeson.Object ("seconds" .= t)
where
ttl = "time_to_live" .= [json|{ "quantity": #{t}, "unit": "second"}|]
addTxTTL _ _ = error "can't do that"

addTxMetadata :: Aeson.Value -> Payload -> Payload
Expand Down
14 changes: 2 additions & 12 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Expand Up @@ -65,7 +65,6 @@ module Cardano.Wallet.Api.Types
, PostTransactionFeeData (..)
, PostExternalTransactionData (..)
, ApiTransaction (..)
, ApiTransactionTTL (..)
, ApiWithdrawalPostData (..)
, ApiFee (..)
, ApiTxId (..)
Expand Down Expand Up @@ -557,23 +556,19 @@ data ByronWalletPutPassphraseData = ByronWalletPutPassphraseData
, newPassphrase :: !(ApiT (Passphrase "raw"))
} deriving (Eq, Generic, Show)

newtype ApiTransactionTTL = ApiTransactionTTL
{ seconds :: NominalDiffTime
} deriving (Eq, Generic, Show)

data PostTransactionData (n :: NetworkDiscriminant) = PostTransactionData
{ payments :: !(NonEmpty (AddressAmount (ApiT Address, Proxy n)))
, passphrase :: !(ApiT (Passphrase "lenient"))
, withdrawal :: !(Maybe ApiWithdrawalPostData)
, metadata :: !(Maybe (ApiT TxMetadata))
, ttl :: !(Maybe ApiTransactionTTL)
, timeToLive :: !(Maybe (Quantity "second" NominalDiffTime))
} deriving (Eq, Generic, Show)

data PostTransactionFeeData (n :: NetworkDiscriminant) = PostTransactionFeeData
{ payments :: (NonEmpty (AddressAmount (ApiT Address, Proxy n)))
, withdrawal :: !(Maybe ApiWithdrawalPostData)
, metadata :: !(Maybe (ApiT TxMetadata))
, ttl :: !(Maybe ApiTransactionTTL)
, timeToLive :: !(Maybe (Quantity "second" NominalDiffTime))
} deriving (Eq, Generic, Show)

newtype PostExternalTransactionData = PostExternalTransactionData
Expand Down Expand Up @@ -1483,11 +1478,6 @@ instance ToJSON ApiTxMetadata where
Just (ApiT md) | txMetadataIsNull md -> Aeson.Null
Just md -> toJSON md

instance FromJSON ApiTransactionTTL where
parseJSON = genericParseJSON defaultRecordTypeOptions
instance ToJSON ApiTransactionTTL where
toJSON = genericToJSON defaultRecordTypeOptions

instance (DecodeAddress n , PassphraseMaxLength s , PassphraseMinLength s) => FromJSON (ApiWalletMigrationPostData n s)
where
parseJSON = genericParseJSON defaultRecordTypeOptions
Expand Down
2 changes: 2 additions & 0 deletions lib/core/src/Cardano/Wallet/Primitive/Types.hs
Expand Up @@ -933,6 +933,8 @@ data TxMeta = TxMeta
, blockHeight :: !(Quantity "block" Word32)
, amount :: !(Quantity "lovelace" Natural)
, expiry :: !(Maybe SlotNo)
-- ^ The slot at which a pending transaction will no longer be accepted
-- into mempools.
} deriving (Show, Eq, Ord, Generic)

instance NFData TxMeta
Expand Down
8 changes: 2 additions & 6 deletions lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Expand Up @@ -69,7 +69,6 @@ import Cardano.Wallet.Api.Types
, ApiStakePoolMetrics (..)
, ApiT (..)
, ApiTransaction (..)
, ApiTransactionTTL (..)
, ApiTxId (..)
, ApiTxInput (..)
, ApiTxMetadata (..)
Expand Down Expand Up @@ -763,7 +762,7 @@ spec = do
, passphrase = passphrase (x :: PostTransactionData ('Testnet 0))
, withdrawal = withdrawal (x :: PostTransactionData ('Testnet 0))
, metadata = metadata (x :: PostTransactionData ('Testnet 0))
, ttl = ttl (x :: PostTransactionData ('Testnet 0))
, timeToLive = timeToLive (x :: PostTransactionData ('Testnet 0))
}
in
x' === x .&&. show x' === show x
Expand All @@ -773,7 +772,7 @@ spec = do
{ payments = payments (x :: PostTransactionFeeData ('Testnet 0))
, withdrawal = withdrawal (x :: PostTransactionFeeData ('Testnet 0))
, metadata = metadata (x :: PostTransactionFeeData ('Testnet 0))
, ttl = ttl (x :: PostTransactionFeeData ('Testnet 0))
, timeToLive = timeToLive (x :: PostTransactionFeeData ('Testnet 0))
}
in
x' === x .&&. show x' === show x
Expand Down Expand Up @@ -1364,9 +1363,6 @@ instance Arbitrary a => Arbitrary (AddressAmount a) where
arbitrary = applyArbitrary2 AddressAmount
shrink _ = []

instance Arbitrary ApiTransactionTTL where
arbitrary = ApiTransactionTTL . fromIntegral @Int <$> choose (0, 10000)

instance Arbitrary (PostTransactionData t) where
arbitrary = PostTransactionData
<$> arbitrary
Expand Down

0 comments on commit 77c03de

Please sign in to comment.