From 88c6dda56eae5d12f526b090f680df1b5920986d Mon Sep 17 00:00:00 2001 From: Guilherme Dantas Date: Sun, 14 Jul 2024 21:00:38 -0300 Subject: [PATCH] Remove "Blob" suffix in function names (#27) * Remove "Blob" at the end of function names * Adapted CLI to new @guidanoli/cmioc API --- .changeset/fresh-lamps-joke.md | 5 ++++ .changeset/proud-pumas-greet.md | 5 ++++ apps/cli/src/index.ts | 22 ++++++++---------- packages/core/src/index.ts | 8 +++---- packages/core/test/index.test.ts | 39 ++++++++++++++------------------ 5 files changed, 41 insertions(+), 38 deletions(-) create mode 100644 .changeset/fresh-lamps-joke.md create mode 100644 .changeset/proud-pumas-greet.md diff --git a/.changeset/fresh-lamps-joke.md b/.changeset/fresh-lamps-joke.md new file mode 100644 index 0000000..fa7831b --- /dev/null +++ b/.changeset/fresh-lamps-joke.md @@ -0,0 +1,5 @@ +--- +"@guidanoli/cmioc-cli": patch +--- + +Adapted to new @guidanoli/cmioc API diff --git a/.changeset/proud-pumas-greet.md b/.changeset/proud-pumas-greet.md new file mode 100644 index 0000000..f05669c --- /dev/null +++ b/.changeset/proud-pumas-greet.md @@ -0,0 +1,5 @@ +--- +"@guidanoli/cmioc": minor +--- + +Removed "Blob" at the end of function names diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts index 38ecb52..a009bb8 100644 --- a/apps/cli/src/index.ts +++ b/apps/cli/src/index.ts @@ -11,10 +11,10 @@ import { } from "viem"; import { - encodeInputBlob, - encodeOutputBlob, - decodeInputBlob, - decodeOutputBlob, + encodeInput, + encodeOutput, + decodeInput, + decodeOutput, Input, Notice, Voucher, @@ -151,7 +151,7 @@ encodeCommand .action((options) => { const input: Input = { ...options }; const { binary } = options; - writeHexToStdout(encodeInputBlob(input), binary); + writeHexToStdout(encodeInput(input), binary); }); encodeCommand @@ -172,7 +172,7 @@ encodeCommand .action((options) => { const voucher: Voucher = { type: "voucher", ...options }; const { binary } = options; - writeHexToStdout(encodeOutputBlob(voucher), binary); + writeHexToStdout(encodeOutput(voucher), binary); }); encodeCommand @@ -183,7 +183,7 @@ encodeCommand .action((options) => { const notice: Notice = { type: "notice", ...options }; const { binary } = options; - writeHexToStdout(encodeOutputBlob(notice), binary); + writeHexToStdout(encodeOutput(notice), binary); }); encodeCommand @@ -202,7 +202,7 @@ encodeCommand ...options, }; const { binary } = options; - writeHexToStdout(encodeOutputBlob(delegatecallvoucher), binary); + writeHexToStdout(encodeOutput(delegatecallvoucher), binary); }); const decodeCommand = program.command("decode"); @@ -216,9 +216,7 @@ decodeCommand .option("-b, --binary", "read from stdin as binary data", false) .action(async (blob, { binary }) => { try { - const input = decodeInputBlob( - blob ?? (await readHexFromStdin(binary)), - ); + const input = decodeInput(blob ?? (await readHexFromStdin(binary))); console.log(toJSON(input)); } catch (e) { handleError(e); @@ -232,7 +230,7 @@ decodeCommand .option("-b, --binary", "read from stdin as binary data", false) .action(async (blob, { binary }) => { try { - const output = decodeOutputBlob( + const output = decodeOutput( blob ?? (await readHexFromStdin(binary)), ); console.log(toJSON(output)); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index cd29773..2334e2f 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -13,7 +13,7 @@ export type Input = { payload: Hex; }; -export const encodeInputBlob = (input: Input): Hex => { +export const encodeInput = (input: Input): Hex => { const { chainId, appContract, @@ -43,7 +43,7 @@ export const encodeInputBlob = (input: Input): Hex => { return blob; }; -export const decodeInputBlob = (blob: Hex): Input => { +export const decodeInput = (blob: Hex): Input => { const { functionName, args } = decodeFunctionData({ abi: Inputs__factory.abi, data: blob, @@ -96,7 +96,7 @@ export type DelegateCallVoucher = { export type Output = Notice | Voucher | DelegateCallVoucher; -export const encodeOutputBlob = (output: Output): Hex => { +export const encodeOutput = (output: Output): Hex => { switch (output.type) { case "notice": { const { payload } = output; @@ -134,7 +134,7 @@ export const encodeOutputBlob = (output: Output): Hex => { } }; -export const decodeOutputBlob = (blob: Hex): Output => { +export const decodeOutput = (blob: Hex): Output => { const { functionName, args } = decodeFunctionData({ abi: Outputs__factory.abi, data: blob, diff --git a/packages/core/test/index.test.ts b/packages/core/test/index.test.ts index 8efb7f4..756806d 100644 --- a/packages/core/test/index.test.ts +++ b/packages/core/test/index.test.ts @@ -1,9 +1,4 @@ -import { - encodeInputBlob, - encodeOutputBlob, - decodeInputBlob, - decodeOutputBlob, -} from "../src"; +import { encodeInput, encodeOutput, decodeInput, decodeOutput } from "../src"; import { describe, expect, test } from "@jest/globals"; @@ -12,9 +7,9 @@ describe("decode/encode", () => { const blob = "0x415bf363000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070ac08179605af2d9e75782b8decdd3c22aa4d0c000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000129bbad00000000000000000000000000000000000000000000000000000000660195215a41539c3688747a1a8c7811b98b0427331ff73aab018eb5c9921993d617f314000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000"; - const input = decodeInputBlob(blob); + const input = decodeInput(blob); - expect(encodeInputBlob(input)).toEqual(blob); + expect(encodeInput(input)).toEqual(blob); expect(input.chainId).toEqual(1n); expect(input.appContract).toEqual( @@ -36,9 +31,9 @@ describe("decode/encode", () => { const blob = "0x415bf363000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070ac08179605af2d9e75782b8decdd3c22aa4d0c000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000129bbad00000000000000000000000000000000000000000000000000000000660195215a41539c3688747a1a8c7811b98b0427331ff73aab018eb5c9921993d617f314000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000"; - const input = decodeInputBlob(blob); + const input = decodeInput(blob); - expect(encodeInputBlob(input)).toEqual(blob); + expect(encodeInput(input)).toEqual(blob); expect(input.chainId).toEqual(1n); expect(input.appContract).toEqual( @@ -60,9 +55,9 @@ describe("decode/encode", () => { const blob = "0xc258d6e500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000"; - const output = decodeOutputBlob(blob); + const output = decodeOutput(blob); - expect(encodeOutputBlob(output)).toEqual(blob); + expect(encodeOutput(output)).toEqual(blob); switch (output.type) { case "notice": { @@ -78,9 +73,9 @@ describe("decode/encode", () => { const blob = "0xc258d6e500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"; - const output = decodeOutputBlob(blob); + const output = decodeOutput(blob); - expect(encodeOutputBlob(output)).toEqual(blob); + expect(encodeOutput(output)).toEqual(blob); switch (output.type) { case "notice": { @@ -96,9 +91,9 @@ describe("decode/encode", () => { const blob = "0x237a816f000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000003fafafa0000000000000000000000000000000000000000000000000000000000"; - const output = decodeOutputBlob(blob); + const output = decodeOutput(blob); - expect(encodeOutputBlob(output)).toEqual(blob); + expect(encodeOutput(output)).toEqual(blob); switch (output.type) { case "voucher": { @@ -118,9 +113,9 @@ describe("decode/encode", () => { const blob = "0x237a816f000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000"; - const output = decodeOutputBlob(blob); + const output = decodeOutput(blob); - expect(encodeOutputBlob(output)).toEqual(blob); + expect(encodeOutput(output)).toEqual(blob); switch (output.type) { case "voucher": { @@ -140,9 +135,9 @@ describe("decode/encode", () => { const blob = "0x10321e8b000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003fafafa0000000000000000000000000000000000000000000000000000000000"; - const output = decodeOutputBlob(blob); + const output = decodeOutput(blob); - expect(encodeOutputBlob(output)).toEqual(blob); + expect(encodeOutput(output)).toEqual(blob); switch (output.type) { case "delegatecallvoucher": { @@ -161,9 +156,9 @@ describe("decode/encode", () => { const blob = "0x10321e8b000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000"; - const output = decodeOutputBlob(blob); + const output = decodeOutput(blob); - expect(encodeOutputBlob(output)).toEqual(blob); + expect(encodeOutput(output)).toEqual(blob); switch (output.type) { case "delegatecallvoucher": {