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

Support of mint/burn of assets in decode transaction #3025

Merged

Conversation

paweljakubas
Copy link
Contributor

@paweljakubas paweljakubas commented Nov 17, 2021

  • I have added support for mint/burn assets along with illustrative integration tests

I will add supports for certs with integration tests in next PR

Comments

Issue Number

@paweljakubas paweljakubas self-assigned this Nov 17, 2021
Copy link
Contributor

@jonathanknowles jonathanknowles left a comment

Choose a reason for hiding this comment

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

Hi @paweljakubas

Two comments so far:

  • So far, we've used the terminology "burned" rather than "burnt", both in our API types and in our internal algorithms. I think it would be good to be consistent and continue to use "burned" everywhere, rather than having a mixture of the two.

  • There are two fields in ApiDecodedTransaction: assets_minted and assets_burned that have the same type ApiMintedBurnedAssets. Given that minted and burned assets are separated in this way, I think it's okay to say that ApiMintedBurnedAssets can only contain positive values. Indeed, this provides a nicer mapping to our internal types, which do not allow negative values. What do you think?

@@ -941,6 +941,19 @@ x-assetMint: &assetMint
Positive values mean creation and negative values mean
destruction.

x-assetMintedBurnt: &assetMintedBurnt
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: use "burned", rather than "burnt".

Elsewhere, we have used the "burned" terminology; it's probably good to be consistent.

Suggested change
x-assetMintedBurnt: &assetMintedBurnt
x-assetMintedBurned: &assetMintedBurned

@@ -2381,6 +2394,16 @@ components:
description: |
Withdrawals that could be external or belong to the wallet.

ApiMintedBurntAssets: &ApiMintedBurntAssets
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ApiMintedBurntAssets: &ApiMintedBurntAssets
ApiMintedBurnedAssets: &ApiMintedBurnedAssets

@@ -2381,6 +2394,16 @@ components:
description: |
Withdrawals that could be external or belong to the wallet.

ApiMintedBurntAssets: &ApiMintedBurntAssets
description: |
Assets minted (created) or burnt (destroyed)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Assets minted (created) or burnt (destroyed)
Assets minted (created) or burned (destroyed)

Comment on lines 2424 to 2425
assets_minted: *ApiMintedBurntAssets
assets_burnt: *ApiMintedBurntAssets
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @paweljakubas

I'm wondering why are there two of these fields, when both of these fields are ApiMintedBurnedAssets?

Shouldn't it be something like:

        assets_minted: *ApiMintedAssets
        assets_burned: *ApiBurnedAssets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

adopted

Assets minted (created) or burnt (destroyed)
This amount contributes to the total transaction value.
Positive values denote creation of assets and negative values
denote the reverse.
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that you have two fields of this type, I think it would be okay to only allow positive values here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

revised this fragments

@paweljakubas
Copy link
Contributor Author

thanks @jonathanknowles for looking at this. First of all, let's address only minting/burning in this PR, and certs in separate PR. When it comes to positive values for both minting/burning I think it is ok to have this like that. We can change this during adding minting/burning support in wallet soon, though. Right now it is the least invasive to have this with decomposition into minting and burning using positive values.

@paweljakubas paweljakubas force-pushed the paweljakubas/adp-1245/mint-burn-certs-decode-transaction branch from 3572145 to e9cffcc Compare November 18, 2021 08:32
@paweljakubas paweljakubas changed the title Support of mint/burn of assets and certs in decode transaction Support of mint/burn of assets in decode transaction Nov 18, 2021
@paweljakubas paweljakubas marked this pull request as ready for review November 18, 2021 08:36

ApiBurnedAssets: &ApiBurnedAssets
description: |
Assets burned (destroyed)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Assets burned (destroyed)
Assets burned (destroyed).

ApiMintedAssets: &ApiMintedAssets
description: |
Assets minted (created).
This amount contributes to the total transaction value.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This amount contributes to the total transaction value.
The act of minting assets provides value to a transaction.

ApiBurnedAssets: &ApiBurnedAssets
description: |
Assets burned (destroyed)
This amount contributes to the total transaction value.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This amount contributes to the total transaction value.
The act of burning assets consumes value from a transaction.

(unsafeFromHex $ T.encodeUtf8 cborHexWithBurning)

let (Right txBodyBurn) = Cardano.deserialiseFromTextEnvelope (Cardano.AsTxBody Cardano.AsAlonzoEra) textEnvelopeBurn
let cborHexBurn = T.decodeUtf8 $ hex $ Cardano.serialiseToCBOR (Cardano.makeSignedTransaction [] txBodyBurn)
Copy link
Contributor

Choose a reason for hiding this comment

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

(line length limit)

Suggested change
let cborHexBurn = T.decodeUtf8 $ hex $ Cardano.serialiseToCBOR (Cardano.makeSignedTransaction [] txBodyBurn)
let cborHexBurn = T.decodeUtf8
$ hex
$ Cardano.serialiseToCBOR
$ Cardano.makeSignedTransaction [] txBodyBurn

""
(unsafeFromHex $ T.encodeUtf8 cborHexWithBurning)

let (Right txBodyBurn) = Cardano.deserialiseFromTextEnvelope (Cardano.AsTxBody Cardano.AsAlonzoEra) textEnvelopeBurn
Copy link
Contributor

Choose a reason for hiding this comment

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

(line length limit)

Suggested change
let (Right txBodyBurn) = Cardano.deserialiseFromTextEnvelope (Cardano.AsTxBody Cardano.AsAlonzoEra) textEnvelopeBurn
let Right txBodyBurn = Cardano.deserialiseFromTextEnvelope
(Cardano.AsTxBody Cardano.AsAlonzoEra)
textEnvelopeBurn

(unsafeFromHex $ T.encodeUtf8 cborHexWithMinting)

let (Right txBodyMint) = Cardano.deserialiseFromTextEnvelope (Cardano.AsTxBody Cardano.AsAlonzoEra) textEnvelopeMint
let cborHexMint = T.decodeUtf8 $ hex $ Cardano.serialiseToCBOR (Cardano.makeSignedTransaction [] txBodyMint)
Copy link
Contributor

Choose a reason for hiding this comment

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

(line length limit)

Suggested change
let cborHexMint = T.decodeUtf8 $ hex $ Cardano.serialiseToCBOR (Cardano.makeSignedTransaction [] txBodyMint)
let cborHexMint = T.decodeUtf8
$ hex
$ Cardano.serialiseToCBOR
$ Cardano.makeSignedTransaction [] txBodyMint

""
(unsafeFromHex $ T.encodeUtf8 cborHexWithMinting)

let (Right txBodyMint) = Cardano.deserialiseFromTextEnvelope (Cardano.AsTxBody Cardano.AsAlonzoEra) textEnvelopeMint
Copy link
Contributor

Choose a reason for hiding this comment

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

(line length limit)

Suggested change
let (Right txBodyMint) = Cardano.deserialiseFromTextEnvelope (Cardano.AsTxBody Cardano.AsAlonzoEra) textEnvelopeMint
let Right txBodyMint = Cardano.deserialiseFromTextEnvelope
(Cardano.AsTxBody Cardano.AsAlonzoEra)
textEnvelopeMint

Comment on lines 1357 to 1358
let tokens = TokenMap.fromNestedList
[(tokenPolicyId, NE.fromList [(UnsafeTokenName "HappyCoin", TokenQuantity 50000)])]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: use TokenMap.singleton here:

Suggested change
let tokens = TokenMap.fromNestedList
[(tokenPolicyId, NE.fromList [(UnsafeTokenName "HappyCoin", TokenQuantity 50000)])]
let tokens = TokenMap.singleton
(AssetId tokenPolicyId (UnsafeTokenName "HappyCoin"))
(TokenQuantity 50_000)

(Link.decodeTransaction @'Shelley wa) Default decodeMintPayload
verify rTx
[ expectResponseCode HTTP.status202
, expectField (#fee . #getQuantity) (`shouldBe` 202725)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: use NumericUnderscores for extra clarity.

Suggested change
, expectField (#fee . #getQuantity) (`shouldBe` 202725)
, expectField (#fee . #getQuantity) (`shouldBe` 202_725)

(Link.decodeTransaction @'Shelley wa) Default decodeBurnPayload
verify rTx'
[ expectResponseCode HTTP.status202
, expectField (#fee . #getQuantity) (`shouldBe` 202725)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: use NumericUnderscores for extra clarity.

Suggested change
, expectField (#fee . #getQuantity) (`shouldBe` 202725)
, expectField (#fee . #getQuantity) (`shouldBe` 202_725)

@paweljakubas
Copy link
Contributor Author

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 18, 2021

Build succeeded:

@iohk-bors iohk-bors bot merged commit d768d8a into master Nov 18, 2021
@iohk-bors iohk-bors bot deleted the paweljakubas/adp-1245/mint-burn-certs-decode-transaction branch November 18, 2021 10:48
WilliamKingNoel-Bot pushed a commit that referenced this pull request Nov 18, 2021
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.

2 participants