-
Notifications
You must be signed in to change notification settings - Fork 720
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
Initial lexer and parser for specifying Mary multi assets via the cli #2072
Conversation
a474787
to
71efdff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we expand upon this PR's description with an example(s) of the kind of input this parser is capable of handling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #2072 (review).
Forgot to select "request changes" on that review.
af251c9
to
492e784
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more comments.
6ee854c
to
37c5205
Compare
f11528e
to
e275a4d
Compare
Depends on #2129. Marking this PR as a draft until that's been merged. |
e275a4d
to
a5a59ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good.
I think the second patch can be dropped now, as it looks like it was applied already in another PR.
1be2c5f
to
67e990b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good.
data ValueExpr | ||
= ValueExprAdd !ValueExpr !ValueExpr | ||
| ValueExprLovelace !Quantity | ||
| ValueExprMultiAsset !PolicyId !AssetName !Quantity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes nice.
tokenParser :: GenTokenParser String u Identity | ||
tokenParser = makeTokenParser haskellDef -- TODO: What language def to use? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should avoid using this token parser. Our language is very very simple. We don't need to pull in this stuff.
We're only using it here for parens
, which we don't actually want, and for reservedOp
. The reservedOp
is for checking that operators are not prefixes of any other reserved operators. But we have no other operators! So we can define our binary and prefix operators directly, without the token parser stuff.
period :: Parser String | ||
period = string "." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make this have type Parser ()
then when we use it we don't need the _ <-
syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's true. Thanks.
67e990b
to
7019f0b
Compare
7019f0b
to
1b5494b
Compare
9f4bbff
to
dd8e1da
Compare
Opt.option (eitherReader readTxOut) | ||
( Opt.long "tx-out" | ||
<> Opt.metavar "TX-OUT" | ||
-- TODO: Update the help text to describe the new syntax as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be addressed
6e2299c
to
24a1b77
Compare
f669c6a
to
0dd4445
Compare
0dd4445
to
f669c6a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ok now. We can make further internal improvements later (e.g. the error messages).
If CI tests pass lets squash down to one patch and merge it.
Add a concrete syntax and parser for multi-asset values. Use it in the cli for transaction outputs and minting. Example multi-asset values * "42" 42 lovelace, same syntax as coin values in previous eras * "42 lovelace" same with the special asset id for lovelace * "3 e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a.foobar" 3 units of the asset with that policy id and asset name "foobar" * "3 e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a" 3 units of the asset with that policy id and empty asset name "" * "42 lovelace + 3 e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a" multiple such assets can be combined with + * "-3 e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a + 42 dd0044a26cf7d4491ecea720fda11afb59d5725b53afa605fdf695e6" negative quantities are allowed for minting * "42 lovelace + -42 lovelace" Empty value! Co-authored-by: Luke Nadur <19835357+intricate@users.noreply.github.com> Co-authored-by: Duncan Coutts <duncan@well-typed.com>
90a5f4f
to
db8e2f4
Compare
bors merge |
Build succeeded: |
Introduce CLI parsing of a new proposed syntax for multi-asset
Value
s andTxOut
s. Note that this new syntax is backward-compatible with the old syntax. i.e. the old transaction output CLI syntax:${address}+{lovelace}
is still supported.The new syntax is defined as follows:
Values
Specifying individual values
Lovelace values can be specified in the following ways:
${quantity} lovelace
(wherequantity
is a signed integer)${quantity}
(wherequantity
is a signed integer)Values for other assets can be specified in the following ways:
${quantity} ${policyId}.${assetName}
(wherequantity
is a signed integer,policyId
is a hex-encoded policy ID [script hash], andassetName
is an alphanumeric asset name)${quantity} ${policyId}
(wherequantity
is a signed integer andpolicyId
is a hex-encoded policy ID [script hash])Negating individual values
Individual values can be negated by utilizing the
-
prefix operator. All individual values can be prefixed by this operator. Some examples:-42 46f192e30c5d8fcc5ccbcd9c91e430283166b3382cd25261a1601b74
-72191 46f192e30c5d8fcc5ccbcd9c91e430283166b3382cd25261a1601b74.foo
-100
-920 lovelace
Combining individual values
Values can be combined by using the
+
binary operator. Some examples:42 lovelace + -1
(this would result in aValue
of 41 lovelace)20 46f192e30c5d8fcc5ccbcd9c91e430283166b3382cd25261a1601b74 + 12 46f192e30c5d8fcc5ccbcd9c91e430283166b3382cd25261a1601b74.foo + -2 46f192e30c5d8fcc5ccbcd9c91e430283166b3382cd25261a1601b74.bar
201 46f192e30c5d8fcc5ccbcd9c91e430283166b3382cd25261a1601b74.foo + 12 + -1 + 9 lovelace + 10 46f192e30c5d8fcc5ccbcd9c91e430283166b3382cd25261a1601b74
Transaction outputs
Transaction outputs can be specified in the following ways:
${address} ${value}
(whereaddress
is a Cardano address andvalue
is a value)${address}+${value}
(whereaddress
is a Cardano address andvalue
is a value) (n.b. this is actually the old tx out CLI syntax that is additionally supported by the new parser)