Skip to content

Commit

Permalink
fix(tx-builder): buildTx produces the same type as unpackTx accepts
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jun 29, 2023
1 parent 7509795 commit d3d6c88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions src/tx/builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export function getSchema(tag: Tag, version?: number): Array<[string, Field]> {
return Object.entries(schema);
}

type TxEncoding = Encoding.Transaction | Encoding.Poi | Encoding.StateTrees
| Encoding.CallStateTree;

/**
* Build transaction hash
* @category transaction builder
Expand All @@ -31,15 +34,9 @@ export function getSchema(tag: Tag, version?: number): Array<[string, Field]> {
* @param options.prefix - Prefix of transaction
* @returns object Base64Check transaction hash with 'tx_' prefix
*/
export function buildTx<
E extends Encoding = Encoding.Transaction,
>(
export function buildTx<E extends TxEncoding = Encoding.Transaction>(
params: TxParams,
{
prefix,
}: {
prefix?: E;
} = {},
{ prefix }: { prefix?: E } = {},
): Encoded.Generic<E> {
const schema = getSchema(params.tag, params.version);

Expand Down Expand Up @@ -92,7 +89,7 @@ export async function buildTxAsync(params: TxParamsAsync): Promise<Encoded.Trans
* @returns Object with transaction param's
*/
export function unpackTx<TxType extends Tag>(
encodedTx: Encoded.Transaction | Encoded.Poi | Encoded.StateTrees | Encoded.CallStateTree,
encodedTx: Encoded.Generic<TxEncoding>,
txType?: TxType,
): TxUnpacked & { tag: TxType } {
const binary = rlpDecode(decode(encodedTx));
Expand Down
2 changes: 1 addition & 1 deletion test/integration/Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('MiddlewareSubscriber', () => {
},
mdwGensPerMinute: res.mdwGensPerMinute,
mdwHeight: res.mdwHeight,
mdwLastMigration: 20230519120000,
mdwLastMigration: res.mdwLastMigration,
mdwRevision: res.mdwRevision,
mdwSynced: true,
mdwSyncing: true,
Expand Down

0 comments on commit d3d6c88

Please sign in to comment.