Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alice blueprint commit #1627

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ repository cardano-haskell-packages

-- See CONTRIBUTING.md for information about when and how to update these.
index-state:
, hackage.haskell.org 2024-07-19T19:07:04Z
, cardano-haskell-packages 2024-07-19T19:04:02Z
, hackage.haskell.org 2024-09-23T15:45:50Z
, cardano-haskell-packages 2024-09-20T19:39:13Z

packages:
hydra-prelude
Expand Down
134 changes: 134 additions & 0 deletions demo/alice-blueprint-commit.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{-# LANGUAGE ExtendedDefaultRules #-}
{-# LANGUAGE OverloadedStrings #-}

import Control.Lens (asIndex, to, (&), (^.), (^?))
import Data.Aeson
import qualified Data.Aeson.Key as Key
import Data.Aeson.Lens
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as LBS
import Data.Maybe (fromJust)
import Data.String
import Data.Text (Text)
import qualified Data.Text.Lazy as Text
import Data.Text.Lazy.Encoding (decodeLatin1)
import Shh

getAddress :: IO ByteString
getAddress = do
exe
"cardano-cli"
"address"
"build"
"--payment-verification-key-file"
"devnet/credentials/alice-funds.vk"
"--testnet-magic"
"42"
|> capture

getUTxO :: ByteString -> IO (Either String Value)
getUTxO address = do
k <-
exe
"cardano-cli"
"query"
"utxo"
"--socket-path"
"devnet/node.socket"
"--address"
address
"--testnet-magic"
"42"
"--output-json"
|> capture
pure $ eitherDecode k

buildTransaction :: ByteString -> ByteString -> IO (Either String Value)
buildTransaction i o = do
x <-
exe
"cardano-cli"
"conway"
"transaction"
"build-raw"
"--tx-in"
i
"--tx-out"
(o <> "+5000000")
"--fee"
"0"
"--out-file"
"/dev/stdout"
|> capture
pure $ eitherDecode x

blueprintTx :: Text -> Value -> Text -> Value
blueprintTx address utxo cborHex =
object
[ "blueprintTx"
.= object
[ "cborHex" .= String cborHex
, "description" .= ""
, "type" .= "Tx ConwayEra"
]
, "utxo" .= utxo
]

decodeTxFile :: IO (Either String Value)
decodeTxFile = do
x <- LBS.readFile "tx.json"
pure $ eitherDecode x

curlCommitRequest :: IO ByteString
curlCommitRequest =
exe
"curl"
"-X"
"POST"
"127.0.0.1:4001/commit"
"--data"
"@commit-request.json"
|> capture

signTransaction :: IO ()
signTransaction =
exe
"cardano-cli"
"transaction"
"sign"
"--tx-file"
"commit-tx.json"
"--signing-key-file"
"devnet/credentials/alice-funds.sk"
"--out-file"
"signed-tx.json"

submitTransaction :: IO ()
submitTransaction =
exe
"cardano-cli"
"transaction"
"submit"
"--tx-file"
"signed-tx.json"
"--socket-path"
"devnet/node.socket"
"--testnet-magic"
"42"

main = do
address <- getAddress
utxo <- either error id <$> getUTxO address
let utxoKey = utxo ^. members . asIndex
tx <- either error id <$> buildTransaction (Data.String.fromString . Key.toString $ utxoKey) address
let cborHex = tx ^? key "cborHex"
let (String cborHexBS) = fromJust cborHex
encodeFile "commit-request.json" $
blueprintTx
(Text.toStrict $ decodeLatin1 address)
utxo
cborHexBS
commitTx <- curlCommitRequest
LBS.writeFile "commit-tx.json" commitTx
signTransaction
submitTransaction
69 changes: 43 additions & 26 deletions flake.lock

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

13 changes: 11 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@
value = addWerror v;
})
x.components."${y}") [ "benchmarks" "exes" "sublibs" "tests" ]);
alice-blueprint-commit = pkgs.writers.writeHaskellBin
"alice-blueprint-commit"
{
libraries =
with pkgs.haskellPackages;
[ aeson text bytestring lens lens-aeson shh ];
} ''${builtins.readFile demo/alice-blueprint-commit.hs}'';
in
{
legacyPackages = pkgs // hsPkgs;
Expand All @@ -132,6 +139,7 @@
hydraPackages //
(if pkgs.stdenv.isLinux then (prefixAttrs "docker-" hydraImages) else { }) // {
spec = inputs.hydra-spec.packages.${system}.default;
alice-blueprint-commit = alice-blueprint-commit;
};
process-compose."demo" = import ./nix/hydra/demo.nix {
inherit system pkgs inputs self;
Expand All @@ -149,7 +157,7 @@
pkgs.nixpkgs-fmt
pkgs.fourmolu
];
treefmt = pkgs.treefmt;
treefmt = pkgsLatest.treefmt;
};
} // lib.attrsets.mergeAttrsList (map (x: componentsToWerrors x hsPkgs.${x}) [
"hydra-cardano-api"
Expand All @@ -167,7 +175,8 @@
]);

devShells = import ./nix/hydra/shell.nix {
inherit inputs pkgs hsPkgs system compiler pkgsLatest;
inherit inputs pkgs hsPkgs system pkgsLatest;
ghc = pkgs.buildPackages.haskell-nix.compiler.${compiler};
};
};
};
Expand Down
8 changes: 4 additions & 4 deletions hydra-plutus/hydra-plutus.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ library
, hydra-cardano-api
, hydra-plutus-extras
, hydra-prelude
, plutus-core >=1.21
, plutus-ledger-api >=1.21
, plutus-tx >=1.21
, plutus-tx-plugin >=1.21
, plutus-core ^>=1.30
, plutus-ledger-api ^>=1.30
, plutus-tx ^>=1.30
, plutus-tx-plugin ^>=1.30
, QuickCheck
, serialise
, template-haskell
Expand Down
4 changes: 2 additions & 2 deletions nix/hydra/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
, inputs
, system
, pkgs
, compiler
, ghc
, pkgsLatest
}:
let
Expand Down Expand Up @@ -90,7 +90,7 @@ let
name = "hydra-node-cabal-shell";

buildInputs = libs ++ [
hsPkgs.ghc
ghc
pkgs.cabal-install
pkgs.pkg-config
] ++ buildInputs;
Expand Down