Giter Club home page Giter Club logo

take-home's Introduction

Documentation

How To Run

Go into the off-chain folder

cd off-chain

Install dependencies

npm i

Run the tests. Make sure you are running Node Version 19 and above

npm run test

Overview

To ensure that only the owner of the UTxO can consume it we need to check if the transaction is signed by the owner. We will store it in the datum of the UTxO and the smart contract simply needs to check that the signature is in the transaction to approve it.

On-Chain

The validator looks for the signtures in the transaction and compares it with the owner pub key hash in the datum

let must_be_signed_by_owner =
    list.has(ctx.transaction.extra_signatories, datum.owner_address_hash)
must_be_signed_by_owner

Off-chain

Create a function that gets all available UTxOs locked up in the contract by the owner.

export async function getOwnerUTxOsAtScript(
  ownerPubKeyHash: string,
  lucid: Lucid
) {
  const { validatorAddress } = getValidators(lucid);
  const utxos = await lucid.utxosAt(validatorAddress);

  const availableOffers = utxos.filter((utxo) => {
    try {
      const datum = Data.castFrom(
        Data.from(utxo.datum as string),
        OwnerConsumeDatum
      );
      return datum.ownerPubKeyHash === ownerPubKeyHash;
    } catch (error) {
      return false;
    }
  });

  return availableOffers;
}

The function to consume the transaction will take in two parameters. One of the UTxOs that can be consumed and the other owner public key hash. The function needs to make sure it has added the owner's signature to the transaction.

take-home's People

Contributors

shan501 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.