Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate fcl-js binding files #8

Open
4 of 8 tasks
bthaile opened this issue Aug 10, 2023 · 3 comments
Open
4 of 8 tasks

Generate fcl-js binding files #8

bthaile opened this issue Aug 10, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@bthaile
Copy link
Contributor

bthaile commented Aug 10, 2023

Given a interactive template (flix) need to create binding files. Task should address local development.

In current Cadence vs code project structure, bindings files can be generated to "bindings" folder by default.
For CLI configuration user passes in "Cadence" folder and all transactions and scripts will be discovered and templates generated to "templates" directory and binding generated to "bindings" folder.

Tasks:

Sub Tasks:

  • verify parameters have not changed at run time
    • FLIX template file is pulled in at runtime.
    • Bindings only need to change if arguments changed or contract addresses.
  • Handle structs as arguments
  • Handle complex built-in Cadence types

Note:

Reference: Cadut uses handlebar templates to generate javascript files.

Binding should have a hash template interface (arguments) and verify the hash has not changed at runtime.

Example javascript binding that uses a URL to flix

import * as fcl from @onflow/fcl

const params =  { "amount": "UFix64", "to": "Address"}
const templateURL = "https://flix.flow.com/v1/templates?name=transfer-flow"

export async function TemplateName({to, amount }) {
  // check argument hash
  let hashMatches = false;
  let hasError = false;
  try {
        const response = await fetch(templateURL);
        // Check if the request was successful
        if (response.ok) {
          const templateData = await response.json();  // Convert response to JSON
          doesMatches = matchParams(templateData.parameters, params)
        } else {
          throw new Error(`Failed to fetch: ${response.status} ${response.statusText}`);
        }
   } catch (error) {
      console.error(error)  // need better way to convey errors than console log and eat
      hasError = true
  } 
  if (!doesMatches) return 
   return request({to, amount});
}

async function request({ to, amount }) {
  const transactionId = await fcl.mutate({
    template: templateURL,
    args: (arg, t) => ([ arg(to, t.Address), arg(amount, t.UFix64)])
  })

  return transactionId
}
@bthaile bthaile changed the title [Improvement] Generate javascript and typescript bindings Generate javascript and typescript bindings Aug 10, 2023
@bthaile bthaile added the enhancement New feature or request label Aug 10, 2023
@chasefleming
Copy link
Member

I'm not sure TS or JS bindings should be generated in this library. I'm wondering if this should be a separate lib (maybe even a TS lib).

@bjartek
Copy link
Collaborator

bjartek commented Sep 1, 2023

Go has the ability to parse the program and get out information from it so i think go is the right choixe here. The code should also support generating go bindings.

@bthaile
Copy link
Contributor Author

bthaile commented Sep 5, 2023

@chasefleming I was thinking this flixkit-go would be all things flix.

  • running flix
  • generating flix
  • migrating versions
  • generating binding files
    • js
    • ts
    • go

Also, my thinking was that flow-cli is already bringing in this lib to do flix stuff.

@bthaile bthaile changed the title Generate javascript and typescript bindings Generate fcl-js binding files Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants