HeliosLang / compiler

Helios is a DSL for writing Cardano smart contracts. This library lets you compile Helios scripts and build Cardano transactions.
https://www.hyperion-bt.org/helios-book
BSD 3-Clause "New" or "Revised" License
142 stars 31 forks source link

UserError: TypeError on line 1: expected delayed value, got 'fn' #46

Closed gavinharris-dev closed 1 year ago

gavinharris-dev commented 1 year ago

The below scenario is doing the following:

  1. List an Asset at a Contract address
  2. Using the Smart Contract, allow a user to spend the UTxO

The contract is not generated by Helios and seems to be using functionality that is as yet not supported.

import {
  Address,
  Assets,
  Datum,
  hexToBytes,
  MintingPolicyHash,
  NetworkEmulator,
  NetworkParams,
  Program,
  Tx,
  TxOutput,
  UplcData,
  UplcProgram,
  Value,
} from '@hyperionbt/helios';

async function test() {
  const contractCbor =
    '590a015909fe010000323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232222323232533535533357346064606a0062646464642466002008004a666ae68c0d8c0e00044c848c004008c078d5d0981b8008191baa357426ae88c0d80154ccd5cd1819981b0008991919191919191919191919191919191919191919190919999999999980080b80a8098088078068058048038028018011aba135744004666068eb88004d5d08009aba2002357420026ae88008cc0c9d71aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011981300f1aba1001357440046ae84004d5d1181b001198111192999ab9a30353038001132321233001003002301d357426ae88c0e0008c078d5d0981b8008191baa00135742606a0020606ea8d5d0981a001817911a8011111111111111a80691919299aa99a998149aa99a80109815a481035054380022100203d00303903a03a1533501213302549101350033302330340362350012232333027303803a235001223500122533533302b0440040062153353333026303e040223500222533500321533533303104a0030062153353302b0010031303f3305722533500104c221350022253353305100200a100313304d33047002001300600300215335330370010031303f333302d04b0043370200200600409209008e60720020044266060920102313000333573466e20ccd54c0fc104c0a8cc0f1c024000400266aa608008246a00209600200809208e266ae712410231310004813357389201023132000470023335530360393501b0403501b04233355303603922533535002222253353302200800413038003042213303d001002100103f010333301c303403622350022253353303c00b002100313333020303803a235001222533533302a0210030012133330260220043355303e03f235001223303d002333500120012235002223500322330433370000800466aa608e09046a002446608c004666a0024002e008004ccc0c013400c0048004ccc09c11000c0040084cccc09408400c00800400c0040f140044cc0952410134003330233034036235001223303b00a0025001153353355303403523500122350012222302c533350021303104821001213304e2253350011303404a221350022253353304800200710011300600300c0011302a49010136002213355303603723500122350012222302e533350021303304a2100121330502253350011303604c221350022253353304a00200710011300600300e0033335530310342253353353530283500203f03d203f253353303c001330482253350011302e044221350022253353303000200a135302f001223350022303504b20011300600301003b1302c4901013300133037002001100103a00d1120011533573892010350543500165333573460640020502a666ae68c0c400409c0b8c0ccdd50019baa00133019223355301f020235001223301e002335530220232350012233021002333500137009000380233700002900000099aa980f81011a800911980f001199a800919aa981181211a8009119811001180880080091199806815001000919aa981181211a80091198110011809000800999804012801000812111919807198021a8018139a801013a99a9a80181490a99a8011099a801119a80111980400100091101711119a80210171112999ab9a3370e00c0062a666ae68cdc38028010998068020008158158120a99a80090120121a8008141119a801119a8011198128010009014119a801101411981280100091199ab9a3370e00400204604a44446666aa00866032444600660040024002006002004444466aa603803a46a0024466036004666a0024002052400266600a0080026603c66030006004046444666aa603003603866aa603403646a00244660320046010002666aa6030036446a00444a66a666aa603a03e60106603444a66a00404a200204e46a002446601400400a00c200626604000800604200266aa603403646a00244660320046605e44a66a002260160064426a00444a66a6601800401022444660040140082600c00600800446602644666a0060420040026a00204242444600600842444600200844604e44a66a0020364426a00444a66a6601000400e2602a0022600c0064466aa0046602000603600244a66a004200202e44a66a00202e266ae7000806c8c94ccd5cd180f9811000899190919800801801198079192999ab9a3022302500113232123300100300233301075c464a666ae68c094c0a00044c8cc0514cd4cc028005200110011300e4901022d330033301375c464a66a660180029000080089808249022d3200375a0026ae84d5d118140011bad35742604e0020446ea8004d5d09aba23025002300c35742604800203e6ea8004d5d09aba23022002375c6ae84c084004070dd500091199ab9a3371200400203202e46a002444400844a666ae68cdc79a80100b1a80080b0999ab9a3370e6a0040306a00203002a02e024464a666ae68c06cc0780044c8c8c8c8c8c8c8c848cccc00402401c00c008d5d09aba20045333573466e1d2004001132122230020043574260460042a666ae68c0880044c84888c004010dd71aba1302300215333573460420022244400603c60460026ea8d5d08009aba200233300a75c66014eb9d69aba100135744603c004600a6ae84c074004060dd50009299ab9c001162325333573460326038002264646424660020060046eb4d5d09aba2301d003533357346034603a00226eb8d5d0980e00080b9baa35742603600202c6ea80048c94ccd5cd180c180d80089919191909198008028012999ab9a301b00113232300953335734603c00226464646424466600200c0080066eb4d5d09aba2002375a6ae84004d5d118100019bad35742603e0042a666ae68c0740044c8488c00800cc020d5d0980f80100d180f8009baa35742603a0042a666ae68c070004044060c074004dd51aba135744603600460066ae84c068004054dd5000919192999ab9a30190011321223001003375c6ae84c06800854ccd5cd180c00089909118010019bae35742603400402a60340026ea80048488c00800c888cc06888cccd55cf800900911919807198041803980e8009803180e00098021aba2003357420040166eac0048848cc00400c00888cc05c88cccd55cf800900791980518029aba10023003357440040106eb0004c05088448894cd40044008884cc014008ccd54c01c028014010004c04c88448894cd40044d400c040884ccd4014040c010008ccd54c01c024014010004c0488844894cd4004024884cc020c010008cd54c01801c0100044800488488cc00401000cc03c8894cd40080108854cd4cc02000800c01c4cc01400400c4014400888ccd5cd19b8f0020010030051001220021001220011533573892010350543100164901022d31004901013700370e90001b874800955cf2ab9d2323001001223300330020020011';

  const program = UplcProgram.fromCbor(hexToBytes(contractCbor));

  const network = new NetworkEmulator();

  const assets = new Assets();

  assets.addComponent(
    MintingPolicyHash.fromHex(
      '16aa5486dab6527c4697387736ae449411c03dcd20a3950453e6779c'
    ),
    Array.from(new TextEncoder().encode('PodgyPenguin1047')),
    BigInt(1)
  );

  const alice = network.createWallet(BigInt(100_000_000), assets);
  const bruce = network.createWallet(BigInt(100_000_000));

  const contractAddress = Address.fromValidatorHash(program.validatorHash);

  network.tick(BigInt(10));

  // Create the Listing Transaction
  const tx = new Tx();

  const utxo = await network.getUtxos(alice.address);

  console.log(alice.pubKeyHash.hex, alice.address.stakingHash?.hex);

  tx.addInput(utxo[0]);

  const datum = Datum.inline(
    UplcData.fromCbor(
      hexToBytes(
        'd8799f581c8edd1bf0def91edf9c47e02363249668825deb7d5c8374f9fde2834d9fd8799fd8799fd8799f581c8edd1bf0def91edf9c47e02363249668825deb7d5c8374f9fde2834dffd87a80ffa140d8799f00a1401a000f4240ffffffff'
      )
    )
  );

  tx.addOutput(
    new TxOutput(contractAddress, new Value(BigInt(2_000_000), assets), datum)
  );

  const networkParams = new NetworkParams(
    await fetch('https://d1t0d7c2nekuk0.cloudfront.net/preview.json').then(
      (response) => response.json()
    )
  );

  const builtTx = await tx.finalize(networkParams, alice.address);

  const signatures = await alice.signTx(tx);

  console.log(signatures);

  builtTx.addSignatures(signatures);

  const txId = await network.submitTx(builtTx);
  network.tick(BigInt(10));

  const contractUtxo = (await network.getUtxos(contractAddress))[0];

  const purchaseTx = new Tx();

  const bruceUtxos = await network.getUtxos(bruce.address);

  const prog = Program.new(DATUM_AND_REDEEMER);
  const accept = prog.evalParam('REDEEMER_ACCEPT');

  const aliceOutput = new TxOutput(alice.address, new Value(BigInt(1_000_000)));

  purchaseTx
    .addInput(contractUtxo, accept.data)
    .addInput(bruceUtxos[0])
    .addOutput(aliceOutput)
    .addCollateral(bruceUtxos[0])
    .attachScript(program);

  const purchaseTxFinal = await purchaseTx.finalize(
    networkParams,
    bruce.address
  );

  const purchaseTxSignatures = await bruce.signTx(purchaseTx);
  purchaseTxFinal.addSignatures(purchaseTxSignatures);

  await network.submitTx(purchaseTxFinal);
  network.tick(BigInt(10));
}

test().then(console.log).catch(console.error);

const DATUM_AND_REDEEMER = `
spending dropspotmarket

struct SwapAddress {
  sAddressCredential: Credential
  sAddressStakingCredential: Option[StakingCredential]
}

struct Thing {
  a: Int
  b: Map[ByteArray]Int
}
struct Oh {
  a: []Thing
}

struct Payout {
  pAddress: SwapAddress
  pValue: Map [ MintingPolicyHash ] Oh
}

struct Swap {
  sOwner : PubKeyHash
  sSwapPayouts : []Payout
}

struct Datum {
  swaps: []Swap
}

enum Redeemer {
  Cancel
  Accept
}

func main() -> Bool {
  true
}

const REDEEMER_CANCEL = Redeemer::Cancel {}
const REDEEMER_ACCEPT = Redeemer::Accept {}

const OWNER_BYTES = #cb9358529df4729c3246a2a033cb9821abbfd16de4888005904abc41
const OWNER_BYTES2 = #cb9358529df4729c3246a2a033cb9821abbfd16de4888005904abc41
const AMOUNT: Int = 10000000
const pkh: PubKeyHash = PubKeyHash::new(OWNER_BYTES2)

const SWAP = Swap {
  sOwner: PubKeyHash::new(OWNER_BYTES),
  sSwapPayouts: []Payout { 
    Payout {
      pAddress: SwapAddress {
        sAddressCredential: Credential::new_pubkey(PubKeyHash::new(#cb9358529df4729c3246a2a033cb9821abbfd16de4888005904abc41)),
        sAddressStakingCredential: Option[StakingCredential]::None
      },
      pValue: Map[MintingPolicyHash]Oh {
        MintingPolicyHash::new(#): Oh {
          a: []Thing {
            Thing {
              a: 0,
              b: Map[ByteArray]Int{#: 10000000}
            }
          }
        }
      }
    }
  }
}

const DATUM: Datum = Datum {
  swaps: []Swap { SWAP }
}
`;

/*

spending parameterizea

struct VestingParam {
  beneficiary: PubKeyHash 
  deadline: Time
}

const BENEFICIARY = #
const TIME: Int = 7000

const params - VestingParam {beneficiary: PubKeyHash: :new (BENEFICIARY), deadline: Time: :new (TIME)}

func main (ct:ScriptContext) -> Bool {
  now: Time = ct.tx.time_range.start;
  tx.tx.is_signed_by (params .beneficiary) . trace("You are not the beneficiary") && (now › params.deadline). trace ("Deadline not reached")
}

*/
/*

sAddressStakingCredential: Option[StakingCredential]::Some{
          StakingCredential::new_hash(
            StakingHash::new_stakekey(
              StakeKeyHash::new(#51978db90b5c0fdf7f2d38fcad1a5c42a98b2ddef0dfa16034e16d2b)
            )
          )
        }
*/
nielstron commented 1 year ago

Is the contract by any chance written in PlutusTx? j am facing the same error

christianschmitz commented 1 year ago

I believe v0.13.1 fixes this. chooseList was missing a delay/force

gavinharris-dev commented 1 year ago

Going to be looking into this again quite soon so will provide an update based on Helios 14+

gavinharris-dev commented 1 year ago

This is now fixed and verified against the contract I was testing with. Thank you!!