Skip to content

Commit

Permalink
Modify coin selection to support minting and burning
Browse files Browse the repository at this point in the history
- Modifies "performSelection" to account for minted and burnt tokens. On a
  superficial level, mints provide extra tokens to use, where burns increase the
  amount of tokens we need to select.
- Modifies the "makeChange" algorithm to account for minted and burnt tokens.
  When tokens are minted they are added to the largest change bundle. When
  tokens are burnt they are removed from the smallest change bundles until the
  burn has been satisfied. See the code for more detailed commentary.
- Adds property tests that ensure the "addMintChange" and "removeBurnChange"
  family of functions:
  - maintain number of change bundles,
  - maintain partial ascending ordering of change bundles
  - modify the total value of the change bundle by their respective mint/burn
    amounts.
- Adds a few unit tests to ensure the change generation occurs as we expect it
  to.
- Adds some debugging information to the coin selection tests to make debugging
  in the presence of minting and burning easier.
- Adds a "minted but not spent" error to the API. This is returned when a user
  tries to mint a token but doesn't send it anywhere.
  • Loading branch information
sevanspowell committed Jun 18, 2021
1 parent fb3abfc commit bfd7afa
Show file tree
Hide file tree
Showing 6 changed files with 776 additions and 61 deletions.
8 changes: 8 additions & 0 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ import Cardano.Wallet.Primitive.CoinSelection.MA.RoundRobin
, SelectionResult (..)
, UnableToConstructChangeError (..)
, balanceMissing
, outputsMissing
, selectionDelta
)
import Cardano.Wallet.Primitive.Delegation.UTxO
Expand Down Expand Up @@ -3558,6 +3559,13 @@ instance IsServerError ErrSelectAssets where
, "must specify enough ada. Here are the problematic "
, "outputs:\n" <> pretty (indentF 2 $ blockListF xs)
]
OutputsInsufficient e ->
apiError err403 MintedNotSpent $ mconcat
[ "I can't process this transaction because some "
, "minted values were not spent or burned. These "
, "are the values that should be spent or burned: "
, pretty . Flat $ outputsMissing e
]
UnableToConstructChange e ->
apiError err403 CannotCoverFee $ mconcat
[ "I am unable to finalize the transaction, as there is "
Expand Down
1 change: 1 addition & 0 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ data ApiErrorCode
| SharedWalletNoSuchCosigner
| SharedWalletCannotUpdateKey
| SharedWalletScriptTemplateInvalid
| MintedNotSpent
deriving (Eq, Generic, Show, Data, Typeable)
deriving anyclass NFData

Expand Down
Loading

0 comments on commit bfd7afa

Please sign in to comment.