From cc2e36995ad10cdb6afdb5dcd6f1a8eb8c6f81a1 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 7 Sep 2022 17:50:57 +0200 Subject: [PATCH] Finalize feegrant code --- CHANGELOG.md | 2 ++ packages/amino/src/signdoc.ts | 2 ++ .../proto-signing/src/directsecp256k1hdwallet.spec.ts | 4 ++-- packages/proto-signing/src/directsecp256k1wallet.spec.ts | 4 ++-- packages/proto-signing/src/signing.ts | 8 ++++++++ packages/stargate/src/stargateclient.spec.ts | 4 ++-- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ead672e92..737266f730 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,8 @@ and this project adheres to - @cosmjs/stargate: `BankExtension.totalSupply` now takes a pagination key argument and returns the full `QueryTotalSupplyResponse` including the next pagination key ([#1095]). +- @cosmjs/proto-signing: `makeAuthInfoBytes` now expects a fee granter and fee + payer argument in position 4 and 5. [#1131]: https://github.com/cosmos/cosmjs/pull/1131 [#1168]: https://github.com/cosmos/cosmjs/pull/1168 diff --git a/packages/amino/src/signdoc.ts b/packages/amino/src/signdoc.ts index 6e20a32129..2348353eb3 100644 --- a/packages/amino/src/signdoc.ts +++ b/packages/amino/src/signdoc.ts @@ -12,7 +12,9 @@ export interface AminoMsg { export interface StdFee { readonly amount: readonly Coin[]; readonly gas: string; + /** The granter address that is used for paying with feegrants */ readonly granter?: string; + /** The fee payer address. The payer must have signed the transaction. */ readonly payer?: string; } diff --git a/packages/proto-signing/src/directsecp256k1hdwallet.spec.ts b/packages/proto-signing/src/directsecp256k1hdwallet.spec.ts index 02c9aae280..24757783c2 100644 --- a/packages/proto-signing/src/directsecp256k1hdwallet.spec.ts +++ b/packages/proto-signing/src/directsecp256k1hdwallet.spec.ts @@ -261,8 +261,8 @@ describe("DirectSecp256k1HdWallet", () => { }; const fee = coins(2000, "ucosm"); const gasLimit = 200000; - const feeGranter = ""; - const feePayer = ""; + const feeGranter = undefined; + const feePayer = undefined; const chainId = "simd-testing"; const signDoc = makeSignDoc( fromHex(bodyBytes), diff --git a/packages/proto-signing/src/directsecp256k1wallet.spec.ts b/packages/proto-signing/src/directsecp256k1wallet.spec.ts index 3e071621b6..58af6c3ace 100644 --- a/packages/proto-signing/src/directsecp256k1wallet.spec.ts +++ b/packages/proto-signing/src/directsecp256k1wallet.spec.ts @@ -44,8 +44,8 @@ describe("DirectSecp256k1Wallet", () => { const fee = coins(2000, "ucosm"); const gasLimit = 200000; const chainId = "simd-testing"; - const feePayer = ""; - const feeGranter = ""; + const feePayer = undefined; + const feeGranter = undefined; const signDoc = makeSignDoc( fromHex(bodyBytes), makeAuthInfoBytes([{ pubkey, sequence }], fee, gasLimit, feeGranter, feePayer), diff --git a/packages/proto-signing/src/signing.ts b/packages/proto-signing/src/signing.ts index 24e69c3d4a..7ce7e476f3 100644 --- a/packages/proto-signing/src/signing.ts +++ b/packages/proto-signing/src/signing.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { assert } from "@cosmjs/utils"; import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin"; import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing"; import { AuthInfo, SignDoc, SignerInfo } from "cosmjs-types/cosmos/tx/v1beta1/tx"; @@ -38,6 +39,13 @@ export function makeAuthInfoBytes( feePayer: string | undefined, signMode = SignMode.SIGN_MODE_DIRECT, ): Uint8Array { + // Required arguments 4 and 5 were added in CosmJS 0.29. Use runtime checks to help our non-TS users. + assert( + feeGranter === undefined || typeof feeGranter === "string", + "feeGranter must be undefined or string", + ); + assert(feePayer === undefined || typeof feePayer === "string", "feePayer must be undefined or string"); + const authInfo = { signerInfos: makeSignerInfos(signers, signMode), fee: { diff --git a/packages/stargate/src/stargateclient.spec.ts b/packages/stargate/src/stargateclient.spec.ts index df4823e8a5..641a31e854 100644 --- a/packages/stargate/src/stargateclient.spec.ts +++ b/packages/stargate/src/stargateclient.spec.ts @@ -499,8 +499,8 @@ describe("StargateClient", () => { const chainId = await client.getChainId(); const feeAmount = coins(2000, "ucosm"); const gasLimit = 200000; - const feeGranter = ""; - const feePayer = ""; + const feeGranter = undefined; + const feePayer = undefined; const { accountNumber: accountNumber1, sequence: sequence1 } = (await client.getSequence(address))!; const authInfoBytes1 = makeAuthInfoBytes(