Skip to content

Commit

Permalink
Add makeMultisignedTxBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Jun 15, 2022
1 parent 42e39f9 commit c78031f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to

## [Unreleased]

### Added

- @cosmjs/stargate: Add `makeMultisignedTxBytes` which is like
`makeMultisignedTx` but returns bytes ready to broadcast ([#1176]).

[#1176]: https://github.com/cosmos/cosmjs/pull/1176

### Fixed

- @cosmjs/stargate: Fix valid values of `BondStatusString` for `validators`
Expand Down
2 changes: 1 addition & 1 deletion packages/stargate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export {
createIbcAminoConverters,
createStakingAminoConverters,
} from "./modules";
export { makeMultisignedTx } from "./multisignature";
export { makeMultisignedTx, makeMultisignedTxBytes } from "./multisignature";
export {
createPagination,
createProtobufRpcClient,
Expand Down
9 changes: 4 additions & 5 deletions packages/stargate/src/multisignature.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import {
import { coins } from "@cosmjs/proto-signing";
import { assert } from "@cosmjs/utils";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";

import { MsgSendEncodeObject } from "./modules";
import { makeCompactBitArray, makeMultisignedTx } from "./multisignature";
import { makeCompactBitArray, makeMultisignedTxBytes } from "./multisignature";
import { SignerData, SigningStargateClient } from "./signingstargateclient";
import { assertIsDeliverTxSuccess, StargateClient } from "./stargateclient";
import { faucet, pendingWithoutSimapp, simapp } from "./testutils.spec";
Expand Down Expand Up @@ -169,7 +168,7 @@ describe("multisignature", () => {
});
});

describe("makeMultisignedTx", () => {
describe("makeMultisignedTxBytes", () => {
it("works", async () => {
pendingWithoutSimapp();
const multisigAccountAddress = "cosmos1h90ml36rcu7yegwduzgzderj2jmq49hcpfclw9";
Expand Down Expand Up @@ -253,7 +252,7 @@ describe("multisignature", () => {
const address4 = pubkeyToAddress(pubkey4, "cosmos");

const broadcaster = await StargateClient.connect(simapp.tendermintUrl);
const signedTx = makeMultisignedTx(
const signedTx = makeMultisignedTxBytes(
multisigPubkey,
signingInstruction.sequence,
signingInstruction.fee,
Expand All @@ -267,7 +266,7 @@ describe("multisignature", () => {
]),
);
// ensure signature is valid
const result = await broadcaster.broadcastTx(Uint8Array.from(TxRaw.encode(signedTx).finish()));
const result = await broadcaster.broadcastTx(signedTx);
assertIsDeliverTxSuccess(result);
}
});
Expand Down
24 changes: 24 additions & 0 deletions packages/stargate/src/multisignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export function makeCompactBitArray(bits: readonly boolean[]): CompactBitArray {
return CompactBitArray.fromPartial({ elems: bytes, extraBitsStored: extraBits });
}

/**
* Creates a signed transaction from signer info, transaction body and signatures.
* The result can be broadcasted after serialization.
*
* Consider using `makeMultisignedTxBytes` instead if you want to broadcast the
* transaction immediately.
*/
export function makeMultisignedTx(
multisigPubkey: MultisigThresholdPubkey,
sequence: number,
Expand Down Expand Up @@ -70,3 +77,20 @@ export function makeMultisignedTx(
});
return signedTx;
}

/**
* Creates a signed transaction from signer info, transaction body and signatures.
* The result can be broadcasted.
*
* This is a wrapper around `makeMultisignedTx` that encodes the transaction for broadcasting.
*/
export function makeMultisignedTxBytes(
multisigPubkey: MultisigThresholdPubkey,
sequence: number,
fee: StdFee,
bodyBytes: Uint8Array,
signatures: Map<string, Uint8Array>,
): Uint8Array {
const signedTx = makeMultisignedTx(multisigPubkey, sequence, fee, bodyBytes, signatures);
return Uint8Array.from(TxRaw.encode(signedTx).finish());
}

0 comments on commit c78031f

Please sign in to comment.