granter and payer are added in the StdFee interface

This commit is contained in:
arnabghose997 2022-06-15 18:31:51 +05:30 committed by Simon Warta
parent 3d5863be8f
commit d843da4a60
12 changed files with 61 additions and 13 deletions

View File

@ -13,6 +13,7 @@ export interface StdFee {
readonly amount: readonly Coin[];
readonly gas: string;
readonly granter?: string;
readonly payer?: string;
}
/**

View File

@ -79,8 +79,9 @@ async function sendTokens(
},
];
const gasLimit = 200000;
const feeGranter = "";
const feePayer = "";
const authInfoBytes = makeAuthInfoBytes([{ pubkey, sequence }], feeAmount, gasLimit, feePayer);
const authInfoBytes = makeAuthInfoBytes([{ pubkey, sequence }], feeAmount, gasLimit, feeGranter, feePayer);
const chainId = await client.getChainId();
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);

View File

@ -203,8 +203,15 @@ describe("CosmWasmClient", () => {
};
const txBodyBytes = registry.encode(txBody);
const gasLimit = Int53.fromString(fee.gas).toNumber();
const feeGranter = "";
const feePayer = "";
const authInfoBytes = makeAuthInfoBytes([{ pubkey, sequence }], fee.amount, gasLimit, feePayer);
const authInfoBytes = makeAuthInfoBytes(
[{ pubkey, sequence }],
fee.amount,
gasLimit,
feeGranter,
feePayer,
);
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
const { signed, signature } = await wallet.signDirect(alice.address0, signDoc);
const txRaw = TxRaw.fromPartial({

View File

@ -582,11 +582,13 @@ export class SigningCosmWasmClient extends CosmWasmClient {
const signedTxBodyBytes = this.registry.encode(signedTxBody);
const signedGasLimit = Int53.fromString(signed.fee.gas).toNumber();
const signedSequence = Int53.fromString(signed.sequence).toNumber();
const signedFeePayer = "";
const signedFeeGranter = signed.fee.granter == undefined ? "" : signed.fee.granter;
const signedFeePayer = signed.fee.payer == undefined ? "" : signed.fee.payer;
const signedAuthInfoBytes = makeAuthInfoBytes(
[{ pubkey, sequence: signedSequence }],
signed.fee.amount,
signedGasLimit,
signedFeeGranter,
signedFeePayer,
signMode,
);
@ -621,8 +623,15 @@ export class SigningCosmWasmClient extends CosmWasmClient {
};
const txBodyBytes = this.registry.encode(txBody);
const gasLimit = Int53.fromString(fee.gas).toNumber();
const feePayer = fee.granter == undefined ? "" : fee.granter;
const authInfoBytes = makeAuthInfoBytes([{ pubkey, sequence }], fee.amount, gasLimit, feePayer);
const feePayer = fee.payer == undefined ? "" : fee.payer;
const feeGranter = fee.granter == undefined ? "" : fee.granter;
const authInfoBytes = makeAuthInfoBytes(
[{ pubkey, sequence }],
fee.amount,
gasLimit,
feeGranter,
feePayer,
);
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
const { signature, signed } = await this.signer.signDirect(signerAddress, signDoc);
return TxRaw.fromPartial({

View File

@ -225,6 +225,7 @@ export class ModifyingDirectSecp256k1HdWallet extends DirectSecp256k1HdWallet {
}));
const modifiedFeeAmount = coins(3000, "ucosm");
const modifiedGasLimit = 333333;
const modifiedFeeGranter = "";
const modifiedFeePayer = "";
const modifiedSignDoc = {
...signDoc,
@ -233,6 +234,7 @@ export class ModifyingDirectSecp256k1HdWallet extends DirectSecp256k1HdWallet {
signers,
modifiedFeeAmount,
modifiedGasLimit,
modifiedFeeGranter,
modifiedFeePayer,
SignMode.SIGN_MODE_DIRECT,
),

View File

@ -261,11 +261,12 @@ describe("DirectSecp256k1HdWallet", () => {
};
const fee = coins(2000, "ucosm");
const gasLimit = 200000;
const feeGranter = "";
const feePayer = "";
const chainId = "simd-testing";
const signDoc = makeSignDoc(
fromHex(bodyBytes),
makeAuthInfoBytes([{ pubkey, sequence }], fee, gasLimit, feePayer),
makeAuthInfoBytes([{ pubkey, sequence }], fee, gasLimit, feeGranter, feePayer),
chainId,
accountNumber,
);

View File

@ -45,9 +45,10 @@ describe("DirectSecp256k1Wallet", () => {
const gasLimit = 200000;
const chainId = "simd-testing";
const feePayer = "";
const feeGranter = "";
const signDoc = makeSignDoc(
fromHex(bodyBytes),
makeAuthInfoBytes([{ pubkey, sequence }], fee, gasLimit, feePayer),
makeAuthInfoBytes([{ pubkey, sequence }], fee, gasLimit, feeGranter, feePayer),
chainId,
accountNumber,
);

View File

@ -34,6 +34,7 @@ export function makeAuthInfoBytes(
signers: ReadonlyArray<{ readonly pubkey: Any; readonly sequence: number }>,
feeAmount: readonly Coin[],
gasLimit: number,
feeGranter: string | undefined,
feePayer: string | undefined,
signMode = SignMode.SIGN_MODE_DIRECT,
): Uint8Array {
@ -42,7 +43,8 @@ export function makeAuthInfoBytes(
fee: {
amount: [...feeAmount],
gasLimit: Long.fromNumber(gasLimit),
granter: feePayer,
granter: feeGranter,
payer: feePayer,
},
};
return AuthInfo.encode(AuthInfo.fromPartial(authInfo)).finish();

View File

@ -362,11 +362,13 @@ export class SigningStargateClient extends StargateClient {
const signedTxBodyBytes = this.registry.encode(signedTxBodyEncodeObject);
const signedGasLimit = Int53.fromString(signed.fee.gas).toNumber();
const signedSequence = Int53.fromString(signed.sequence).toNumber();
const signedFeePayer = signed.fee.granter == undefined ? "" : signed.fee.granter;
const signedFeeGranter = signed.fee.granter == undefined ? "" : signed.fee.granter;
const signedFeePayer = signed.fee.payer == undefined ? "" : signed.fee.payer;
const signedAuthInfoBytes = makeAuthInfoBytes(
[{ pubkey, sequence: signedSequence }],
signed.fee.amount,
signedGasLimit,
signedFeeGranter,
signedFeePayer,
signMode,
);
@ -401,8 +403,15 @@ export class SigningStargateClient extends StargateClient {
};
const txBodyBytes = this.registry.encode(txBodyEncodeObject);
const gasLimit = Int53.fromString(fee.gas).toNumber();
const feePayer = fee.granter == undefined ? "" : fee.granter;
const authInfoBytes = makeAuthInfoBytes([{ pubkey, sequence }], fee.amount, gasLimit, feePayer);
const feeGranter = fee.granter == undefined ? "" : fee.granter;
const feePayer = fee.payer == undefined ? "" : fee.payer;
const authInfoBytes = makeAuthInfoBytes(
[{ pubkey, sequence }],
fee.amount,
gasLimit,
feeGranter,
feePayer,
);
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
const { signature, signed } = await this.signer.signDirect(signerAddress, signDoc);
return TxRaw.fromPartial({

View File

@ -74,8 +74,9 @@ async function sendTokens(
},
];
const gasLimit = 200000;
const feeGranter = "";
const feePayer = "";
const authInfoBytes = makeAuthInfoBytes([{ pubkey, sequence }], feeAmount, gasLimit, feePayer);
const authInfoBytes = makeAuthInfoBytes([{ pubkey, sequence }], feeAmount, gasLimit, feeGranter, feePayer);
const chainId = await client.getChainId();
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);

View File

@ -364,8 +364,15 @@ describe("StargateClient", () => {
const { accountNumber, sequence } = (await client.getSequence(address))!;
const feeAmount = coins(2000, "ucosm");
const gasLimit = 200000;
const feeGranter = "";
const feePayer = "";
const authInfoBytes = makeAuthInfoBytes([{ pubkey, sequence }], feeAmount, gasLimit, feePayer);
const authInfoBytes = makeAuthInfoBytes(
[{ pubkey, sequence }],
feeAmount,
gasLimit,
feeGranter,
feePayer,
);
const chainId = await client.getChainId();
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
@ -422,11 +429,13 @@ describe("StargateClient", () => {
const { accountNumber, sequence } = (await client.getSequence(address))!;
const feeAmount = coins(2000, "ucosm");
const gasLimit = 200000;
const feeGranter = "";
const feePayer = "";
const authInfoBytes = makeAuthInfoBytes(
[{ pubkey, sequence }],
feeAmount,
gasLimit,
feeGranter,
feePayer,
sequence,
);
@ -490,6 +499,7 @@ describe("StargateClient", () => {
const chainId = await client.getChainId();
const feeAmount = coins(2000, "ucosm");
const gasLimit = 200000;
const feeGranter = "";
const feePayer = "";
const { accountNumber: accountNumber1, sequence: sequence1 } = (await client.getSequence(address))!;
@ -497,6 +507,7 @@ describe("StargateClient", () => {
[{ pubkey, sequence: sequence1 }],
feeAmount,
gasLimit,
feeGranter,
feePayer,
);
const signDoc1 = makeSignDoc(txBodyBytes, authInfoBytes1, chainId, accountNumber1);
@ -516,6 +527,7 @@ describe("StargateClient", () => {
[{ pubkey, sequence: sequence2 }],
feeAmount,
gasLimit,
feeGranter,
feePayer,
);
const signDoc2 = makeSignDoc(txBodyBytes, authInfoBytes2, chainId, accountNumber2);

View File

@ -234,6 +234,7 @@ export class ModifyingDirectSecp256k1HdWallet extends DirectSecp256k1HdWallet {
}));
const modifiedFeeAmount = coins(3000, "ucosm");
const modifiedGasLimit = 333333;
const modifiedFeeGranter = "";
const modifiedFeePayer = "";
const modifiedSignDoc = {
...signDoc,
@ -242,6 +243,7 @@ export class ModifyingDirectSecp256k1HdWallet extends DirectSecp256k1HdWallet {
signers,
modifiedFeeAmount,
modifiedGasLimit,
modifiedFeeGranter,
modifiedFeePayer,
SignMode.SIGN_MODE_DIRECT,
),