Skip to content

Commit

Permalink
Remove "Blob" suffix in function names (#27)
Browse files Browse the repository at this point in the history
* Remove "Blob" at the end of function names

* Adapted CLI to new @guidanoli/cmioc API
  • Loading branch information
guidanoli authored Jul 15, 2024
1 parent 5687164 commit 88c6dda
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-lamps-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@guidanoli/cmioc-cli": patch
---

Adapted to new @guidanoli/cmioc API
5 changes: 5 additions & 0 deletions .changeset/proud-pumas-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@guidanoli/cmioc": minor
---

Removed "Blob" at the end of function names
22 changes: 10 additions & 12 deletions apps/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
} from "viem";

import {
encodeInputBlob,
encodeOutputBlob,
decodeInputBlob,
decodeOutputBlob,
encodeInput,
encodeOutput,
decodeInput,
decodeOutput,
Input,
Notice,
Voucher,
Expand Down Expand Up @@ -151,7 +151,7 @@ encodeCommand
.action((options) => {
const input: Input = { ...options };
const { binary } = options;
writeHexToStdout(encodeInputBlob(input), binary);
writeHexToStdout(encodeInput(input), binary);
});

encodeCommand
Expand All @@ -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
Expand All @@ -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
Expand All @@ -202,7 +202,7 @@ encodeCommand
...options,
};
const { binary } = options;
writeHexToStdout(encodeOutputBlob(delegatecallvoucher), binary);
writeHexToStdout(encodeOutput(delegatecallvoucher), binary);
});

const decodeCommand = program.command("decode");
Expand All @@ -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);
Expand All @@ -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));
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type Input = {
payload: Hex;
};

export const encodeInputBlob = (input: Input): Hex => {
export const encodeInput = (input: Input): Hex => {
const {
chainId,
appContract,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
39 changes: 17 additions & 22 deletions packages/core/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand Down

0 comments on commit 88c6dda

Please sign in to comment.