Hi i am building CrowdFund where i need to know the total amount raised at the script as an OnChain validation. i was looking at Contexts.findOwnInput but would this only return the tx-in's provided in this particular redeem call? I am looking to get all the unspent UTXOs at the script address and i need that in the OnChain logic and not offChain- so i can total all the Ada to know how much is now at the Script. And if certain target is reached i can allow the Crowd Source owner to take that Ada. appreciate your thoughts.
-
As far as I know, the on-chain validator does not have access to anything else than what you send it as parameters. So what you want is not possible. You need to do it off-chain.– George - APEX Stake PoolJan 5 at 10:52
-
yes thx George! i also realized that later. i think Cause script cannot see whole blockchain but only utXos submitted with the Txn. So i still am working but i think we can use NFT at script to instead use redeem actions to add contributions and that way update datum with target amount. and then i know if total target reached or not.– Chakravarti RaghavanJan 6 at 23:44
1 Answer
i was actually able to do this:
txinfo :: Contexts.TxInfo
txinfo = Contexts.scriptContextTxInfo context
txInputs = Contexts.txInfoInputs txinfo
validatedValue = Contexts.txOutValue . Contexts.txInInfoResolved <$> txInputs
With this i was able to get all the UTXOs submitted to the transaction. It still means the submit transaction need to gather UTXO's and submit it with tx-in to the transaction. Obviously there might be some limits on how many tx-in you can submit based on the transaction size etc. But i was able to submit 2 UTXO as tx-in and with Contexts.txInfoInputs was able to get both amounts locked at the script at once.
Contexts.findOwnInput seems to validate 1 at a time even when 2 tx-in are submitted. So i would NOT know the combined value of both UTXOs at this script address. I would be interested to know whats other solutions are there that could be even better
-
i realized later i think Cause script cannot see whole blockchain but only utXos submitted with the Txn. So i still am working but i think we can use NFT at script to instead use redeem actions to add contributions and that way update datum with target amount. and then i know if total target reached or not. Jan 6 at 23:46