mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-10 10:46:11 +03:00
hlb, reformat all the types (#2369)
This commit is contained in:
parent
8625d2e81b
commit
1c12354f38
@ -6,92 +6,95 @@
|
|||||||
-- These types offer the following benefits over the LowLevel types
|
-- These types offer the following benefits over the LowLevel types
|
||||||
--
|
--
|
||||||
-- (1) These types are human curated and intended for human consumption.
|
-- (1) These types are human curated and intended for human consumption.
|
||||||
-- (The lowlevel types are generated by compile-proto, and have verbose record-field and constructor names.)
|
-- (The lowlevel types are generated by compile-proto,
|
||||||
-- (2) These types are stronger: distinguishing various identifier classes, instead of everywhere being `Text`.
|
-- and have verbose record-field and constructor names.)
|
||||||
|
-- (2) These types are stronger:
|
||||||
|
-- distinguishing various identifier classes, instead of everywhere being `Text`.
|
||||||
-- (3) These types capture required-field invariants.
|
-- (3) These types capture required-field invariants.
|
||||||
-- (4) These types form a barrier against changes to names & representation in the .proto files.
|
-- (4) These types form a barrier against changes to names & representation in the .proto files.
|
||||||
|
|
||||||
module DA.Ledger.Types( -- High Level types for communication over Ledger API
|
module DA.Ledger.Types( -- High Level types for communication over Ledger API
|
||||||
|
|
||||||
Commands(..),
|
AbsOffset(..),
|
||||||
Command(..),
|
|
||||||
LedgerOffset(..),
|
|
||||||
Completion(..),
|
|
||||||
Checkpoint(..),
|
Checkpoint(..),
|
||||||
Transaction(..),
|
Choice(..),
|
||||||
|
Command(..),
|
||||||
|
Commands(..),
|
||||||
|
Completion(..),
|
||||||
|
EntityName(..),
|
||||||
|
Enum(..),
|
||||||
Event(..),
|
Event(..),
|
||||||
|
Identifier(..),
|
||||||
|
LedgerConfiguration(..),
|
||||||
|
LedgerOffset(..),
|
||||||
|
ModuleName(..),
|
||||||
|
Party(..),
|
||||||
|
Record(..),
|
||||||
|
RecordField(..),
|
||||||
|
Timestamp(..),
|
||||||
|
Transaction(..),
|
||||||
TransactionTree(..),
|
TransactionTree(..),
|
||||||
TreeEvent(..),
|
TreeEvent(..),
|
||||||
Value(..),
|
Value(..),
|
||||||
Record(..),
|
|
||||||
RecordField(..),
|
|
||||||
Variant(..),
|
Variant(..),
|
||||||
Enum(..),
|
Verbosity(..),
|
||||||
Identifier(..),
|
|
||||||
Timestamp(..),
|
|
||||||
|
|
||||||
MicroSecondsSinceEpoch(..),
|
MicroSecondsSinceEpoch(..),
|
||||||
DaysSinceEpoch(..),
|
DaysSinceEpoch(..),
|
||||||
TemplateId(..),
|
|
||||||
LedgerId(..),
|
|
||||||
TransactionId(..),
|
|
||||||
EventId(..),
|
|
||||||
ContractId(..),
|
|
||||||
WorkflowId(..),
|
|
||||||
ApplicationId(..),
|
ApplicationId(..),
|
||||||
CommandId(..),
|
CommandId(..),
|
||||||
PackageId(..),
|
|
||||||
ConstructorId(..),
|
ConstructorId(..),
|
||||||
Choice(..),
|
ContractId(..),
|
||||||
Party(..),
|
EventId(..),
|
||||||
ModuleName(..),
|
LedgerId(..),
|
||||||
EntityName(..),
|
PackageId(..),
|
||||||
AbsOffset(..),
|
TemplateId(..),
|
||||||
Verbosity(..),
|
TransactionId(..),
|
||||||
|
WorkflowId(..),
|
||||||
LedgerConfiguration(..),
|
|
||||||
|
|
||||||
LL.Duration(..),
|
LL.Duration(..),
|
||||||
LL.Status(..),
|
LL.Status(..),
|
||||||
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Prelude hiding(Enum)
|
|
||||||
import Data.Map (Map)
|
import Data.Map (Map)
|
||||||
import Data.Text.Lazy (Text)
|
import Data.Text.Lazy (Text)
|
||||||
|
import Prelude hiding(Enum)
|
||||||
import qualified Data.Text.Lazy as Text(unpack)
|
import qualified Data.Text.Lazy as Text(unpack)
|
||||||
|
|
||||||
import qualified Google.Protobuf.Duration as LL
|
import qualified Google.Protobuf.Duration as LL
|
||||||
import qualified Google.Rpc.Status as LL
|
import qualified Google.Rpc.Status as LL
|
||||||
|
|
||||||
-- commands.proto
|
-- commands.proto
|
||||||
|
|
||||||
data Commands = Commands {
|
data Commands = Commands
|
||||||
lid :: LedgerId,
|
{ lid :: LedgerId
|
||||||
wid :: Maybe WorkflowId,
|
, wid :: Maybe WorkflowId
|
||||||
aid :: ApplicationId,
|
, aid :: ApplicationId
|
||||||
cid :: CommandId,
|
, cid :: CommandId
|
||||||
party :: Party,
|
, party :: Party
|
||||||
leTime :: Timestamp,
|
, leTime :: Timestamp
|
||||||
mrTime :: Timestamp,
|
, mrTime :: Timestamp
|
||||||
coms :: [Command] }
|
, coms :: [Command]
|
||||||
|
}
|
||||||
|
|
||||||
data Command
|
data Command
|
||||||
= CreateCommand {
|
= CreateCommand
|
||||||
tid :: TemplateId,
|
{ tid :: TemplateId
|
||||||
args :: Record }
|
, args :: Record
|
||||||
|
}
|
||||||
| ExerciseCommand {
|
| ExerciseCommand
|
||||||
tid :: TemplateId,
|
{ tid :: TemplateId
|
||||||
cid :: ContractId,
|
, cid :: ContractId
|
||||||
choice :: Choice,
|
, choice :: Choice
|
||||||
arg :: Value }
|
, arg :: Value
|
||||||
|
}
|
||||||
| CreateAndExerciseCommand {
|
| CreateAndExerciseCommand
|
||||||
tid :: TemplateId,
|
{ tid :: TemplateId
|
||||||
createArgs :: Record,
|
, createArgs :: Record
|
||||||
choice :: Choice,
|
, choice :: Choice
|
||||||
choiceArg :: Value }
|
, choiceArg :: Value
|
||||||
|
}
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
-- ledger_offset.proto
|
-- ledger_offset.proto
|
||||||
@ -101,83 +104,84 @@ data LedgerOffset = LedgerBegin | LedgerEnd | LedgerAbsOffset AbsOffset
|
|||||||
|
|
||||||
-- completion.proto
|
-- completion.proto
|
||||||
|
|
||||||
data Completion
|
data Completion = Completion
|
||||||
= Completion {
|
{ cid :: CommandId
|
||||||
cid :: CommandId,
|
, status :: Maybe LL.Status
|
||||||
status :: Maybe LL.Status }
|
}
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
data Checkpoint
|
data Checkpoint = Checkpoint -- TODO: add time info
|
||||||
= Checkpoint {
|
{ offset :: AbsOffset
|
||||||
-- TODO: add time info
|
|
||||||
offset :: AbsOffset
|
|
||||||
}
|
}
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
-- transaction.proto
|
-- transaction.proto
|
||||||
|
|
||||||
data Transaction
|
data Transaction = Transaction
|
||||||
= Transaction {
|
{ trid :: TransactionId
|
||||||
trid :: TransactionId,
|
, cid :: Maybe CommandId
|
||||||
cid :: Maybe CommandId,
|
, wid :: Maybe WorkflowId
|
||||||
wid :: Maybe WorkflowId,
|
, leTime :: Timestamp
|
||||||
leTime :: Timestamp,
|
, events :: [Event]
|
||||||
events :: [Event],
|
, offset :: AbsOffset
|
||||||
offset :: AbsOffset } deriving (Eq,Ord,Show)
|
}
|
||||||
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
data TransactionTree
|
data TransactionTree = TransactionTree
|
||||||
= TransactionTree {
|
{ trid :: TransactionId
|
||||||
trid :: TransactionId,
|
, cid :: Maybe CommandId
|
||||||
cid :: Maybe CommandId,
|
, wid :: Maybe WorkflowId
|
||||||
wid :: Maybe WorkflowId,
|
, leTime :: Timestamp
|
||||||
leTime :: Timestamp,
|
, offset :: AbsOffset
|
||||||
offset :: AbsOffset,
|
, events :: Map EventId TreeEvent
|
||||||
events :: Map EventId TreeEvent,
|
, roots :: [EventId]
|
||||||
roots :: [EventId]
|
}
|
||||||
} deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
data TreeEvent
|
data TreeEvent
|
||||||
= CreatedTreeEvent { -- TODO: dedup TreeEvent / Event ! ?
|
= CreatedTreeEvent -- TODO: dedup TreeEvent / Event ! ?
|
||||||
eid :: EventId,
|
{ eid :: EventId
|
||||||
cid :: ContractId,
|
, cid :: ContractId
|
||||||
tid :: TemplateId,
|
, tid :: TemplateId
|
||||||
createArgs :: Record,
|
, createArgs :: Record
|
||||||
witness :: [Party],
|
, witness :: [Party]
|
||||||
key :: Maybe Value,
|
, key :: Maybe Value
|
||||||
signatories :: [Party],
|
, signatories :: [Party]
|
||||||
observers :: [Party] }
|
, observers :: [Party]
|
||||||
|
}
|
||||||
| ExercisedTreeEvent {
|
| ExercisedTreeEvent
|
||||||
eid :: EventId,
|
{ eid :: EventId
|
||||||
cid :: ContractId,
|
, cid :: ContractId
|
||||||
tid :: TemplateId,
|
, tid :: TemplateId
|
||||||
choice :: Choice,
|
, choice :: Choice
|
||||||
choiceArg :: Value,
|
, choiceArg :: Value
|
||||||
acting :: [Party],
|
, acting :: [Party]
|
||||||
consuming :: Bool,
|
, consuming :: Bool
|
||||||
witness :: [Party],
|
, witness :: [Party]
|
||||||
childEids :: [EventId],
|
, childEids :: [EventId]
|
||||||
result :: Value}
|
, result :: Value
|
||||||
|
}
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
-- event.proto
|
-- event.proto
|
||||||
|
|
||||||
data Event
|
data Event
|
||||||
= CreatedEvent {
|
= CreatedEvent
|
||||||
eid :: EventId,
|
{ eid :: EventId
|
||||||
cid :: ContractId,
|
, cid :: ContractId
|
||||||
tid :: TemplateId,
|
, tid :: TemplateId
|
||||||
createArgs :: Record,
|
, createArgs :: Record
|
||||||
witness :: [Party],
|
, witness :: [Party]
|
||||||
key :: Maybe Value,
|
, key :: Maybe Value
|
||||||
signatories :: [Party],
|
, signatories :: [Party]
|
||||||
observers :: [Party] }
|
, observers :: [Party]
|
||||||
|
}
|
||||||
| ArchivedEvent {
|
| ArchivedEvent
|
||||||
eid :: EventId,
|
{ eid :: EventId
|
||||||
cid :: ContractId,
|
, cid :: ContractId
|
||||||
tid :: TemplateId,
|
, tid :: TemplateId
|
||||||
witness :: [Party] }
|
, witness :: [Party]
|
||||||
|
}
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
-- value.proto
|
-- value.proto
|
||||||
@ -203,70 +207,72 @@ data Value
|
|||||||
data Enum = Enum
|
data Enum = Enum
|
||||||
{ eid :: Maybe Identifier
|
{ eid :: Maybe Identifier
|
||||||
, cons :: ConstructorId
|
, cons :: ConstructorId
|
||||||
} deriving (Eq,Ord,Show)
|
}
|
||||||
|
|
||||||
data Record
|
|
||||||
= Record {
|
|
||||||
rid :: Maybe Identifier,
|
|
||||||
fields :: [RecordField] } deriving (Eq,Ord,Show)
|
|
||||||
|
|
||||||
data RecordField
|
|
||||||
= RecordField {
|
|
||||||
label :: Text,
|
|
||||||
fieldValue :: Value } deriving (Eq,Ord,Show)
|
|
||||||
|
|
||||||
data Variant
|
|
||||||
= Variant {
|
|
||||||
vid :: Maybe Identifier,
|
|
||||||
cons :: ConstructorId,
|
|
||||||
value :: Value } deriving (Eq,Ord,Show)
|
|
||||||
|
|
||||||
data Identifier
|
|
||||||
= Identifier {
|
|
||||||
pid :: PackageId,
|
|
||||||
mod :: ModuleName,
|
|
||||||
ent :: EntityName } deriving (Eq,Ord,Show)
|
|
||||||
|
|
||||||
newtype MicroSecondsSinceEpoch =
|
|
||||||
MicroSecondsSinceEpoch { unMicroSecondsSinceEpoch :: Int }
|
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
newtype DaysSinceEpoch =
|
data Record = Record
|
||||||
DaysSinceEpoch { unDaysSinceEpoch :: Int }
|
{ rid :: Maybe Identifier
|
||||||
|
, fields :: [RecordField]
|
||||||
|
}
|
||||||
deriving (Eq,Ord,Show)
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
data Timestamp
|
data RecordField = RecordField
|
||||||
= Timestamp {
|
{ label :: Text
|
||||||
seconds :: Int,
|
, fieldValue :: Value
|
||||||
nanos :: Int } deriving (Eq,Ord,Show)
|
}
|
||||||
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
|
data Variant = Variant
|
||||||
|
{ vid :: Maybe Identifier
|
||||||
|
, cons :: ConstructorId
|
||||||
|
, value :: Value
|
||||||
|
}
|
||||||
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
|
data Identifier = Identifier
|
||||||
|
{ pid :: PackageId
|
||||||
|
, mod :: ModuleName
|
||||||
|
, ent :: EntityName
|
||||||
|
}
|
||||||
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
|
data Timestamp = Timestamp
|
||||||
|
{ seconds :: Int
|
||||||
|
, nanos :: Int
|
||||||
|
}
|
||||||
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
|
data LedgerConfiguration = LedgerConfiguration
|
||||||
|
{ minTtl :: LL.Duration
|
||||||
|
, maxTtl :: LL.Duration
|
||||||
|
}
|
||||||
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
|
newtype MicroSecondsSinceEpoch = MicroSecondsSinceEpoch { unMicroSecondsSinceEpoch :: Int}
|
||||||
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
|
newtype DaysSinceEpoch = DaysSinceEpoch { unDaysSinceEpoch :: Int}
|
||||||
|
deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
newtype TemplateId = TemplateId Identifier deriving (Eq,Ord,Show)
|
newtype TemplateId = TemplateId Identifier deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
newtype LedgerId = LedgerId { unLedgerId :: Text } deriving (Eq,Ord,Show)
|
|
||||||
newtype TransactionId = TransactionId { unTransactionId :: Text } deriving (Eq,Ord,Show)
|
|
||||||
newtype EventId = EventId { unEventId :: Text } deriving (Eq,Ord,Show)
|
|
||||||
newtype ContractId = ContractId { unContractId :: Text } deriving (Eq,Ord,Show)
|
|
||||||
newtype WorkflowId = WorkflowId { unWorkflowId :: Text } deriving (Eq,Ord,Show)
|
|
||||||
newtype ApplicationId = ApplicationId { unApplicationId :: Text } deriving (Eq,Ord,Show)
|
newtype ApplicationId = ApplicationId { unApplicationId :: Text } deriving (Eq,Ord,Show)
|
||||||
newtype CommandId = CommandId { unCommandId :: Text } deriving (Eq,Ord,Show)
|
newtype CommandId = CommandId { unCommandId :: Text } deriving (Eq,Ord,Show)
|
||||||
newtype PackageId = PackageId { unPackageId :: Text } deriving (Eq,Ord,Show)
|
|
||||||
newtype ConstructorId = ConstructorId { unConstructorId :: Text } deriving (Eq,Ord,Show)
|
newtype ConstructorId = ConstructorId { unConstructorId :: Text } deriving (Eq,Ord,Show)
|
||||||
|
newtype ContractId = ContractId { unContractId :: Text } deriving (Eq,Ord,Show)
|
||||||
|
newtype EventId = EventId { unEventId :: Text } deriving (Eq,Ord,Show)
|
||||||
|
newtype LedgerId = LedgerId { unLedgerId :: Text } deriving (Eq,Ord,Show)
|
||||||
|
newtype PackageId = PackageId { unPackageId :: Text } deriving (Eq,Ord,Show)
|
||||||
|
newtype TransactionId = TransactionId { unTransactionId :: Text } deriving (Eq,Ord,Show)
|
||||||
|
newtype WorkflowId = WorkflowId { unWorkflowId :: Text } deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
|
newtype ModuleName = ModuleName { unModuleName :: Text } deriving (Eq,Ord,Show)
|
||||||
|
newtype EntityName = EntityName { unEntityName :: Text } deriving (Eq,Ord,Show)
|
||||||
|
newtype AbsOffset = AbsOffset { unAbsOffset :: Text } deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
newtype Choice = Choice { unChoice :: Text } deriving (Eq,Ord,Show)
|
newtype Choice = Choice { unChoice :: Text } deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
newtype Party = Party { unParty :: Text } deriving (Eq,Ord)
|
newtype Party = Party { unParty :: Text } deriving (Eq,Ord)
|
||||||
instance Show Party where show = Text.unpack . unParty
|
instance Show Party where show = Text.unpack . unParty
|
||||||
|
|
||||||
newtype ModuleName = ModuleName { unModuleName :: Text } deriving (Eq,Ord,Show)
|
|
||||||
newtype EntityName = EntityName { unEntityName :: Text } deriving (Eq,Ord,Show)
|
|
||||||
|
|
||||||
newtype AbsOffset = AbsOffset { unAbsOffset :: Text } deriving (Eq,Ord,Show)
|
|
||||||
|
|
||||||
newtype Verbosity = Verbosity { unVerbosity :: Bool } deriving (Eq,Ord,Show)
|
newtype Verbosity = Verbosity { unVerbosity :: Bool } deriving (Eq,Ord,Show)
|
||||||
|
|
||||||
data LedgerConfiguration = LedgerConfiguration
|
|
||||||
{ minTtl :: Duration
|
|
||||||
, maxTtl :: Duration
|
|
||||||
} deriving (Eq,Ord,Show)
|
|
||||||
|
|
||||||
type Duration = LL.Duration
|
|
||||||
|
Loading…
Reference in New Issue
Block a user