From 50ec5031c6bc3edf9a001fa76db7a77a73d8ce42 Mon Sep 17 00:00:00 2001 From: Tim Holmes-Mitra Date: Tue, 8 Oct 2024 11:06:05 +0100 Subject: [PATCH] feat(payments): add compat layer from bufbuild to cosmjs registry; drop ts-proto --- .prettierignore | 2 +- package-lock.json | 273 +++++++++++++----- packages/client-payments/buf.gen.yaml | 8 + packages/client-payments/buf.yaml | 9 + packages/client-payments/package.json | 7 +- .../meta/v1/msg_pay_for.proto} | 0 packages/client-payments/src/client.ts | 11 +- .../nillion/meta/v1/msg_pay_for_pb.ts | 63 ++++ packages/client-payments/src/grpc-compat.ts | 56 ++++ packages/client-payments/src/proto/index.ts | 1 - .../client-payments/src/proto/nilchain.ts | 225 --------------- 11 files changed, 342 insertions(+), 313 deletions(-) create mode 100644 packages/client-payments/buf.gen.yaml create mode 100644 packages/client-payments/buf.yaml rename packages/client-payments/proto/{nilchain.proto => nillion/meta/v1/msg_pay_for.proto} (100%) create mode 100644 packages/client-payments/src/gen-proto/nillion/meta/v1/msg_pay_for_pb.ts create mode 100644 packages/client-payments/src/grpc-compat.ts delete mode 100644 packages/client-payments/src/proto/index.ts delete mode 100644 packages/client-payments/src/proto/nilchain.ts diff --git a/.prettierignore b/.prettierignore index 26ade68..a44cd3e 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,2 @@ packages/wasm/dist -packages/client-payments/src/proto/nilchain.ts +packages/client-payments/src/gen-proto diff --git a/package-lock.json b/package-lock.json index 7d5041f..1ec0e1c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -731,12 +731,189 @@ "dev": true, "license": "MIT" }, + "node_modules/@bufbuild/buf": { + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf/-/buf-1.44.0.tgz", + "integrity": "sha512-5xdNiEUzI3Je5rFK9UzJl+gyKAv3fG1HdSlChqQXjTNZ3DZgeeuM7VdyHnr2QC/qgZfZ9L8PRKhJYbXZWYLVUg==", + "dev": true, + "hasInstallScript": true, + "license": "Apache-2.0", + "bin": { + "buf": "bin/buf", + "protoc-gen-buf-breaking": "bin/protoc-gen-buf-breaking", + "protoc-gen-buf-lint": "bin/protoc-gen-buf-lint" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@bufbuild/buf-darwin-arm64": "1.44.0", + "@bufbuild/buf-darwin-x64": "1.44.0", + "@bufbuild/buf-linux-aarch64": "1.44.0", + "@bufbuild/buf-linux-x64": "1.44.0", + "@bufbuild/buf-win32-arm64": "1.44.0", + "@bufbuild/buf-win32-x64": "1.44.0" + } + }, + "node_modules/@bufbuild/buf-darwin-arm64": { + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf-darwin-arm64/-/buf-darwin-arm64-1.44.0.tgz", + "integrity": "sha512-TZIorkTCICvVKYukkWeUFOMceaGWBrmKVOkXDC1Lusw3bRAdotQRZcwUHEW+XhHjOFFrrqcow4e7UKmk3Qekiw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@bufbuild/buf-darwin-x64": { + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf-darwin-x64/-/buf-darwin-x64-1.44.0.tgz", + "integrity": "sha512-0ygdEIYBUvvyJtNP7RWI1sgpsNaXX8f0JlMhG/y0IdozT+hQtDF9PSrw8+pz+ywpCJdiLzDwj4drZ+GuurQm8Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@bufbuild/buf-linux-aarch64": { + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf-linux-aarch64/-/buf-linux-aarch64-1.44.0.tgz", + "integrity": "sha512-8NRfpF/x3G5S3fZ4/OIOewxYs2/gnmYMhd0U6gKPrGQz7XblZNfY3Hfmx/5sWv6kybJJ8Iz2P7IVRyKP8net/Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@bufbuild/buf-linux-x64": { + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf-linux-x64/-/buf-linux-x64-1.44.0.tgz", + "integrity": "sha512-AjLw7WiqrzvJPA6NLLP3HIOv5bHAJB115qqOzVewsppBvtaCGDj6Du/cpccbSOJTuu88XUdVnJZa85+bnVxdIQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@bufbuild/buf-win32-arm64": { + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf-win32-arm64/-/buf-win32-arm64-1.44.0.tgz", + "integrity": "sha512-jlS3zbDI6pFXo0VuK8oxIAfpulWBiEW/l5I4LPT0AR5+q1Pfkn004GKox8znypXCLDV/xNh4/ZqrpL3c4ZAwjg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@bufbuild/buf-win32-x64": { + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/@bufbuild/buf-win32-x64/-/buf-win32-x64-1.44.0.tgz", + "integrity": "sha512-CRCeVVFssfLlXDzSBlI2y9b+xL/qP6umDp77HWg3iQugqONqy2ccSsDJNyxRATqaE5mixK5++Em/kqbnuhbKEA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, "node_modules/@bufbuild/protobuf": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@bufbuild/protobuf/-/protobuf-2.1.0.tgz", - "integrity": "sha512-+2Mx67Y3skJ4NCD/qNSdBJNWtu6x6Qr53jeNg+QcwiL6mt0wK+3jwHH2x1p7xaYH6Ve2JKOVn0OxU35WsmqI9A==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@bufbuild/protobuf/-/protobuf-2.2.0.tgz", + "integrity": "sha512-+imAQkHf7U/Rwvu0wk1XWgsP3WnpCWmK7B48f0XqSNzgk64+grljTKC7pnO/xBiEMUziF7vKRfbBnOQhg126qQ==", "license": "(Apache-2.0 AND BSD-3-Clause)" }, + "node_modules/@bufbuild/protoc-gen-es": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@bufbuild/protoc-gen-es/-/protoc-gen-es-2.2.0.tgz", + "integrity": "sha512-PmUTtbJJfgcabTsoF59W0bsAr7xO5aGcMe69G8vOq0ogYV1aWmvFKhHKHDtn295pOLhTXmfrDSUNi/OTHuDdpw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@bufbuild/protobuf": "^2.2.0", + "@bufbuild/protoplugin": "2.2.0" + }, + "bin": { + "protoc-gen-es": "bin/protoc-gen-es" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@bufbuild/protobuf": "2.2.0" + }, + "peerDependenciesMeta": { + "@bufbuild/protobuf": { + "optional": true + } + } + }, + "node_modules/@bufbuild/protoplugin": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@bufbuild/protoplugin/-/protoplugin-2.2.0.tgz", + "integrity": "sha512-ijsCHuhtXbfTiffoBRve2uCPR7gy6cwJsMe8z5bYQtczGiZVVfiyAze55gk1J/1ruqkr40oZ9BwKAGOzz69f0g==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@bufbuild/protobuf": "2.2.0", + "@typescript/vfs": "^1.5.2", + "typescript": "5.4.5" + } + }, + "node_modules/@bufbuild/protoplugin/node_modules/typescript": { + "version": "5.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", + "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/@commitlint/cli": { "version": "19.5.0", "resolved": "https://registry.npmjs.org/@commitlint/cli/-/cli-19.5.0.tgz", @@ -4252,6 +4429,19 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/@typescript/vfs": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@typescript/vfs/-/vfs-1.6.0.tgz", + "integrity": "sha512-hvJUjNVeBMp77qPINuUvYXj4FyWeeMMKZkxEATEU3hqBAQ7qdTBCUFT7Sp0Zu0faeEtFf+ldXxMEDr/bk73ISg==", + "dev": true, + "license": "MIT", + "dependencies": { + "debug": "^4.1.1" + }, + "peerDependencies": { + "typescript": "*" + } + }, "node_modules/@webassemblyjs/ast": { "version": "1.12.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.12.1.tgz", @@ -5217,19 +5407,6 @@ ], "license": "CC-BY-4.0" }, - "node_modules/case-anything": { - "version": "2.1.13", - "resolved": "https://registry.npmjs.org/case-anything/-/case-anything-2.1.13.tgz", - "integrity": "sha512-zlOQ80VrQ2Ue+ymH5OuM/DlDq64mEm+B9UTdHULv5osUMD6HalNTblf2b1u/m6QecjsnOkBpqVZ+XPwIVsy7Ng==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=12.13" - }, - "funding": { - "url": "https://github.com/sponsors/mesqueeb" - } - }, "node_modules/chalk": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", @@ -6152,19 +6329,6 @@ "npm": "1.2.8000 || >= 1.4.16" } }, - "node_modules/detect-libc": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", - "integrity": "sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg==", - "dev": true, - "license": "Apache-2.0", - "bin": { - "detect-libc": "bin/detect-libc.js" - }, - "engines": { - "node": ">=0.10" - } - }, "node_modules/detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -6245,16 +6409,6 @@ "url": "https://dotenvx.com" } }, - "node_modules/dprint-node": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/dprint-node/-/dprint-node-1.0.8.tgz", - "integrity": "sha512-iVKnUtYfGrYcW1ZAlfR/F59cUVL8QIhWoBJoSjkkdua/dkWIgjZfiLMeTjiB06X0ZLkQ0M2C1VbUj/CxkIf1zg==", - "dev": true, - "license": "MIT", - "dependencies": { - "detect-libc": "^1.0.3" - } - }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -13557,42 +13711,6 @@ "dev": true, "license": "MIT" }, - "node_modules/ts-poet": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/ts-poet/-/ts-poet-6.9.0.tgz", - "integrity": "sha512-roe6W6MeZmCjRmppyfOURklO5tQFQ6Sg7swURKkwYJvV7dbGCrK28um5+51iW3twdPRKtwarqFAVMU6G1mvnuQ==", - "dev": true, - "license": "Apache-2.0", - "dependencies": { - "dprint-node": "^1.0.8" - } - }, - "node_modules/ts-proto": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/ts-proto/-/ts-proto-2.2.3.tgz", - "integrity": "sha512-sI9qyTcMg7syJjk0CvkRVxZyAuCbpweO2Kq5Dz/JXaRwpaB9ujMHdFF06raXj5nLxDknzV5cUIcdCuUThPXuYg==", - "dev": true, - "license": "ISC", - "dependencies": { - "@bufbuild/protobuf": "^2.0.0", - "case-anything": "^2.1.13", - "ts-poet": "^6.7.0", - "ts-proto-descriptors": "2.0.0" - }, - "bin": { - "protoc-gen-ts_proto": "protoc-gen-ts_proto" - } - }, - "node_modules/ts-proto-descriptors": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ts-proto-descriptors/-/ts-proto-descriptors-2.0.0.tgz", - "integrity": "sha512-wHcTH3xIv11jxgkX5OyCSFfw27agpInAd6yh89hKG6zqIXnjW9SYqSER2CVQxdPj4czeOhGagNvZBEbJPy7qkw==", - "dev": true, - "license": "ISC", - "dependencies": { - "@bufbuild/protobuf": "^2.0.0" - } - }, "node_modules/tsconfig-paths": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz", @@ -15145,11 +15263,12 @@ "zod": "^3.23.8" }, "devDependencies": { + "@bufbuild/buf": "^1.44.0", + "@bufbuild/protoc-gen-es": "^2.1.0", "@keplr-wallet/types": "^0.12.130", "@types/debug": "^4.1.12", "browserslist": "^4.24.0", - "esbuild-plugin-browserslist": "^0.15.0", - "ts-proto": "^2.2.3" + "esbuild-plugin-browserslist": "^0.15.0" } }, "packages/client-react-hooks": { diff --git a/packages/client-payments/buf.gen.yaml b/packages/client-payments/buf.gen.yaml new file mode 100644 index 0000000..5bb3a71 --- /dev/null +++ b/packages/client-payments/buf.gen.yaml @@ -0,0 +1,8 @@ +version: v2 +managed: + enabled: true +clean: true +plugins: + - local: protoc-gen-es + opt: target=ts + out: src/gen-proto diff --git a/packages/client-payments/buf.yaml b/packages/client-payments/buf.yaml new file mode 100644 index 0000000..c7e30e3 --- /dev/null +++ b/packages/client-payments/buf.yaml @@ -0,0 +1,9 @@ +version: v2 +modules: + - path: proto +lint: + use: + - STANDARD +breaking: + use: + - FILE diff --git a/packages/client-payments/package.json b/packages/client-payments/package.json index b3878d5..39f9c2b 100644 --- a/packages/client-payments/package.json +++ b/packages/client-payments/package.json @@ -18,8 +18,8 @@ "scripts": { "clean": "rm -rf dist dist-test", "build": "node esbuild.config.mjs", - "build:proto": "protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./src proto/nilchain.proto", "build:watch": "node esbuild.config.mjs --watch", + "build:proto": "npx buf generate", "test": "npx jasmine-browser-runner runSpecs --config=jasmine.config.mjs", "test:build": "npx webpack --config webpack.config.mjs", "test:build:watch": "npx webpack --config webpack.config.mjs --watch", @@ -35,11 +35,12 @@ "zod": "^3.23.8" }, "devDependencies": { + "@bufbuild/buf": "^1.44.0", + "@bufbuild/protoc-gen-es": "^2.1.0", "@keplr-wallet/types": "^0.12.130", "@types/debug": "^4.1.12", "browserslist": "^4.24.0", - "esbuild-plugin-browserslist": "^0.15.0", - "ts-proto": "^2.2.3" + "esbuild-plugin-browserslist": "^0.15.0" }, "files": [ "dist", diff --git a/packages/client-payments/proto/nilchain.proto b/packages/client-payments/proto/nillion/meta/v1/msg_pay_for.proto similarity index 100% rename from packages/client-payments/proto/nilchain.proto rename to packages/client-payments/proto/nillion/meta/v1/msg_pay_for.proto diff --git a/packages/client-payments/src/client.ts b/packages/client-payments/src/client.ts index a1e00e3..19eb5aa 100644 --- a/packages/client-payments/src/client.ts +++ b/packages/client-payments/src/client.ts @@ -1,3 +1,4 @@ +import { create } from "@bufbuild/protobuf"; import { OfflineSigner, Registry } from "@cosmjs/proto-signing"; import { GasPrice, @@ -18,8 +19,9 @@ import { PaymentError, UnknownPaymentError, } from "./errors"; +import { MsgPayForSchema } from "./gen-proto/nillion/meta/v1/msg_pay_for_pb"; +import { MsgPayForCompatWrapper } from "./grpc-compat"; import { Log } from "./logger"; -import { MsgPayFor } from "./proto"; import { NilChainProtobufTypeUrl, PaymentClientConfig } from "./types"; import { getKeplr } from "./wallet"; @@ -67,10 +69,7 @@ export class PaymentsClient { const { endpoint, chainId } = this._config; const registry = new Registry(); - // @ts-expect-error ts-proto 2+ migrated from protobufjs to @bufbuild/protobuf causing a type - // misalignment between our generated bindings and cosmjs. Tests are all passing so we'll - // keep as-is. - registry.register(NilChainProtobufTypeUrl, MsgPayFor); + registry.register(NilChainProtobufTypeUrl, MsgPayForCompatWrapper); this._signer = this._config.signer; if (!this._signer) { @@ -109,7 +108,7 @@ export class PaymentsClient { pay(quote: PriceQuote): E.Effect { return E.Do.pipe( E.let("transferMessage", () => - MsgPayFor.create({ + create(MsgPayForSchema, { fromAddress: this.address, resource: quote.nonce, amount: [{ denom: Token.Unil, amount: String(quote.cost.total) }], diff --git a/packages/client-payments/src/gen-proto/nillion/meta/v1/msg_pay_for_pb.ts b/packages/client-payments/src/gen-proto/nillion/meta/v1/msg_pay_for_pb.ts new file mode 100644 index 0000000..6f16a89 --- /dev/null +++ b/packages/client-payments/src/gen-proto/nillion/meta/v1/msg_pay_for_pb.ts @@ -0,0 +1,63 @@ +// @generated by protoc-gen-es v2.2.0 with parameter "target=ts" +// @generated from file nillion/meta/v1/msg_pay_for.proto (package nillion.meta.v1, syntax proto3) +/* eslint-disable */ + +import type { GenFile, GenMessage } from "@bufbuild/protobuf/codegenv1"; +import { fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv1"; +import type { Message } from "@bufbuild/protobuf"; + +/** + * Describes the file nillion/meta/v1/msg_pay_for.proto. + */ +export const file_nillion_meta_v1_msg_pay_for: GenFile = /*@__PURE__*/ + fileDesc("CiFuaWxsaW9uL21ldGEvdjEvbXNnX3BheV9mb3IucHJvdG8SD25pbGxpb24ubWV0YS52MSJcCglNc2dQYXlGb3ISEAoIcmVzb3VyY2UYASABKAwSFAoMZnJvbV9hZGRyZXNzGAIgASgJEicKBmFtb3VudBgDIAMoCzIXLm5pbGxpb24ubWV0YS52MS5BbW91bnQiJwoGQW1vdW50Eg0KBWRlbm9tGAEgASgJEg4KBmFtb3VudBgCIAEoCUKDAQoTY29tLm5pbGxpb24ubWV0YS52MUIOTXNnUGF5Rm9yUHJvdG9QAaICA05NWKoCD05pbGxpb24uTWV0YS5WMcoCD05pbGxpb25cTWV0YVxWMeICG05pbGxpb25cTWV0YVxWMVxHUEJNZXRhZGF0YeoCEU5pbGxpb246Ok1ldGE6OlYxYgZwcm90bzM"); + +/** + * @generated from message nillion.meta.v1.MsgPayFor + */ +export type MsgPayFor = Message<"nillion.meta.v1.MsgPayFor"> & { + /** + * @generated from field: bytes resource = 1; + */ + resource: Uint8Array; + + /** + * @generated from field: string from_address = 2; + */ + fromAddress: string; + + /** + * @generated from field: repeated nillion.meta.v1.Amount amount = 3; + */ + amount: Amount[]; +}; + +/** + * Describes the message nillion.meta.v1.MsgPayFor. + * Use `create(MsgPayForSchema)` to create a new message. + */ +export const MsgPayForSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_nillion_meta_v1_msg_pay_for, 0); + +/** + * @generated from message nillion.meta.v1.Amount + */ +export type Amount = Message<"nillion.meta.v1.Amount"> & { + /** + * @generated from field: string denom = 1; + */ + denom: string; + + /** + * @generated from field: string amount = 2; + */ + amount: string; +}; + +/** + * Describes the message nillion.meta.v1.Amount. + * Use `create(AmountSchema)` to create a new message. + */ +export const AmountSchema: GenMessage = /*@__PURE__*/ + messageDesc(file_nillion_meta_v1_msg_pay_for, 1); + diff --git a/packages/client-payments/src/grpc-compat.ts b/packages/client-payments/src/grpc-compat.ts new file mode 100644 index 0000000..505de1a --- /dev/null +++ b/packages/client-payments/src/grpc-compat.ts @@ -0,0 +1,56 @@ +import { create } from "@bufbuild/protobuf"; +import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire"; +import { TsProtoGeneratedType } from "@cosmjs/proto-signing/build/registry"; + +import { + MsgPayFor, + MsgPayForSchema, +} from "./gen-proto/nillion/meta/v1/msg_pay_for_pb"; + +/** + * This wrapper maintains API compatibility with the cosmjs library while using `@bufbuild/protobuf`. + * It bridges the gap between different protobuf implementations during the migration from + * protobufjs to `@bufbuild/protobuf` and from the cluster's migration from libp2p to gRPC. + * + * Only `encode` and `fromPartial` methods are implemented as they are sufficient for sending transactions. + * + * We use `@ts-expect-error` because `TsProtoGeneratedType` expects `protobuf.Writer/Reader`, + * but we're using `BinaryWriter/Reader`. The methods used are compatible between these types, + * allowing us to bypass the type check safely in this context. + */ +export const MsgPayForCompatWrapper: TsProtoGeneratedType = { + // @ts-expect-error see MsgPayForCompatWrapper comment + encode: ( + message: MsgPayFor, + writer: BinaryWriter = new BinaryWriter(), + ): BinaryWriter => { + if (message.resource.length > 0) { + writer.uint32(10).bytes(message.resource); + } + if (message.fromAddress !== "") { + writer.uint32(18).string(message.fromAddress); + } + for (const amount of message.amount) { + const amountWriter = new BinaryWriter(); + if (amount.denom !== "") { + amountWriter.uint32(10).string(amount.denom); + } + if (amount.amount !== "") { + amountWriter.uint32(18).string(amount.amount); + } + writer.uint32(26).bytes(amountWriter.finish()); + } + return writer; + }, + // @ts-expect-error see MsgPayForCompatWrapper comment + decode: (_input: BinaryReader | Uint8Array, _length?: number): MsgPayFor => { + throw new Error("MsgPayForCompatWrapper: decode not implemented"); + }, + fromPartial: (object: Partial): MsgPayFor => { + return create(MsgPayForSchema, { + resource: object.resource, + fromAddress: object.fromAddress, + amount: object.amount, + }); + }, +}; diff --git a/packages/client-payments/src/proto/index.ts b/packages/client-payments/src/proto/index.ts deleted file mode 100644 index efdc7aa..0000000 --- a/packages/client-payments/src/proto/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./nilchain"; diff --git a/packages/client-payments/src/proto/nilchain.ts b/packages/client-payments/src/proto/nilchain.ts deleted file mode 100644 index 0a8e9de..0000000 --- a/packages/client-payments/src/proto/nilchain.ts +++ /dev/null @@ -1,225 +0,0 @@ -// Code generated by protoc-gen-ts_proto. DO NOT EDIT. -// versions: -// protoc-gen-ts_proto v2.0.3 -// protoc v5.27.3 -// source: proto/nilchain.proto - -/* eslint-disable */ -import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire"; - -export const protobufPackage = "nillion.meta.v1"; - -export interface MsgPayFor { - resource: Uint8Array; - fromAddress: string; - amount: Amount[]; -} - -export interface Amount { - denom: string; - amount: string; -} - -function createBaseMsgPayFor(): MsgPayFor { - return { resource: new Uint8Array(0), fromAddress: "", amount: [] }; -} - -export const MsgPayFor = { - encode(message: MsgPayFor, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { - if (message.resource.length !== 0) { - writer.uint32(10).bytes(message.resource); - } - if (message.fromAddress !== "") { - writer.uint32(18).string(message.fromAddress); - } - for (const v of message.amount) { - Amount.encode(v!, writer.uint32(26).fork()).join(); - } - return writer; - }, - - decode(input: BinaryReader | Uint8Array, length?: number): MsgPayFor { - const reader = input instanceof BinaryReader ? input : new BinaryReader(input); - let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseMsgPayFor(); - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break; - } - - message.resource = reader.bytes(); - continue; - case 2: - if (tag !== 18) { - break; - } - - message.fromAddress = reader.string(); - continue; - case 3: - if (tag !== 26) { - break; - } - - message.amount.push(Amount.decode(reader, reader.uint32())); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skip(tag & 7); - } - return message; - }, - - fromJSON(object: any): MsgPayFor { - return { - resource: isSet(object.resource) ? bytesFromBase64(object.resource) : new Uint8Array(0), - fromAddress: isSet(object.fromAddress) ? globalThis.String(object.fromAddress) : "", - amount: globalThis.Array.isArray(object?.amount) ? object.amount.map((e: any) => Amount.fromJSON(e)) : [], - }; - }, - - toJSON(message: MsgPayFor): unknown { - const obj: any = {}; - if (message.resource.length !== 0) { - obj.resource = base64FromBytes(message.resource); - } - if (message.fromAddress !== "") { - obj.fromAddress = message.fromAddress; - } - if (message.amount?.length) { - obj.amount = message.amount.map((e) => Amount.toJSON(e)); - } - return obj; - }, - - create, I>>(base?: I): MsgPayFor { - return MsgPayFor.fromPartial(base ?? ({} as any)); - }, - fromPartial, I>>(object: I): MsgPayFor { - const message = createBaseMsgPayFor(); - message.resource = object.resource ?? new Uint8Array(0); - message.fromAddress = object.fromAddress ?? ""; - message.amount = object.amount?.map((e) => Amount.fromPartial(e)) || []; - return message; - }, -}; - -function createBaseAmount(): Amount { - return { denom: "", amount: "" }; -} - -export const Amount = { - encode(message: Amount, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { - if (message.denom !== "") { - writer.uint32(10).string(message.denom); - } - if (message.amount !== "") { - writer.uint32(18).string(message.amount); - } - return writer; - }, - - decode(input: BinaryReader | Uint8Array, length?: number): Amount { - const reader = input instanceof BinaryReader ? input : new BinaryReader(input); - let end = length === undefined ? reader.len : reader.pos + length; - const message = createBaseAmount(); - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break; - } - - message.denom = reader.string(); - continue; - case 2: - if (tag !== 18) { - break; - } - - message.amount = reader.string(); - continue; - } - if ((tag & 7) === 4 || tag === 0) { - break; - } - reader.skip(tag & 7); - } - return message; - }, - - fromJSON(object: any): Amount { - return { - denom: isSet(object.denom) ? globalThis.String(object.denom) : "", - amount: isSet(object.amount) ? globalThis.String(object.amount) : "", - }; - }, - - toJSON(message: Amount): unknown { - const obj: any = {}; - if (message.denom !== "") { - obj.denom = message.denom; - } - if (message.amount !== "") { - obj.amount = message.amount; - } - return obj; - }, - - create, I>>(base?: I): Amount { - return Amount.fromPartial(base ?? ({} as any)); - }, - fromPartial, I>>(object: I): Amount { - const message = createBaseAmount(); - message.denom = object.denom ?? ""; - message.amount = object.amount ?? ""; - 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; - -export type DeepPartial = T extends Builtin ? T - : T extends globalThis.Array ? globalThis.Array> - : T extends ReadonlyArray ? ReadonlyArray> - : T extends {} ? { [K in keyof T]?: DeepPartial } - : Partial; - -type KeysOfUnion = T extends T ? keyof T : never; -export type Exact = P extends Builtin ? P - : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; - -function isSet(value: any): boolean { - return value !== null && value !== undefined; -}