mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
stargate: Add delegateTokens method to SigningStargateClient
This commit is contained in:
parent
a2fd121bca
commit
c0ccf9be0c
@ -40,6 +40,15 @@ describe("SigningStargateClient", () => {
|
||||
],
|
||||
gas: "80000",
|
||||
},
|
||||
delegate: {
|
||||
amount: [
|
||||
{
|
||||
amount: "4000",
|
||||
denom: "ucosm",
|
||||
},
|
||||
],
|
||||
gas: "160000",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@ -71,6 +80,15 @@ describe("SigningStargateClient", () => {
|
||||
],
|
||||
gas: "80000",
|
||||
},
|
||||
delegate: {
|
||||
amount: [
|
||||
{
|
||||
amount: "502400", // 3.14 * 160_000
|
||||
denom: "utest",
|
||||
},
|
||||
],
|
||||
gas: "160000",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@ -79,6 +97,7 @@ describe("SigningStargateClient", () => {
|
||||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic);
|
||||
const gasLimits = {
|
||||
send: 160000,
|
||||
delegate: 120000,
|
||||
};
|
||||
const options = { gasLimits: gasLimits };
|
||||
const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet, options);
|
||||
@ -93,6 +112,15 @@ describe("SigningStargateClient", () => {
|
||||
],
|
||||
gas: "160000",
|
||||
},
|
||||
delegate: {
|
||||
amount: [
|
||||
{
|
||||
amount: "3000", // 0.025 * 120_000
|
||||
denom: "ucosm",
|
||||
},
|
||||
],
|
||||
gas: "120000",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@ -102,6 +130,7 @@ describe("SigningStargateClient", () => {
|
||||
const gasPrice = GasPrice.fromString("3.14utest");
|
||||
const gasLimits = {
|
||||
send: 160000,
|
||||
delegate: 160000,
|
||||
};
|
||||
const options = { gasPrice: gasPrice, gasLimits: gasLimits };
|
||||
const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet, options);
|
||||
@ -116,6 +145,15 @@ describe("SigningStargateClient", () => {
|
||||
],
|
||||
gas: "160000",
|
||||
},
|
||||
delegate: {
|
||||
amount: [
|
||||
{
|
||||
amount: "502400", // 3.14 * 160_000
|
||||
denom: "utest",
|
||||
},
|
||||
],
|
||||
gas: "160000",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -66,10 +66,11 @@ import { BroadcastTxResponse, StargateClient } from "./stargateclient";
|
||||
*/
|
||||
export interface CosmosFeeTable extends FeeTable {
|
||||
readonly send: StdFee;
|
||||
readonly delegate: StdFee;
|
||||
}
|
||||
|
||||
const defaultGasPrice = GasPrice.fromString("0.025ucosm");
|
||||
const defaultGasLimits: GasLimits<CosmosFeeTable> = { send: 80000 };
|
||||
const defaultGasLimits: GasLimits<CosmosFeeTable> = { send: 80000, delegate: 160000 };
|
||||
|
||||
export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
["/cosmos.bank.v1beta1.MsgMultiSend", MsgMultiSend],
|
||||
@ -198,6 +199,19 @@ export class SigningStargateClient extends StargateClient {
|
||||
return this.signAndBroadcast(senderAddress, [sendMsg], this.fees.send, memo);
|
||||
}
|
||||
|
||||
public async delegateTokens(
|
||||
senderAddress: string,
|
||||
validatorAddress: string,
|
||||
amount: Coin,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
const delegateMsg = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
||||
value: MsgDelegate.fromPartial({ delegatorAddress: senderAddress, validatorAddress, amount }),
|
||||
};
|
||||
return this.signAndBroadcast(senderAddress, [delegateMsg], this.fees.delegate, memo);
|
||||
}
|
||||
|
||||
public async signAndBroadcast(
|
||||
signerAddress: string,
|
||||
messages: readonly EncodeObject[],
|
||||
|
Loading…
x
Reference in New Issue
Block a user