Closed LendaDeAfonselio closed 3 years ago
Alternatively you can export fundsAtAddressCondition
in the watchAddress
module
Thanks for reporting!
Yeah, while the fix is not in master yet, you can copy fundsAtAddressCondition
to your code. ghc will ask some language extensions and imports, but it should work.
Thank you!
I am currently using the playground, is there any way in which I can use fundsAtAddressCondition
on the playground? Or is it impossible atm?
While I am this topic, what is currently the best option for smart contracts?
fundsAtAddressCondition
and use it in the local playground:{-# LANGUAGE RankNTypes, FlexibleContexts, GADTs #-}
import Ledger.AddressMap (UtxoMap)
import Plutus.Contract.Util (loopM)
fundsAtAddressCondition
:: forall w s e.
( AsContractError e
, HasAwaitSlot s
, HasUtxoAt s
)
=> (Value -> Bool)
-> Address
-> Contract w s e UtxoMap
fundsAtAddressCondition condition addr = loopM go () where
go () = do
cur <- utxoAt addr
sl <- Contract.currentSlot
let presentVal = foldMap (txOutValue . txOutTxOut) cur
if condition presentVal
then pure (Right cur)
else awaitSlot (sl + 1) >> pure (Left ())
Maybe some language extensions or imports are missing but ghc will suggest them.
Area
[] Plutus Foundation Related to the GHC plugin, Haskell-to-Plutus compiler, on-chain code [x] Plutus Application Framework Related to the Plutus application backend (PAB), emulator, Plutus libraries [] Marlowe Related to Marlowe [] Other Any other topic (Playgrounds, etc.)
Describe the feature you'd like
Hello, I was coding a smart contract where ADA would be deposited in the contract after a certain operation and I wanted to have trigger that activated when that money was withdrawn and then perform certain logic. Something like:
Unfortunately there is no way that I can actively wait until there are no funds in the contract. As such I suggest that
fundsAtAddressLeq
andfundsAtAddressLt
are added to the Plutus library.I have seen the documentation for
fundsAtAddressGt
andfundsAtAddressGeq
unfortunately none of them are useful in the logic I want to implementDescribe alternatives you've considered
I have considered "negating"
fundsAtAddressGt
but I have not seen how I can achieve this. In this specific case I have also considered knowing the stored value using the state machine, once again without any results.Additional context / screenshots
The code presented previously using this feature would look like this:
Any possible workaround this situation that are not storing the current value in
DepositedState
?