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

Enhance ManifestCoder for Encoding/Decoding Routine Arguments and Returned Values #81

Merged
merged 14 commits into from
Oct 24, 2024

Conversation

sarvalabs-harshrastogi
Copy link
Member

Enhance ManifestCoder for Encoding/Decoding Routine Arguments and Returned Values

Important

This pull request has breaking changes

This pull request enhances the ManifestCoder class by introducing new methods and improvements to existing ones. These changes aim to simplify the process of encoding and decoding routine arguments and returned values, improving the overall developer experience.

Changes:

  1. ElementDescriptor:

    • The ElementDescriptor class has been relocated from js-moi-logic to js-moi-manifest.
    • Developers can now instantiate an ElementDescriptor object with a manifest object, providing more flexibility and integration with the manifest data.
  2. ManifestCoder:

    • This constructor method now accepts a manifest of type LogicManifest.Manifest as input. (Breaking Change)
  3. Manifest.encodeArguments:

    • This method now supports extracting routine type fields from arguments based on the routine name.
    • It can encode arguments into the POLO format, simplifying the developer experience.
    • The existing functionality remains unaffected, ensuring backward compatibility.
const manifest = await loadManifestFromFile("../../manifests/tokenledger.json");
const manifestCoder = new ManifestCoder(manifest);
const args = ["MOI", 100_000_000];
const calldata = manifestCoder.encodeArguments("Seeder", args);
console.log(calldata) // >>> 0x0d6f0665b6019502737570706c790305f5e10073796d626f6c064d4f49
  1. ManifestCoder.decodeArguments:
    • This new method enables extracting the type of the returned value from a routine.
    • It can decode the POLO output passed as an argument, facilitating the processing of routine results.
const manifest = await loadManifestFromFile("../../manifests/tokenledger.json");
const manifestCoder = new ManifestCoder(manifest);
const outputSerialized = "0x0e1f0305f5e100";
const callsite = "BalanceOf";
const output = manifestCoder.decodeOutput<{ balance: number }>(outputSerialized, callsite);

console.log(output) // >>> { balance: 100000000 }

These changes streamline the process of working with routine arguments and returned values within the ManifestCoder class.

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)

Checklist

  • I have assigned this PR to myself
  • I have added at least 1 reviewer
  • I have tested this code
  • I have updated the README and other relevant documents (guides...)

@sarvalabs-harshrastogi sarvalabs-harshrastogi added manifest Issues related to manifest logic Module to interact with MOI Logic Objects breaking labels Aug 22, 2024
@sarvalabs-harshrastogi sarvalabs-harshrastogi changed the base branch from main to develop August 22, 2024 07:32
docs/source/manifest-call-encoder.rst Show resolved Hide resolved
docs/source/manifest-call-encoder.rst Outdated Show resolved Hide resolved
packages/js-moi-manifest/__tests__/abi.test.ts Outdated Show resolved Hide resolved
Copy link

cloudflare-workers-and-pages bot commented Sep 24, 2024

Deploying js-moi-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 412c7cc
Status: ✅  Deploy successful!
Preview URL: https://a707c507.js-moi-sdk.pages.dev
Branch Preview URL: https://refactor-manifest-coder.js-moi-sdk.pages.dev

View logs

@sarvalabs-harshrastogi sarvalabs-harshrastogi merged commit a5acbd5 into develop Oct 24, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking logic Module to interact with MOI Logic Objects manifest Issues related to manifest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Encode/Decode Argument and Returned Values
2 participants