hlb, reformat all the types (#2369)

This commit is contained in:
nickchapman-da 2019-08-01 22:24:28 +01:00 committed by GitHub
parent 8625d2e81b
commit 1c12354f38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,92 +6,95 @@
-- These types offer the following benefits over the LowLevel types
--
-- (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.)
-- (2) These types are stronger: distinguishing various identifier classes, instead of everywhere being `Text`.
-- (The lowlevel types are generated by compile-proto,
-- 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.
-- (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
Commands(..),
Command(..),
LedgerOffset(..),
Completion(..),
AbsOffset(..),
Checkpoint(..),
Transaction(..),
Choice(..),
Command(..),
Commands(..),
Completion(..),
EntityName(..),
Enum(..),
Event(..),
Identifier(..),
LedgerConfiguration(..),
LedgerOffset(..),
ModuleName(..),
Party(..),
Record(..),
RecordField(..),
Timestamp(..),
Transaction(..),
TransactionTree(..),
TreeEvent(..),
Value(..),
Record(..),
RecordField(..),
Variant(..),
Enum(..),
Identifier(..),
Timestamp(..),
Verbosity(..),
MicroSecondsSinceEpoch(..),
DaysSinceEpoch(..),
TemplateId(..),
LedgerId(..),
TransactionId(..),
EventId(..),
ContractId(..),
WorkflowId(..),
ApplicationId(..),
CommandId(..),
PackageId(..),
ConstructorId(..),
Choice(..),
Party(..),
ModuleName(..),
EntityName(..),
AbsOffset(..),
Verbosity(..),
LedgerConfiguration(..),
ContractId(..),
EventId(..),
LedgerId(..),
PackageId(..),
TemplateId(..),
TransactionId(..),
WorkflowId(..),
LL.Duration(..),
LL.Status(..),
) where
import Prelude hiding(Enum)
import Data.Map (Map)
import Data.Text.Lazy (Text)
import Prelude hiding(Enum)
import qualified Data.Text.Lazy as Text(unpack)
import qualified Google.Protobuf.Duration as LL
import qualified Google.Rpc.Status as LL
-- commands.proto
data Commands = Commands {
lid :: LedgerId,
wid :: Maybe WorkflowId,
aid :: ApplicationId,
cid :: CommandId,
party :: Party,
leTime :: Timestamp,
mrTime :: Timestamp,
coms :: [Command] }
data Commands = Commands
{ lid :: LedgerId
, wid :: Maybe WorkflowId
, aid :: ApplicationId
, cid :: CommandId
, party :: Party
, leTime :: Timestamp
, mrTime :: Timestamp
, coms :: [Command]
}
data Command
= CreateCommand {
tid :: TemplateId,
args :: Record }
| ExerciseCommand {
tid :: TemplateId,
cid :: ContractId,
choice :: Choice,
arg :: Value }
| CreateAndExerciseCommand {
tid :: TemplateId,
createArgs :: Record,
choice :: Choice,
choiceArg :: Value }
= CreateCommand
{ tid :: TemplateId
, args :: Record
}
| ExerciseCommand
{ tid :: TemplateId
, cid :: ContractId
, choice :: Choice
, arg :: Value
}
| CreateAndExerciseCommand
{ tid :: TemplateId
, createArgs :: Record
, choice :: Choice
, choiceArg :: Value
}
deriving (Eq,Ord,Show)
-- ledger_offset.proto
@ -101,83 +104,84 @@ data LedgerOffset = LedgerBegin | LedgerEnd | LedgerAbsOffset AbsOffset
-- completion.proto
data Completion
= Completion {
cid :: CommandId,
status :: Maybe LL.Status }
data Completion = Completion
{ cid :: CommandId
, status :: Maybe LL.Status
}
deriving (Eq,Ord,Show)
data Checkpoint
= Checkpoint {
-- TODO: add time info
offset :: AbsOffset
}
data Checkpoint = Checkpoint -- TODO: add time info
{ offset :: AbsOffset
}
deriving (Eq,Ord,Show)
-- transaction.proto
data Transaction
= Transaction {
trid :: TransactionId,
cid :: Maybe CommandId,
wid :: Maybe WorkflowId,
leTime :: Timestamp,
events :: [Event],
offset :: AbsOffset } deriving (Eq,Ord,Show)
data Transaction = Transaction
{ trid :: TransactionId
, cid :: Maybe CommandId
, wid :: Maybe WorkflowId
, leTime :: Timestamp
, events :: [Event]
, offset :: AbsOffset
}
deriving (Eq,Ord,Show)
data TransactionTree
= TransactionTree {
trid :: TransactionId,
cid :: Maybe CommandId,
wid :: Maybe WorkflowId,
leTime :: Timestamp,
offset :: AbsOffset,
events :: Map EventId TreeEvent,
roots :: [EventId]
} deriving (Eq,Ord,Show)
data TransactionTree = TransactionTree
{ trid :: TransactionId
, cid :: Maybe CommandId
, wid :: Maybe WorkflowId
, leTime :: Timestamp
, offset :: AbsOffset
, events :: Map EventId TreeEvent
, roots :: [EventId]
}
deriving (Eq,Ord,Show)
data TreeEvent
= CreatedTreeEvent { -- TODO: dedup TreeEvent / Event ! ?
eid :: EventId,
cid :: ContractId,
tid :: TemplateId,
createArgs :: Record,
witness :: [Party],
key :: Maybe Value,
signatories :: [Party],
observers :: [Party] }
| ExercisedTreeEvent {
eid :: EventId,
cid :: ContractId,
tid :: TemplateId,
choice :: Choice,
choiceArg :: Value,
acting :: [Party],
consuming :: Bool,
witness :: [Party],
childEids :: [EventId],
result :: Value}
= CreatedTreeEvent -- TODO: dedup TreeEvent / Event ! ?
{ eid :: EventId
, cid :: ContractId
, tid :: TemplateId
, createArgs :: Record
, witness :: [Party]
, key :: Maybe Value
, signatories :: [Party]
, observers :: [Party]
}
| ExercisedTreeEvent
{ eid :: EventId
, cid :: ContractId
, tid :: TemplateId
, choice :: Choice
, choiceArg :: Value
, acting :: [Party]
, consuming :: Bool
, witness :: [Party]
, childEids :: [EventId]
, result :: Value
}
deriving (Eq,Ord,Show)
-- event.proto
data Event
= CreatedEvent {
eid :: EventId,
cid :: ContractId,
tid :: TemplateId,
createArgs :: Record,
witness :: [Party],
key :: Maybe Value,
signatories :: [Party],
observers :: [Party] }
| ArchivedEvent {
eid :: EventId,
cid :: ContractId,
tid :: TemplateId,
witness :: [Party] }
= CreatedEvent
{ eid :: EventId
, cid :: ContractId
, tid :: TemplateId
, createArgs :: Record
, witness :: [Party]
, key :: Maybe Value
, signatories :: [Party]
, observers :: [Party]
}
| ArchivedEvent
{ eid :: EventId
, cid :: ContractId
, tid :: TemplateId
, witness :: [Party]
}
deriving (Eq,Ord,Show)
-- value.proto
@ -203,70 +207,72 @@ data Value
data Enum = Enum
{ eid :: Maybe Identifier
, 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)
newtype DaysSinceEpoch =
DaysSinceEpoch { unDaysSinceEpoch :: Int }
data Record = Record
{ rid :: Maybe Identifier
, fields :: [RecordField]
}
deriving (Eq,Ord,Show)
data Timestamp
= Timestamp {
seconds :: Int,
nanos :: Int } 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)
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 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 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 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 Party = Party { unParty :: Text } deriving (Eq,Ord)
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)
data LedgerConfiguration = LedgerConfiguration
{ minTtl :: Duration
, maxTtl :: Duration
} deriving (Eq,Ord,Show)
type Duration = LL.Duration