0

In the pionner program they have this logic where they filter through utxos and get a specific set of utxos.

{...}
utxos <- Map.filter (isSuitable pkh) <$> utxosAt scrAddress
{...}
where
   isSuitable :: PubKeyHash -> TxOutTx -> Bool

How can i modify this to make it so that it filters utxos that came from a specific public key address. Basically get all utxos sitting in a script address that came from a specific public key.

1 Answer 1

1

Assuming each UTxO at the script address has a datum that contains the PubKeyHash you can compare against, then you can use the above code like so:

data UTxODatum = UTxODatum
    { pubKey :: !PaymentPubKeyHash }

{...}
    isSuitable :: PaymentPubKeyHash -> ChainIndexTxOut -> Bool
    isSuitable pkh o = case getUTxODatum o of
        UTxODatum{pubKey=pubKey} -> pubKey == <your specific pkh>
        _                        -> traceError "Unhandled datum type"
{...}

getUTxODatum :: ChainIndexTxOut -> UTxODatum
getUTxODatum o = case _ciTxOutDatum o of
    Left _ -> traceError "unexpected datum"
    Right (Datum d) -> do
        let parsedDatum = PlutusTx.fromBuiltinData d :: Maybe UTxODatum
        case parsedDatum of
            Just s -> s
            _ -> traceError "Unknown datum type"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.