-
Notifications
You must be signed in to change notification settings - Fork 214
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
Add W.balanceTx
helper
#4629
Add W.balanceTx
helper
#4629
Conversation
03326ac
to
92d8064
Compare
lib/wallet/src/Cardano/Wallet.hs
Outdated
sharedWalletScriptLookup | ||
:: SharedState (NetworkOf s) SharedKey -> Address -> CA.Script KeyHash | ||
sharedWalletScriptLookup s addr = case fst (isShared addr s) of | ||
Nothing -> | ||
error $ "Some inputs selected by coin selection do not belong " | ||
<> "to multi-signature wallet" | ||
Just (ix,role) -> | ||
let template = paymentTemplate s | ||
role' = case role of | ||
UtxoExternal -> CAShelley.UTxOExternal | ||
UtxoInternal -> CAShelley.UTxOInternal | ||
MutableAccount -> | ||
error "role is specified only for payment credential" | ||
in replaceCosignersWithVerKeys role' template ix |
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.
Simply moved from constructUnbalancedSharedTransaction
:<|> balanceTransaction | ||
shelley | ||
(delegationAddressS @n) | ||
(utxoAssumptionsForWallet ShelleyWallet) | ||
mempty | ||
:<|> balanceTransaction shelley |
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.
☝️ (nicer)
(Shared.paymentTemplate (getState wallet)) | ||
(sharedWalletScriptLookup (getState wallet) | ||
. Convert.toWalletAddress) | ||
|
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.
Since we are in IO
, we will be able to query the node for extra UTxO
info here later.
-> IO (Write.Tx era) | ||
balanceTx wrk pp timeTranslation partialTx = do | ||
(utxo, wallet, _txs) <- liftIO $ readWalletUTxO wrk | ||
-- FIXME: Why are we not using the availableUTxO here? |
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 is not the PR to change it, but it probably should be changed.
f9aaec2
to
35e7807
Compare
@@ -3854,6 +3892,13 @@ data PoolRetirementEpochInfo = PoolRetirementEpochInfo | |||
} | |||
deriving (Eq, Generic, Show) | |||
|
|||
throwOnErr :: (MonadIO m, Exception e) => Either e a -> m a |
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 wonder if those things should not be somewhere else to be reused by other modules and packages... Possible here https://github.com/cardano-foundation/cardano-wallet/blob/master/lib/wallet/src/UnliftIO/Compat.hs or somewhere close to it. Maybe this is proper place as it is not needed elsewhere
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 agree it would be nice to co-locate these helpers.
But perhaps somewhere else other than UnliftIO
, as that is specific to the unliftio
way of doing things.
Thoughts?
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.
Looks like a nice code reshuffling that gives rise to simplification on api side and moving logic and details under the hood 👍 If everything passes we are good here IMHO
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.
LGTM! Just have a small number of suggestions.
toApiSerialisedTransaction maybeEncoding tx = | ||
let | ||
encoding = fromMaybe Base64Encoded maybeEncoding | ||
in | ||
ApiSerialisedTransaction (ApiT $ sealWriteTx tx) encoding |
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.
Just curious, why not:
toApiSerialisedTransaction maybeEncoding tx = | |
let | |
encoding = fromMaybe Base64Encoded maybeEncoding | |
in | |
ApiSerialisedTransaction (ApiT $ sealWriteTx tx) encoding | |
toApiSerialisedTransaction maybeEncoding tx = | |
ApiSerialisedTransaction (ApiT $ sealWriteTx tx) encoding | |
where | |
encoding = fromMaybe Base64Encoded maybeEncoding |
(Saves both horizontal and vertical space.)
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.
In this specific example I think I like how you see the flow of
maybeEncoding
introduced (parameter)maybeEncoding
transformed intoencoding
encoding
is used
in order, as opposed to 1-3-2 with where
.
@@ -3854,6 +3892,13 @@ data PoolRetirementEpochInfo = PoolRetirementEpochInfo | |||
} | |||
deriving (Eq, Generic, Show) | |||
|
|||
throwOnErr :: (MonadIO m, Exception e) => Either e a -> m a |
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 agree it would be nice to co-locate these helpers.
But perhaps somewhere else other than UnliftIO
, as that is specific to the unliftio
way of doing things.
Thoughts?
6b6f182
to
81b160c
Compare
81b160c
to
620ff36
Compare
- Add `getUTxOByTxIn` local state query - Resolve `PartialTx` inputs over LSQ in `Cardano.Wallet.balanceTx` ### Comments This is part of the fix for the [integration test in the 8.11 branch](https://buildkite.com/cardano-foundation/cardano-wallet/builds/5254#018fee3c-01ad-441e-bb7e-25acd78cb7f3); if we have the UTxO of the reference input containing the script used for minting in constructTx, then `Ledger.getMinFeeTxUtxo pp tx utxo` will correctly account for minFeeRefScriptCoinsPerByte * totalRefScriptSize. Previous step: #4629 Next step: #4631 ### Issue Number ADP-3373
Add
W.balanceTx
helper used by the following endpointsconstructTransaction
constructTransactionShared
balanceTransaction
such that
W.balanceTx
automatically query the node for theUTxO
corresponding to the inputs of thePartialTx
(this is part of the fix for the integration test in the 8.11 branch; if we have theUTxO
of the reference input, thenLedger.getMinFeeTxUtxo pp tx utxo
will correctly account forminFeeRefScriptCoinsPerByte * totalRefScriptSize
)Comments
Issue Number
ADP-3373