Skip to content

Commit

Permalink
voting-tools: switch to generate account addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
disassembler committed Apr 15, 2021
1 parent a2964f7 commit 2f33a37
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 8 deletions.
78 changes: 74 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions nix/sources.json
Expand Up @@ -17,10 +17,10 @@
"homepage": "https://input-output-hk.github.io/haskell.nix",
"owner": "input-output-hk",
"repo": "haskell.nix",
"rev": "9f774325bc43c405802232bf29a8ce1c2f48bb75",
"sha256": "0pkw3ayzfwqf0cnv8cf8sbmhlfqadz2804iv43i9z37ryajcvvh0",
"rev": "5f11b1197e3fd6418609f22593e751296d770743",
"sha256": "1xc556bdxm2969cdr0071f1wvq6whw2nh5glgw69z3nmcjka7zbr",
"type": "tarball",
"url": "https://github.com/input-output-hk/haskell.nix/archive/9f774325bc43c405802232bf29a8ce1c2f48bb75.tar.gz",
"url": "https://github.com/input-output-hk/haskell.nix/archive/5f11b1197e3fd6418609f22593e751296d770743.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"iohk-nix": {
Expand Down
9 changes: 8 additions & 1 deletion src/Cardano/API/Jormungandr.hs
Expand Up @@ -64,7 +64,7 @@ data Address = Address { unAddress :: B.ByteString }

addressFromVotingKeyPublic :: NetworkId -> VotingKeyPublic -> Address
addressFromVotingKeyPublic nw =
mkSingleAddress (discriminationFromNetworkId nw) . serialiseToRawBytes
mkAccountAddress (discriminationFromNetworkId nw) . serialiseToRawBytes

discriminationFromNetworkId :: NetworkId -> Discrimination
discriminationFromNetworkId Mainnet = Production
Expand All @@ -77,6 +77,13 @@ mkSingleAddress d bs = Address . B.concat $ BL.toChunks . Bin.runPut $ do
Test -> Bin.putWord8 (0b11111111 .&. 0x3)
Bin.putByteString bs

mkAccountAddress :: Discrimination -> B.ByteString -> Address
mkAccountAddress d bs = Address . B.concat $ BL.toChunks . Bin.runPut $ do
case d of
Production -> Bin.putWord8 (0b01111111 .&. 0x5)
Test -> Bin.putWord8 (0b11111111 .&. 0x5)
Bin.putByteString bs

instance SerialiseAsBech32' Address where
bech32PrefixFor (Address _) = "ca"
bech32PrefixesPermitted AsAddress = ["ca"]
Expand Down

0 comments on commit 2f33a37

Please sign in to comment.