Anastasia-Labs / aiken-design-patterns

A collection of tried and tested modules and functions for implementing common design patterns in Aiken
MIT License
16 stars 9 forks source link

Error with stake validator within multivalidator. #3

Closed golddydev closed 6 months ago

golddydev commented 6 months ago

I have made a stake validator within multivaildator according to your document.

validator {
  fn spend(_datum, redeemer: Action, context: ScriptContext) {
    when redeemer is {
      Deposit -> {
        expect ScriptContext { transaction: tx, purpose: tx.Spend(own_ref) } =
          context

        let Transaction { inputs, withdrawals, .. } = tx

        let Output { address: own_addr, .. } =
          resolve_output_reference(inputs, own_ref)

        trace stringify.address(own_addr)

        let own_withdrawal = Inline(own_addr.payment_credential)

        // Arbitrary withdrawal from this script is required.
        dict.has_key(withdrawals, own_withdrawal)
      }
      Claim -> False
    }
  }

  fn withdraw(_redeemer: Data, context: ScriptContext) {
    expect ScriptContext {
      transaction: _t,
      purpose: tx.WithdrawFrom(stake_cred),
    } = context

    expect Inline(ScriptCredential(own_validator)) = stake_cred
    trace stringify.credential(ScriptCredential(own_validator))
    True
  }
}

But when I try to spend utxo, I got this error.

error: Uncaught (in promise) "Redeemer (Spend, 0): Empty List:\n\nCon(\n    ProtoList(\n        Data,\n        [],\n    ),\n)\n\nExBudget {\n    mem: 262,\n    cpu: 564597,\n}\n\n"

Can you help me with this issue?

keyan-m commented 6 months ago

This typically happens when your off-chain is not constructing the redeemer properly. Your plutus.json (generated by Aiken) tells you the structure of the expected redeemer.

golddydev commented 6 months ago

This typically happens when your off-chain is not constructing the redeemer properly. Your plutus.json (generated by Aiken) tells you the structure of the expected redeemer.

Yeah, thanks for your answer. I fixed after I wrapped the redeemer correctly.