Merge pull request #1176 from cosmos/crate-makeMultisignedTxBytes

Add makeMultisignedTxBytes
This commit is contained in:
Simon Warta
2022-06-20 13:24:16 +02:00
committed by GitHub
4 changed files with 36 additions and 6 deletions
+7
View File
@@ -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`
+1 -1
View File
@@ -82,7 +82,7 @@ export {
createIbcAminoConverters,
createStakingAminoConverters,
} from "./modules";
export { makeMultisignedTx } from "./multisignature";
export { makeMultisignedTx, makeMultisignedTxBytes } from "./multisignature";
export {
createPagination,
createProtobufRpcClient,
+4 -5
View File
@@ -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";
@@ -169,7 +168,7 @@ describe("multisignature", () => {
});
});
describe("makeMultisignedTx", () => {
describe("makeMultisignedTxBytes", () => {
it("works", async () => {
pendingWithoutSimapp();
const multisigAccountAddress = "cosmos1h90ml36rcu7yegwduzgzderj2jmq49hcpfclw9";
@@ -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,
@@ -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);
}
});
+24
View File
@@ -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,
@@ -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());
}