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 a JSON abi from a .sw file #343

Merged
merged 32 commits into from Dec 14, 2021
Merged

Conversation

emilyaherbert
Copy link
Contributor

Closes #322

@emilyaherbert emilyaherbert self-assigned this Oct 29, 2021
@emilyaherbert emilyaherbert added the compiler General compiler. Should eventually become more specific as the issue is triaged label Oct 29, 2021
@sezna
Copy link
Contributor

sezna commented Nov 23, 2021

Is this ready to go? I see you've taken on two other tasks and this is still in draft mode, but tests are passing.

core_lang/src/lib.rs Outdated Show resolved Hide resolved
@emilyaherbert
Copy link
Contributor Author

This PR should be ready to go, aside from the implementation of a test suite. Given the example:

https://github.com/FuelLabs/sway/blob/master/test/src/e2e_vm_tests/test_programs/contract_abi_impl/src/main.sw.

the generate JSON abi is:

[
  {
    "inputs": [
      {
        "components": null,
        "name": "gas",
        "type": "u64"
      },
      {
        "components": null,
        "name": "coin",
        "type": "u64"
      },
      {
        "components": null,
        "name": "color",
        "type": "b256"
      },
      {
        "components": [
          {
            "components": null,
            "name": "field_1",
            "type": "bool"
          },
          {
            "components": null,
            "name": "field_2",
            "type": "u64"
          }
        ],
        "name": "input",
        "type": "struct InputStruct"
      }
    ],
    "name": "foo",
    "outputs": [
      {
        "components": [
          {
            "components": null,
            "name": "field_1",
            "type": "bool"
          },
          {
            "components": null,
            "name": "field_2",
            "type": "u64"
          }
        ],
        "name": "",
        "type": "struct InputStruct"
      }
    ],
    "type": "function"
  },
  {
    "inputs": [
      {
        "components": null,
        "name": "gas",
        "type": "u64"
      },
      {
        "components": null,
        "name": "coin",
        "type": "u64"
      },
      {
        "components": null,
        "name": "color",
        "type": "b256"
      },
      {
        "components": null,
        "name": "input",
        "type": "bool"
      }
    ],
    "name": "baz",
    "outputs": [
      {
        "components": null,
        "name": "",
        "type": "()"
      }
    ],
    "type": "function"
  }
][
  {
    "inputs": [
      {
        "components": null,
        "name": "gas",
        "type": "u64"
      },
      {
        "components": null,
        "name": "coin",
        "type": "u64"
      },
      {
        "components": null,
        "name": "color",
        "type": "b256"
      },
      {
        "components": [
          {
            "components": null,
            "name": "field_1",
            "type": "bool"
          },
          {
            "components": null,
            "name": "field_2",
            "type": "u64"
          }
        ],
        "name": "input",
        "type": "struct InputStruct"
      }
    ],
    "name": "foo",
    "outputs": [
      {
        "components": [
          {
            "components": null,
            "name": "field_1",
            "type": "bool"
          },
          {
            "components": null,
            "name": "field_2",
            "type": "u64"
          }
        ],
        "name": "",
        "type": "struct InputStruct"
      }
    ],
    "type": "function"
  },
  {
    "inputs": [
      {
        "components": null,
        "name": "gas",
        "type": "u64"
      },
      {
        "components": null,
        "name": "coin",
        "type": "u64"
      },
      {
        "components": null,
        "name": "color",
        "type": "b256"
      },
      {
        "components": null,
        "name": "input",
        "type": "bool"
      }
    ],
    "name": "baz",
    "outputs": [
      {
        "components": null,
        "name": "",
        "type": "()"
      }
    ],
    "type": "function"
  }
]

Copy link
Contributor

@sezna sezna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good, I like the way we are testing this on every test case. Left a few nits.

forc/src/abi_spec/type_info.rs Outdated Show resolved Hide resolved
core_lang/src/lib.rs Outdated Show resolved Hide resolved
@AlicanC
Copy link
Contributor

AlicanC commented Nov 29, 2021

I tried this last week and it worked well 👏 👏 👏

@emilyaherbert emilyaherbert marked this pull request as ready for review November 30, 2021 00:29
Copy link
Contributor

@adlerjohn adlerjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a failing e2e test

Copy link
Contributor

@sezna sezna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just the naming thing then i think it is good to go

Copy link
Contributor

@sezna sezna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do ittttt

@emilyaherbert emilyaherbert merged commit a3617ef into master Dec 14, 2021
@emilyaherbert emilyaherbert deleted the emilyaherbert-322-2/json-abi branch December 14, 2021 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate a JSON ABI from a .sw abi
4 participants