0

In the auction code of the Plutus pioneer program during week 1, the code approves a bid by comparing the datum with previous ones in the Plutus on-chain code. How could you repurpose this so that you could store multiple utxos of different datums tokens on the smart contract then verify transactions for only the tokens that match the needed datum?

This is the code i'm refrencing

ownOutput   :: TxOut
        outputDatum :: Integer
        (ownOutput, outputDatum) = case getContinuingOutputs ctx of
            [o] -> case txOutDatumHash o of
                Nothing   -> traceError "wrong output type"
                Just h -> case findDatum h info of
                    Nothing        -> traceError "datum not found"
                    Just (Datum d) ->  case PlutusTx.fromBuiltinData d of
                        Just iDatum' -> (o, iDatum')
                        Nothing  -> traceError "error decoding data"
            _   -> traceError "expected exactly one continuing output"   
2
  • This is not a free code foundry. If you attempt a solution and have problems, then the answers may be found here or you could ask about the specific problem you are having.
    – gRebel
    Jan 31 at 1:05
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Jan 31 at 1:06

1 Answer 1

0

I had a similar question: "How do you handle 2 continuing outputs?" Couldn't find any answers or documentation anywhere!

After lots of experimenting, I came up with the following code. (it handles 2 continuing outputs). Probably not the most efficient, but it works:

ownOutputa = (getContinuingOutputs ctx) !! 0
ownOutputb = (getContinuingOutputs ctx) !! 1

myDatum :: TxOut -> (DatumHash -> Maybe Datum) -> Maybe MyDatum
myDatum o f = do
    dh      <- txOutDatum o
    Datum d <- f dh
    PlutusTx.fromBuiltinData d

outputDatuma :: MyDatum
outputDatuma = case myDatum ownOutputa (`findDatum` info) of
    Nothing -> traceError "output datum a not found"
    Just d  -> d

outputDatumb :: MyDatum
outputDatumb = case myDatum ownOutputb (`findDatum` info) of
    Nothing -> traceError "output datum b not found"
    Just d  -> d

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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