Skip to content

Commit 310a407

Browse files
authored
Merge pull request tweag#288 from tweag/joaosreis/entities-accounts
Add entities/accounts/v0 namespace
2 parents 30bb931 + 4955f8e commit 310a407

5 files changed

Lines changed: 73 additions & 0 deletions

File tree

scls-cardano/cddl-src/Cardano/SCLS/CDDL.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Cardano.SCLS.CDDL (
99
) where
1010

1111
import Cardano.SCLS.Namespace.Blocks qualified as Blocks
12+
import Cardano.SCLS.Namespace.EntitiesAccounts qualified as EntitiesAccounts
1213
import Cardano.SCLS.Namespace.EntitiesCommittee qualified as EntitiesCommittee
1314
import Cardano.SCLS.Namespace.EntitiesDReps qualified as EntitiesDReps
1415
import Cardano.SCLS.Namespace.EntitiesStakePools qualified as EntitiesStakePools
@@ -56,6 +57,9 @@ instance KnownSpec "snapshots/go/v0" where
5657
instance KnownSpec "nonces/v0" where
5758
namespaceSpec _ = mkDefinition Nonces.record_entry
5859

60+
instance KnownSpec "entities/accounts/v0" where
61+
namespaceSpec _ = mkDefinition EntitiesAccounts.record_entry
62+
5963
instance KnownSpec "entities/committee/v0" where
6064
namespaceSpec _ = mkDefinition EntitiesCommittee.record_entry
6165

@@ -98,6 +102,7 @@ knownNamespaces =
98102
, mkNamespaceSymbol @"snapshots/set/v0"
99103
, mkNamespaceSymbol @"snapshots/go/v0"
100104
, mkNamespaceSymbol @"nonces/v0"
105+
, mkNamespaceSymbol @"entities/accounts/v0"
101106
, mkNamespaceSymbol @"entities/committee/v0"
102107
, mkNamespaceSymbol @"entities/dreps/v0"
103108
, mkNamespaceSymbol @"entities/stake_pools/v0"
@@ -115,6 +120,7 @@ type instance Spec.NamespaceKeySize "nonces/v0" = 1 -- Just zero
115120
type instance Spec.NamespaceKeySize "snapshots/mark/v0" = 31 -- 1 byte for hash type, 29 bytes for key hash (including 1-byte discriminator/padding; cred 29, key 28+1), 1 byte for value type
116121
type instance Spec.NamespaceKeySize "snapshots/set/v0" = 31 -- 1 byte for hash type, 29 bytes for key hash (including 1-byte discriminator/padding; cred 29, key 28+1), 1 byte for value type
117122
type instance Spec.NamespaceKeySize "snapshots/go/v0" = 31 -- 1 byte for hash type, 29 bytes for key hash (including 1-byte discriminator/padding; cred 29, key 28+1), 1 byte for value type
123+
type instance Spec.NamespaceKeySize "entities/accounts/v0" = 29 -- 1 byte for tag, 28 bytes for hash
118124
type instance Spec.NamespaceKeySize "entities/committee/v0" = 1 -- One-byte zero, as it's a singleton key
119125
type instance Spec.NamespaceKeySize "entities/dreps/v0" = 29 -- 1 byte for tag, 28 bytes for hash
120126
type instance Spec.NamespaceKeySize "entities/stake_pools/v0" = 28
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{-# LANGUAGE ImportQualifiedPost #-}
2+
{-# LANGUAGE OverloadedLists #-}
3+
{-# LANGUAGE OverloadedStrings #-}
4+
{-# LANGUAGE QuasiQuotes #-}
5+
{-# LANGUAGE TypeApplications #-}
6+
{-# LANGUAGE NoImplicitPrelude #-}
7+
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
8+
9+
{-# HLINT ignore "Use camelCase" #-}
10+
module Cardano.SCLS.Namespace.EntitiesAccounts where
11+
12+
import Cardano.SCLS.Common
13+
import Codec.CBOR.Cuddle.Huddle
14+
import Data.Function (($))
15+
import Text.Heredoc (str)
16+
17+
record_entry :: Rule
18+
record_entry =
19+
comment
20+
[str| The key for the namespace
21+
|
22+
| ```
23+
| meta:
24+
| endian: be
25+
|
26+
| seq:
27+
| - id: key
28+
| type: credential
29+
|
30+
| types:
31+
| credential:
32+
| seq:
33+
| - id: tag
34+
| size: 1
35+
| - id: hash
36+
| size: 28
37+
| ```
38+
|]
39+
$ "record_entry" =:= account_state
40+
41+
account_state :: Rule
42+
account_state =
43+
"account_state"
44+
=:= mp
45+
[ "balance" ==> coin
46+
, "deposit" ==> coin
47+
, "drep_delegation" ==> drep / VNil
48+
, "stake_pool_delegation" ==> pool_keyhash / VNil
49+
]
50+
51+
drep :: Rule
52+
drep =
53+
comment
54+
[str| 0 - key hash
55+
| 1 - script hash
56+
| 2 - always abstain
57+
| 3 - always no confidence
58+
|]
59+
$ "drep"
60+
=:= arr [0, a keyhash28]
61+
/ arr [1, a script_hash]
62+
/ arr [2]
63+
/ arr [3]

scls-cardano/scls-cardano.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ library
3131
other-modules:
3232
Cardano.SCLS.Common
3333
Cardano.SCLS.Namespace.Blocks
34+
Cardano.SCLS.Namespace.EntitiesAccounts
3435
Cardano.SCLS.Namespace.EntitiesCommittee
3536
Cardano.SCLS.Namespace.EntitiesDReps
3637
Cardano.SCLS.Namespace.EntitiesStakePools

scls-cardano/test/Reference.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ allReferenceCDDLs =
6969
, ("snapshots/set/v0", "snapshots_set_v0.cddl")
7070
, ("snapshots/go/v0", "snapshots_go_v0.cddl")
7171
, ("nonces/v0", "nonces_v0.cddl")
72+
, ("entities/accounts/v0", "entities_accounts_v0.cddl")
7273
, ("entities/committee/v0", "entities_committee_v0.cddl")
7374
, ("entities/dreps/v0", "entities_dreps_v0.cddl")
7475
, ("entities/stake_pools/v0", "entities_stake_pools_v0.cddl")

scls-cardano/testlib/Cardano/SCLS/Testlib.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ testAllNS ::
5555
, ConstrNS "snapshots/go/v0"
5656
, ConstrNS "snapshots/mark/v0"
5757
, ConstrNS "snapshots/set/v0"
58+
, ConstrNS "entities/accounts/v0"
5859
, ConstrNS "entities/committee/v0"
5960
, ConstrNS "entities/dreps/v0"
6061
, ConstrNS "entities/stake_pools/v0"
@@ -72,6 +73,7 @@ testAllNS = describe "scls/conformance" $ do
7273
testNS @"snapshots/go/v0"
7374
testNS @"snapshots/mark/v0"
7475
testNS @"snapshots/set/v0"
76+
testNS @"entities/accounts/v0"
7577
testNS @"entities/committee/v0"
7678
testNS @"entities/dreps/v0"
7779
testNS @"entities/stake_pools/v0"

0 commit comments

Comments
 (0)