IntersectMBO / plutus-apps

The Plutus application platform
Apache License 2.0
306 stars 214 forks source link

Allow to specify ChangeAddress in BalanceTX API manually #108

Open oskin1 opened 3 years ago

oskin1 commented 3 years ago

Area

Plutus Application Framework Related to the Plutus application backend (PAB), emulator, Plutus libraries

Describe the feature you'd like

It would be infinitely useful if PAB's BalanceTX API allowed to specify change address manually. https://github.com/input-output-hk/plutus-apps/blob/d637b1916522e4ec20b719487a8a2e066937aceb/plutus-contract/src/Plutus/Contract/Request.hs#L705

Probably the changeAddress field should be added to this structure https://github.com/input-output-hk/plutus-apps/blob/ac3f39e1c4384ce44fdb8c321985ac447e85e411/plutus-ledger/src/Ledger/Constraints/OffChain.hs#L170

This would allow to use PAB as a transaction assembly service for trusted external applications which usually require setting a change address depending on a transaction.

Yasuke commented 2 years ago

Hello @oskin1 for a change like this, work needs to be done in deciding on the proper api, and implementing this not only in the PAB but also in cardano-wallet. We are unlikely to add this in the short term but it has been added to the roadmap. Thank you for your suggestion!

etiennejf commented 2 years ago

A possible workaround to this issue is to perform the following steps

However, to be able to perform the following steps, you will have to pass the networkId and protocol parameters to your off-chain code. You will also need to make sure that the only additional outputs that will be added during balancing will concern the change address selected by cardano-wallet (which may not be the primary payment address in the wallet). To do so, you must ensure that you have specify the necessary mustPayToXXX constraints in your offchain code. Note also that the change address must contain both the pubkey and stake credentials so as to target the expect bech32 payment address in the wallet. So there is also a need to pass the stake public key hash of the invoking wallet to your off-chain code.