Skip to content

Commit

Permalink
Add tx expiry slot to db layer
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Aug 5, 2020
1 parent 23642e5 commit 8e5767e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/core/src/Cardano/Wallet/DB/Sqlite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ mkTxMetaEntity wid txid meta = TxMeta
, txMetaSlot = meta ^. #slotNo
, txMetaBlockHeight = getQuantity (meta ^. #blockHeight)
, txMetaAmount = getQuantity (meta ^. #amount)
, txMetaSlotExpires = meta ^. #expiry
}

-- note: TxIn records must already be sorted by order
Expand Down Expand Up @@ -1123,6 +1124,7 @@ txHistoryFromEntity ti tip metas ins outs ws =
, W.slotNo = txMetaSlot m
, W.blockHeight = Quantity (txMetaBlockHeight m)
, W.amount = Quantity (txMetaAmount m)
, W.expiry = txMetaSlotExpires m
}

mkProtocolParametersEntity
Expand Down
19 changes: 12 additions & 7 deletions lib/core/src/Cardano/Wallet/DB/Sqlite/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,19 @@ PrivateKey sql=private_key
-- TxMeta is specific to a wallet because multiple wallets may have the same
-- transaction with different metadata values. The associated inputs and outputs
-- of the transaction are in the TxIn and TxOut tables.
--
-- Transactions with status=Pending have an expiry slot.
-- If not accepted on the chain before the expiry slot they
-- will be removed from the pending set and get status=Expired.
TxMeta
txMetaTxId TxId sql=tx_id
txMetaWalletId W.WalletId sql=wallet_id
txMetaStatus W.TxStatus sql=status
txMetaDirection W.Direction sql=direction
txMetaSlot SlotNo sql=slot
txMetaBlockHeight Word32 sql=block_height
txMetaAmount Natural sql=amount
txMetaTxId TxId sql=tx_id
txMetaWalletId W.WalletId sql=wallet_id
txMetaStatus W.TxStatus sql=status
txMetaDirection W.Direction sql=direction
txMetaSlot SlotNo sql=slot
txMetaBlockHeight Word32 sql=block_height
txMetaAmount Natural sql=amount
txMetaSlotExpires SlotNo Maybe sql=slot_expires

Primary txMetaTxId txMetaWalletId
Foreign Wallet fk_wallet_tx_meta txMetaWalletId ! ON DELETE CASCADE
Expand Down
3 changes: 2 additions & 1 deletion lib/core/src/Cardano/Wallet/Primitive/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ instance Buildable TxMeta where
data TxStatus
= Pending
| InLedger
| Expired
deriving (Show, Eq, Ord, Bounded, Enum, Generic)

instance NFData TxStatus
Expand Down Expand Up @@ -941,7 +942,7 @@ newtype SealedTx = SealedTx { getSealedTx :: ByteString }
deriving stock (Show, Eq, Generic)
deriving newtype (ByteArrayAccess)

-- | True if the given tuple refers to a pending transaction
-- | True if the given metadata refers to a pending transaction
isPending :: TxMeta -> Bool
isPending = (== Pending) . (status :: TxMeta -> TxStatus)

Expand Down

0 comments on commit 8e5767e

Please sign in to comment.