Skip to content

Commit

Permalink
write script to file
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-az committed May 29, 2023
1 parent 0c34b0c commit 6a40c14
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Building

```sh
nix build .#tornadano:exe:tornadano
nix build .#tornadano:exe:dump-script
```

## Development shell
Expand All @@ -13,3 +13,17 @@ You can use cabal, haskell-language-server and other dev tools inside.
```sh
nix develop
```

## Usage

Example in nix dev shell:

```sh
cabal run dump-script -- -s d1ce83174feeb6ae11d95fd47cac403642cb616b244dbb32a2ca0bda -t "mixer thread" -n 100000000
```

Example if exe is build:

```sh
result/bin/dump-script -s d1ce83174feeb6ae11d95fd47cac403642cb616b244dbb32a2ca0bda -t "mixer thread" -n 100000000
```
11 changes: 11 additions & 0 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import Options.Applicative (execParser)
import PlutusLedgerApi.V1.Bytes (LedgerBytes (..), fromHex)
import PlutusLedgerApi.V1.Value (CurrencySymbol (CurrencySymbol), TokenName, assetClass)
import PlutusLedgerApi.V2 (toData)
import Plutarch.Script (serialiseScript)
import Data.ByteString.Short (ShortByteString)
import qualified Data.ByteString.Short as SBS
import Data.ByteString.Builder (byteStringHex, hPutBuilder)
import System.IO (IOMode(WriteMode), withFile)

main :: IO ()
main = do
Expand All @@ -28,3 +33,9 @@ main = do
let (script, budget, log) = either (error . T.unpack) id $ evalWithArgsT validatorLogic [config]
putStrLn $ "Script budget: " <> show budget
putStrLn $ "Compilation log: " <> show log
writeShortByteStringToFile scriptPath $ serialiseScript script

writeShortByteStringToFile :: FilePath -> ShortByteString -> IO ()
writeShortByteStringToFile filePath shortByteString =
withFile filePath WriteMode $ \handle ->
hPutBuilder handle (byteStringHex (SBS.fromShort shortByteString))
Empty file added compiled/.keep
Empty file.
1 change: 1 addition & 0 deletions tornadano.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ executable dump-script
, plutus-ledger-api
, text
, tornadano
, plutarch

-- LANGUAGE extensions used by modules in this package.
-- other-extensions:

0 comments on commit 6a40c14

Please sign in to comment.