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

chore!: internalize old JsonAbi format #2862

Merged
merged 42 commits into from
Aug 5, 2024

Conversation

nedsalk
Copy link
Contributor

@nedsalk nedsalk commented Jul 30, 2024

Note

This PR merges into #2856.

Summary

  1. All public-facing APIs are taking in the new JsonAbi type instead of the old one, which has been renamed to JsonAbiOld.
  2. Transpilation happens on the Interface level and is an internal detail. Typegen includes the new abi format in its generated code and doesn't transpile it.
  3. AbiCoder is no longer exported and its functionality has been added to Interface via encodeType/decodeType methods (ee734b9).
  4. Removed Interface.findTypeById method in 157bdba because the concept of a type in the new abi differs from the old one. Whoever wants to get a specific type, be it a concrete or metadata type, can do so directly from the abi that they have on the Interface.jsonAbi property.

Breaking Changes

AbiCoder is no longer available to import

AbiCoder is no longer exported and the way to do encoding and decoding of specific types is now via the Interface.encodeType and Interface.decodeType methods:

// before
const abi = yourAbi;
const functionArg = abi.functions.inputs[0];

const encoded = AbiCoder.encode(abi, functionArg, valueToEncode);
const decoded = AbiCoder.decode(abi, functionArg, valueToDecode, 0);
// after
const abi = yourAbi;
const functionArg = abi.functions.inputs[0];

const abiInterface = new Interface(abi);

const encoded = abiInterface.encodeType(functionArg.concreteTypeId, valueToEncode);
const decoded = abiInterface.decodeType(functionArg.concreteTypeId, valueToDecode);

Interface.findTypeById has been removed

Previously, you could get a type from the abi via the Interface.findTypeById. This method has been removed after introduction of the new abi specification because the concept of a type has been split into concrete types and metadata types. If you want a specific type, you can get it from the abi directly.

// before
const abiInterface = new Interface(abi);

// internally this method searched the abi types:
// abi.types.find(t => t.typeId === id);
const type = abiInterface.findTypeById(id);
// after
// search the types on the abi directly
const concreteType = abi.concreteTypes.find(ct => ct.concreteTypeId === id);
const metadataType = abiInterface.jsonAbi.metadataTypes.find(mt => mt.metadataTypeId === id);

JsonAbiArgument is no longer exported

The JsonAbiArgument type isn't part of the new ABI spec (#596, #599) as such so we stopped exporting it. Its closest equivalent now would be a concrete type because it fully defines a type.

// before
const arg: JsonAbiArgument = {...};
// after
type ConcreteType = JsonAbi["concreteTypes"][number]
const arg: ConcreteType = {...};

Checklist

  • I addedtests to prove my changes
  • I updated — all the necessary docs
  • I reviewed — the entire PR myself, using the GitHub UI
  • I described — all breaking changes and the Migration Guide

@nedsalk nedsalk added the chore Issue is a chore label Jul 30, 2024
@nedsalk nedsalk self-assigned this Jul 30, 2024
Copy link
Contributor

@petertonysmith94 petertonysmith94 left a comment

Choose a reason for hiding this comment

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

May be worth adding to the breaking changes the removal of the JsonAbiArgument type.

I did a pretty rigorous review of what is exposed publicly and I'm happy with this now - nice one 🍏

arboleya

This comment was marked as resolved.

arboleya

This comment was marked as resolved.

Co-authored-by: Anderson Arboleya <anderson@arboleya.me>
nedsalk and others added 2 commits August 2, 2024 15:13
Co-authored-by: Anderson Arboleya <anderson@arboleya.me>
Co-authored-by: Anderson Arboleya <anderson@arboleya.me>
@petertonysmith94
Copy link
Contributor

@nedsalk @arboleya this looks ready to go now - shall we get this merged into aa/feat/adding-abi-transpiler?

@arboleya arboleya merged commit 942e5cc into aa/feat/adding-abi-transpiler Aug 5, 2024
15 of 17 checks passed
@arboleya arboleya deleted the ns/feat/adding-abi-transpiler branch August 5, 2024 09:53
arboleya added a commit that referenced this pull request Aug 19, 2024
* Upgrading forc to temp branch

* Adding ABI transpiler and integrating it with related areas

* Updating typegen fixtures

* Fixing broken typegen tests; updating outdated IDs

* Re-instating the order

* Loading forc projects the standard and proper way

* Updating coder’s types, regexes, and fixing type matching everywhere

* Updating test using callpath-based naming for Option

* Fixing test, intercepting ABI loading so it can be transpiled

* Adding changeset

* Adjusting changeset

* Excluding sway-repo source files in `forc:check` script

* Ensuring branches are up to date before building

* Building internal packages in `--release` mode

* Fixing directory path for new build target

* Merging duplicated variables, standardizing terminologies

* Improving validation to handle strings / non-objects as well

* fix: option coder decoding incorrect value (#2870)

* Revert "Improving validation to handle strings / non-objects as well"

This reverts commit 45f3ef2.

* chore: fixing types on OptionCoder

* fix: match full qualifying type name with regex

* chore: added test groups

Co-authored-by: Daniel Bate <djbate23@gmail.com>

* chore: revert StructCoder name change

---------

Co-authored-by: Daniel Bate <djbate23@gmail.com>

* Standardizing timeout limits across workflows

* Ignoring `sway-repo`in links check  when building things from source

* Fixing ignore path

* Stop deleting `concreteTypeId`, used in public API

* Update .changeset/odd-horses-cheer.md

* Ignoring also `fuel-core-repo` for the same reasons as `sway-repo`

* Update .changeset/odd-horses-cheer.md

* Updating more fixtures

* Updating snippet

* Fixing random lint warning

* Incrasing test timeout limit

* Fixing ignored paths

* chore!: internalize old `JsonAbi` format (#2862)

* use `transpileAbi` in `Interface`

* add new interfaces to typegen

* no need for `debug` build anymore

* fix `getTypegenForcProject` return type

* added `as JsonAbi` type assertions to fix type errors

* fix typegen tests

* rename variable

* stop exporting `JsonAbi` from typegen

* revert changes that should be in another PR

* contttinue exporting

* rename to match `master`

* fix encode-and-decode test

* Renamed `JsonAbiNew` to `JsonAbi` and the old format to `JsonAbiOld`

* fix compilation errors

* Stop exporting `AbiCoder` and update `encode-and-decode` example

* Removed `Interface.findTypeById` method

* stop casting `as unknown as JsonAbi`

* use `argument` directly

* fix import

* fix: `Interface.encodeType/decodeType`

* Update packages/abi-coder/src/types/JsonAbi.ts

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* Update packages/abi-coder/src/types/JsonAbiNew.ts

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* Update packages/abi-typegen/src/types/interfaces/JsonAbi.ts

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* Update packages/account/test/fuel-wallet-connector.test.ts

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* Update packages/abi-typegen/src/utils/transpile-abi.ts

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* copy/paste transpile-abi

* fix compilation error

* eslint disable todo type

* use `{ transpile: T }` params object

* update `encode-and-decode.md` docs

* fix: spellcheck

* Update apps/docs/src/guide/encoding/encode-and-decode.md

Co-authored-by: Anderson Arboleya <anderson@arboleya.me>

* Update apps/docs/src/guide/encoding/encode-and-decode.md

Co-authored-by: Anderson Arboleya <anderson@arboleya.me>

* Update apps/docs/src/guide/encoding/encode-and-decode.md

Co-authored-by: Anderson Arboleya <anderson@arboleya.me>

---------

Co-authored-by: Anderson Arboleya <anderson@arboleya.me>
Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* Getting around non-null assertions

* Adjusting changeset

* Adjusting scripts

* Updating template fixtures/snapshots

* Triggering CI

* The branch is gone - temporarily switching to `master`

* Temporarily patching sway std lib

* Temporarily skipping problematic sway projects and related tests

* Lintfix - deprecations, types mismatch, and broken imports

* DRYing test setup/teardown

* Fixing broken tests

* Patching base library individually

* Unskipping problematic workspace members

* Adjusting predicate data handling

* Undoing undesired changed

* Adjuting more projects

* Revert "Temporarily skipping problematic sway projects and related tests"

This reverts commit dc054ff.

* Formatting

* Revert "Temporarily patching sway std lib"

This reverts commit 48b0ab3.

* Revert "Patching base library individually"

This reverts commit b97c944.

* Replacing sway `branch` by `0.63.0` version

* Update .changeset/odd-horses-cheer.md

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* Updating forc version

---------

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>
Co-authored-by: Nedim Salkić <nedim.salkic@fuel.sh>
Co-authored-by: Daniel Bate <djbate23@gmail.com>
maschad pushed a commit that referenced this pull request Aug 21, 2024
* Upgrading forc to temp branch

* Adding ABI transpiler and integrating it with related areas

* Updating typegen fixtures

* Fixing broken typegen tests; updating outdated IDs

* Re-instating the order

* Loading forc projects the standard and proper way

* Updating coder’s types, regexes, and fixing type matching everywhere

* Updating test using callpath-based naming for Option

* Fixing test, intercepting ABI loading so it can be transpiled

* Adding changeset

* Adjusting changeset

* Excluding sway-repo source files in `forc:check` script

* Ensuring branches are up to date before building

* Building internal packages in `--release` mode

* Fixing directory path for new build target

* Merging duplicated variables, standardizing terminologies

* Improving validation to handle strings / non-objects as well

* fix: option coder decoding incorrect value (#2870)

* Revert "Improving validation to handle strings / non-objects as well"

This reverts commit 45f3ef2.

* chore: fixing types on OptionCoder

* fix: match full qualifying type name with regex

* chore: added test groups

Co-authored-by: Daniel Bate <djbate23@gmail.com>

* chore: revert StructCoder name change

---------

Co-authored-by: Daniel Bate <djbate23@gmail.com>

* Standardizing timeout limits across workflows

* Ignoring `sway-repo`in links check  when building things from source

* Fixing ignore path

* Stop deleting `concreteTypeId`, used in public API

* Update .changeset/odd-horses-cheer.md

* Ignoring also `fuel-core-repo` for the same reasons as `sway-repo`

* Update .changeset/odd-horses-cheer.md

* Updating more fixtures

* Updating snippet

* Fixing random lint warning

* Incrasing test timeout limit

* Fixing ignored paths

* chore!: internalize old `JsonAbi` format (#2862)

* use `transpileAbi` in `Interface`

* add new interfaces to typegen

* no need for `debug` build anymore

* fix `getTypegenForcProject` return type

* added `as JsonAbi` type assertions to fix type errors

* fix typegen tests

* rename variable

* stop exporting `JsonAbi` from typegen

* revert changes that should be in another PR

* contttinue exporting

* rename to match `master`

* fix encode-and-decode test

* Renamed `JsonAbiNew` to `JsonAbi` and the old format to `JsonAbiOld`

* fix compilation errors

* Stop exporting `AbiCoder` and update `encode-and-decode` example

* Removed `Interface.findTypeById` method

* stop casting `as unknown as JsonAbi`

* use `argument` directly

* fix import

* fix: `Interface.encodeType/decodeType`

* Update packages/abi-coder/src/types/JsonAbi.ts

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* Update packages/abi-coder/src/types/JsonAbiNew.ts

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* Update packages/abi-typegen/src/types/interfaces/JsonAbi.ts

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* Update packages/account/test/fuel-wallet-connector.test.ts

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* Update packages/abi-typegen/src/utils/transpile-abi.ts

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* copy/paste transpile-abi

* fix compilation error

* eslint disable todo type

* use `{ transpile: T }` params object

* update `encode-and-decode.md` docs

* fix: spellcheck

* Update apps/docs/src/guide/encoding/encode-and-decode.md

Co-authored-by: Anderson Arboleya <anderson@arboleya.me>

* Update apps/docs/src/guide/encoding/encode-and-decode.md

Co-authored-by: Anderson Arboleya <anderson@arboleya.me>

* Update apps/docs/src/guide/encoding/encode-and-decode.md

Co-authored-by: Anderson Arboleya <anderson@arboleya.me>

---------

Co-authored-by: Anderson Arboleya <anderson@arboleya.me>
Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* Getting around non-null assertions

* Adjusting changeset

* Adjusting scripts

* Updating template fixtures/snapshots

* Triggering CI

* The branch is gone - temporarily switching to `master`

* Temporarily patching sway std lib

* Temporarily skipping problematic sway projects and related tests

* Lintfix - deprecations, types mismatch, and broken imports

* DRYing test setup/teardown

* Fixing broken tests

* Patching base library individually

* Unskipping problematic workspace members

* Adjusting predicate data handling

* Undoing undesired changed

* Adjuting more projects

* Revert "Temporarily skipping problematic sway projects and related tests"

This reverts commit dc054ff.

* Formatting

* Revert "Temporarily patching sway std lib"

This reverts commit 48b0ab3.

* Revert "Patching base library individually"

This reverts commit b97c944.

* Replacing sway `branch` by `0.63.0` version

* Update .changeset/odd-horses-cheer.md

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>

* Updating forc version

---------

Co-authored-by: Peter Smith <peter@blueoceancomputing.co.uk>
Co-authored-by: Nedim Salkić <nedim.salkic@fuel.sh>
Co-authored-by: Daniel Bate <djbate23@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Issue is a chore
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants