In homework of week4, I refactored my solution:
payTrace :: Integer -> Integer -> EmulatorTrace ()
payTrace payment1 payment2 = do
contract1 <- activateContractWallet (knownWallet 1) payContract
let pkh2 = mockWalletPaymentPubKeyHash $ knownWallet 2
callEndpoint @"pay" contract1 $ PayParams
{
ppRecipient = pkh2
, ppLovelace = payment1
}
void $ Emulator.waitNSlots 1
callEndpoint @"pay" contract1 $ PayParams
{
ppRecipient = pkh2
, ppLovelace = payment2
}
void $ Emulator.waitNSlots 1
to:
payTrace :: Integer -> Integer -> EmulatorTrace ()
payTrace payment1 payment2 = do
contract1 <- activateContractWallet (knownWallet 1) payContract
let pkh2 = mockWalletPaymentPubKeyHash $ knownWallet 2
payTo :: (Member RunContract effs) => PaymentPubKeyHash -> Integer -> Eff effs ()
payTo pkh amount = callEndpoint @"pay" contract1 $ PayParams
{
ppRecipient = pkh
, ppLovelace = amount
}
payTo pkh2 payment1
void $ Emulator.waitNSlots 1
payTo pkh2 payment2
void $ Emulator.waitNSlots 1
However, there are still 2 things I don't like about my current solution:
I'd prefer to put the
payTo
function in the where clause, but that doesn't seem to work properly (although I think I'm close thanks to Luis (https://discord.com/channels/826816523368005654/834340082273878046/942064349831381042). How would one define it in the where clause? (The solution of Luis put me on the right track, but I still can't get it right)I still get compiler warnings about the type. How to define the type of the function properly, so I can get rid of the warnings as well?
src/Week04/Homework.hs:46:18: warning: [-Wsimplifiable-class-constraints]
• The constraint ‘Member RunContract effs’ matches
instance (Data.OpenUnion.Internal.FindElem t r,
Data.OpenUnion.Internal.IfNotFound t r r) =>
Member t r
-- Defined in ‘Data.OpenUnion.Internal’
This makes type inference for inner bindings fragile;
either use MonoLocalBinds, or simplify it using the instance
• In the type signature:
payTo :: (Member RunContract effs) =>
PaymentPubKeyHash -> Integer -> Eff effs ()
In the expression:
do contract1 <- activateContractWallet (knownWallet 1) payContract
let pkh2 = mockWalletPaymentPubKeyHash $ knownWallet 2
payTo ::
(Member RunContract effs) =>
PaymentPubKeyHash -> Integer -> Eff effs ()
....
payTo pkh2 payment1
void $ Emulator.waitNSlots 1
....
In an equation for ‘payTrace’:
payTrace payment1 payment2
= do contract1 <- activateContractWallet
(knownWallet 1) payContract
let pkh2 = ...
....
payTo pkh2 payment1
....
|
46 | payTo :: (Member RunContract effs) => PaymentPubKeyHash -> Integer -> Eff effs ()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ok, 8 modules loaded.
Thanks!