From 4b3a6ed696d6dc41024ea36e48aa81327af5e0b1 Mon Sep 17 00:00:00 2001 From: Franklin Waller Date: Mon, 11 Nov 2024 14:52:22 +0100 Subject: [PATCH 1/2] feat(proto-messages): update to latest proto messages --- .../gen/sedachain/pubkey/v1/pubkey.ts | 46 ++++++++++++++----- .../sedachain/batching/v1/batching.proto | 20 ++++---- .../proto/sedachain/batching/v1/query.proto | 2 +- .../proto/sedachain/pubkey/v1/pubkey.proto | 3 +- package.json | 2 +- 5 files changed, 47 insertions(+), 26 deletions(-) diff --git a/libs/proto-messages/gen/sedachain/pubkey/v1/pubkey.ts b/libs/proto-messages/gen/sedachain/pubkey/v1/pubkey.ts index 2c81cb8..d0aa94d 100644 --- a/libs/proto-messages/gen/sedachain/pubkey/v1/pubkey.ts +++ b/libs/proto-messages/gen/sedachain/pubkey/v1/pubkey.ts @@ -6,16 +6,15 @@ /* eslint-disable */ import _m0 from "protobufjs/minimal"; -import { Any } from "../../../google/protobuf/any"; /** IndexPubKeyPair defines an index - public key pair. */ export interface IndexedPubKey { index: number; - pubKey: Any | undefined; + pubKey: Uint8Array; } function createBaseIndexedPubKey(): IndexedPubKey { - return { index: 0, pubKey: undefined }; + return { index: 0, pubKey: new Uint8Array(0) }; } export const IndexedPubKey = { @@ -23,8 +22,8 @@ export const IndexedPubKey = { if (message.index !== 0) { writer.uint32(8).uint32(message.index); } - if (message.pubKey !== undefined) { - Any.encode(message.pubKey, writer.uint32(18).fork()).ldelim(); + if (message.pubKey.length !== 0) { + writer.uint32(18).bytes(message.pubKey); } return writer; }, @@ -48,7 +47,7 @@ export const IndexedPubKey = { break; } - message.pubKey = Any.decode(reader, reader.uint32()); + message.pubKey = reader.bytes(); continue; } if ((tag & 7) === 4 || tag === 0) { @@ -62,7 +61,7 @@ export const IndexedPubKey = { fromJSON(object: any): IndexedPubKey { return { index: isSet(object.index) ? globalThis.Number(object.index) : 0, - pubKey: isSet(object.pubKey) ? Any.fromJSON(object.pubKey) : undefined, + pubKey: isSet(object.pubKey) ? bytesFromBase64(object.pubKey) : new Uint8Array(0), }; }, @@ -71,8 +70,8 @@ export const IndexedPubKey = { if (message.index !== 0) { obj.index = Math.round(message.index); } - if (message.pubKey !== undefined) { - obj.pubKey = Any.toJSON(message.pubKey); + if (message.pubKey.length !== 0) { + obj.pubKey = base64FromBytes(message.pubKey); } return obj; }, @@ -83,13 +82,36 @@ export const IndexedPubKey = { fromPartial(object: DeepPartial): IndexedPubKey { const message = createBaseIndexedPubKey(); message.index = object.index ?? 0; - message.pubKey = (object.pubKey !== undefined && object.pubKey !== null) - ? Any.fromPartial(object.pubKey) - : undefined; + message.pubKey = object.pubKey ?? new Uint8Array(0); return message; }, }; +function bytesFromBase64(b64: string): Uint8Array { + if ((globalThis as any).Buffer) { + return Uint8Array.from(globalThis.Buffer.from(b64, "base64")); + } else { + const bin = globalThis.atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; + } +} + +function base64FromBytes(arr: Uint8Array): string { + if ((globalThis as any).Buffer) { + return globalThis.Buffer.from(arr).toString("base64"); + } else { + const bin: string[] = []; + arr.forEach((byte) => { + bin.push(globalThis.String.fromCharCode(byte)); + }); + return globalThis.btoa(bin.join("")); + } +} + type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; type DeepPartial = T extends Builtin ? T diff --git a/libs/proto-messages/proto/sedachain/batching/v1/batching.proto b/libs/proto-messages/proto/sedachain/batching/v1/batching.proto index 4e120e4..7c46fec 100644 --- a/libs/proto-messages/proto/sedachain/batching/v1/batching.proto +++ b/libs/proto-messages/proto/sedachain/batching/v1/batching.proto @@ -62,25 +62,25 @@ message Params { // DataResult represents the result of a resolved data request. message DataResult { // id is the Keccack-256 hash of the data result. - string id = 1; + string id = 1 [ (gogoproto.jsontag) = "id" ]; // dr_id is the data request identifier. - string dr_id = 2; + string dr_id = 2 [ (gogoproto.jsontag) = "dr_id" ]; // version is a semantic version string. - string version = 3; + string version = 3 [ (gogoproto.jsontag) = "version" ]; // block_height is the height at which the data request was tallied. - uint64 block_height = 4; + uint64 block_height = 4 [ (gogoproto.jsontag) = "block_height" ]; // exit_code is the exit code of the tally wasm binary execution. - uint32 exit_code = 5; + uint32 exit_code = 5 [ (gogoproto.jsontag) = "exit_code" ]; // gas_used is the gas used by the data request execution. - uint64 gas_used = 6; + uint64 gas_used = 6 [ (gogoproto.jsontag) = "gas_used" ]; // result is the result of the tally wasm binary execution. - bytes result = 7; + bytes result = 7 [ (gogoproto.jsontag) = "result" ]; // payback_address is the payback address set by the relayer. - string payback_address = 8; + string payback_address = 8 [ (gogoproto.jsontag) = "payback_address" ]; // seda_payload is the payload set by SEDA Protocol (e.g. OEV-enabled // data requests) - string seda_payload = 9; + string seda_payload = 9 [ (gogoproto.jsontag) = "seda_payload" ]; // consensus indicates whether consensus was reached in the tally // process. - bool consensus = 10; + bool consensus = 10 [ (gogoproto.jsontag) = "consensus" ]; } diff --git a/libs/proto-messages/proto/sedachain/batching/v1/query.proto b/libs/proto-messages/proto/sedachain/batching/v1/query.proto index ffa806d..333500d 100644 --- a/libs/proto-messages/proto/sedachain/batching/v1/query.proto +++ b/libs/proto-messages/proto/sedachain/batching/v1/query.proto @@ -104,7 +104,7 @@ message QueryDataResultRequest { string data_request_id = 1; } // The response message for QueryDataResult RPC. message QueryDataResultResponse { - DataResult data_result = 1 [ (gogoproto.nullable) = false ]; + DataResult data_result = 1 [ (gogoproto.nullable) = true ]; } // The request message for QueryBatchAssignment RPC. diff --git a/libs/proto-messages/proto/sedachain/pubkey/v1/pubkey.proto b/libs/proto-messages/proto/sedachain/pubkey/v1/pubkey.proto index 8f57451..e25e3fa 100644 --- a/libs/proto-messages/proto/sedachain/pubkey/v1/pubkey.proto +++ b/libs/proto-messages/proto/sedachain/pubkey/v1/pubkey.proto @@ -1,7 +1,6 @@ syntax = "proto3"; package sedachain.pubkey.v1; -import "google/protobuf/any.proto"; import "cosmos_proto/cosmos.proto"; option go_package = "github.com/sedaprotocol/seda-chain/x/pubkey/types"; @@ -9,6 +8,6 @@ option go_package = "github.com/sedaprotocol/seda-chain/x/pubkey/types"; // IndexPubKeyPair defines an index - public key pair. message IndexedPubKey { uint32 index = 1; - google.protobuf.Any pub_key = 2 + bytes pub_key = 2 [ (cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey" ]; } diff --git a/package.json b/package.json index 887a512..23e0dad 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "fmt": "bunx biome check --write .", "test": "nx run-many --all --target=test", "docs": "bun run tools/typedoc/generate.ts", - "cli:generate": "cd libs/cli/proto && npx buf generate" + "proto:generate": "cd libs/proto-messages/proto && npx buf generate" }, "private": true, "type": "module", From b07780a5eb7f81c6c7c6d433841e4d34b40fc29d Mon Sep 17 00:00:00 2001 From: Franklin Waller Date: Mon, 11 Nov 2024 14:53:26 +0100 Subject: [PATCH 2/2] chore(proto-messages): bump version to v0.4.0-dev.2 --- libs/proto-messages/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/proto-messages/package.json b/libs/proto-messages/package.json index 3c87424..51fe8d0 100644 --- a/libs/proto-messages/package.json +++ b/libs/proto-messages/package.json @@ -1,7 +1,7 @@ { "name": "@seda-protocol/proto-messages", "type": "module", - "version": "0.4.0-dev.1", + "version": "0.4.0-dev.2", "scripts": { "build": "bunx buf generate", "prepublish": "bun run build"