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

Rewrite the Scripts API module and use it in the CLI to support the new script language version #2141

Merged
merged 9 commits into from
Nov 30, 2020

Conversation

dcoutts
Copy link
Contributor

@dcoutts dcoutts commented Nov 30, 2020

This makes a change similar to the one we made with addresses recently.
With addresses we identified that there are two independent dimensions:
the address type (i.e. Byron vs Shelley address), and the era in which
the address is valid.

With scripts the dimensions are the language, and the era in which the
language is supported. So with this change we can talk about script
languages independently of the era in which those languages are
supported. We also gain a type covering all language, irrespective of
era, which is useful as an intermediate type for converting from weakly
typed input (e.g. in the CLI) to the strongly-typed internal types.

Another advantage of splitting the dimensions this way is that it will
be easier to add new eras that inherit all the earlier languages,
especially if they do not add new eras themselves.

Though right now we only support the simple script language, structure
the types so that it is clear where to add Plutus once it arrives.

Update the CLI to use this. The effect is that it now supports the
appropriate languages in each era.

Split the Shelley genesis example from the script examples.

They are mostly unrelated and use very different imports. We will
shortly rewrite the script examples.
It contains a CardanoEra but hides the era type arg. This allows us to
use CardanoEra in contexts where we do not statically know what era it
will be.

This is useful for example in error reports (where it is inconvenient
and unnecessary to parametrise by era) or in the CLI when selecting an
era to use.
This also allows eliminating the withCardanoEra helper, since simply
pattern matching on AnyCardanoEra does the same thing.
We will actually use a different impl for scripts, using JSON format not
the text envelope binary format.

The rule for the CLI is that we use input scripts in JSON, but witnesses
in binary (even for witnesses consisting of only scripts).

Also remove unused readFileInAnyShelleyBasedEra.
-- of 'SimpleScriptV1' plus new atomic predicates:
--
-- * require the time be before a given slot number
-- * require the time be before a given slot number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require the time be after a given slot number

Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

This makes a change similar to the one we made with addresses recently.
With addresses we identified that there are two independent dimensions:
the address type (i.e. Byron vs Shelley address), and the era in which
the address is valid.

With scripts the dimensions are the language, and the era in which the
language is supported. So with this change we can talk about script
languages independently of the era in which those languages are
supported. We also gain a type covering all language, irrespective of
era, which is useful as an intermediate type for converting from weakly
typed input (e.g. in the CLI) to the strongly-typed internal types.

Another advantage of splitting the dimensions this way is that it will
be easier to add new eras that inherit all the earlier languages,
especially if they do not add new eras themselves.

Also add numerous utility functions for handling scripts in
language-generic and era-generic ways.

Though right now we only support the simple script language, structure
the types so that it is clear where to add Plutus once it arrives.

Do the minimal updates to the CLI. There is more cleanup that can be
done here, but that can wait for later commits.
We use deriving (Show, IsString) via UsingRawBytesHex for all the
verification and signing keys, but we had missed it for the key hash
types.

Use this to simplify the multi-sig script examples.
We have several clones of this util open-coded in the cli. This will
help clean those up.
This is consistent with making tx witnesses.

Add reusable readFileScriptInAnyLang
Replace the impl in readWitnessSigningData with the shared util.
@dcoutts
Copy link
Contributor Author

dcoutts commented Nov 30, 2020

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 30, 2020

@iohk-bors iohk-bors bot merged commit 13cc50b into master Nov 30, 2020
@iohk-bors iohk-bors bot deleted the dcoutts/api-script-langs branch November 30, 2020 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants