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

Fetch schema #328

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Fetch schema #328

wants to merge 8 commits into from

Conversation

magnusbechwind
Copy link
Contributor

@magnusbechwind magnusbechwind commented Mar 13, 2024

Purpose

Add convenience method to exctract a Schema from a WasmModule if embedded.

Changes

I added the class LEB128U to encode/decode LEB128U encoded integers and refactored TokenAmount to use this.

I added the method getSchema to WasmModule that parses the underlying wasm bytes and exctract a Schema if found.

I added a test extracting a Schema and asserting it works.

Checklist

  • My code follows the style of this project.
  • The code compiles without warnings.
  • I have performed a self-review of the changes.
  • I have documented my code, in particular the intent of the
    hard-to-understand areas.
  • (If necessary) I have updated the CHANGELOG.

@magnusbechwind magnusbechwind self-assigned this Mar 13, 2024
@magnusbechwind magnusbechwind linked an issue Mar 13, 2024 that may be closed by this pull request
@magnusbechwind magnusbechwind marked this pull request as ready for review March 13, 2024 13:36
Copy link
Contributor

@abizjak abizjak left a comment

Choose a reason for hiding this comment

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

Looks pretty good. But I think we should add support for legacy schemas as well for completeness.

@@ -83,6 +86,17 @@ public static WasmModule from(final byte[] bytes) {
return from(moduleBytes, version);
}

/**
* Create {@link WasmModule} from compiled module WASM file. Passed module should have version prefixed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Clarify that this is the module format produced by cargo-concordium.

// We've incremented the buffer by reading the length of the name and the name.
remainingSectionLength = remainingSectionLength - nameLengthBytes - nameLength;

if (name.equals("concordium-schema")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In principle there are also concordium-schema-v1 and concordium-schema-v2 , see https://docs.rs/axum/latest/axum/struct.Router.html#method.fallback_service https://github.com/Concordium/concordium-base/blob/87a752f185869ea567387baac384e0e5bc997fd9/smart-contracts/wasm-chain-integration/src/utils.rs#L583

which would be great to support since the Schema class does as well as far as I understand.

The difference is that the concordium-schema section contains the schema that is versioned inside.

Whereas the new (old,legacy) -v1 and -v2 sections, the contents is the unversioned schema and the version is in the name (v0 and v1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support fetching a schema from a deployed module
2 participants