Usage of dictionaries / the value map from the script context #38
Replies: 3 comments 1 reply
-
Q: does value.get require an extra parameter here -> def entry_policy_present(
txins: List[TxInInfo]
) -> Bool:
res = False
for txi in txins:
if txi.resolved.value.get(token.policy_id) == ENTRY-POLICY:
res = True
return res A: Yes! As opposed to the way it is done in python, you always need to supply a default value when accessing elements in a dictionary in eopsin. The reason is that None is not always of the correct type, so always supply a default value of the correct type. In this case the type is a dictionary from bytestring to integers, you can for example supply |
Beta Was this translation helpful? Give feedback.
-
so in that instance to check for the existance of ENTRY-POLICY the correct should be txo.value.get(token.policy_id, {b"": 0}) ? |
Beta Was this translation helpful? Give feedback.
-
Q: for getting the ada being spent by the contract -> own_utxo = own_spent_utxo(ctx.tx_info.inputs, purpose)
spendingvalue = own_utxo.value.get... A: In this case, we need to access the policy id and token name of ADA. It is defined in the plutus docs that ADA/Lovelace always has the empty bytestring as policy id and token name. So we use |
Beta Was this translation helpful? Give feedback.
-
The script context provides a dictionary/map from policy id -> tokenname -> value being contained in the inputs and outputs of the transaction being validated.
This thread is used to keep track of questions popping up regarding its use.
Beta Was this translation helpful? Give feedback.
All reactions