Skip to content

Commit

Permalink
fix: remove unused gas payer in build TX functions
Browse files Browse the repository at this point in the history
  • Loading branch information
emccorson committed Jul 16, 2024
1 parent 7c8a8a9 commit 798e4e8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 134 deletions.
2 changes: 1 addition & 1 deletion apps/namadillo/src/lib/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const buildBatchTx = async <T>(
).data;

if (!publicKey) {
const revealPkTx = await tx.buildRevealPk(wrapperTxProps, account.address);
const revealPkTx = await tx.buildRevealPk(wrapperTxProps);
txs.push(revealPkTx.tx);
}

Expand Down
115 changes: 30 additions & 85 deletions packages/sdk/src/tx/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,14 @@ export class Tx {
* @param txType - type of the transaction
* @param encodedSpecificTx - encoded specific transaction
* @param wrapperTxMsg - encoded transaction
* @param gasPayer - address of the gas payer
* @returns promise that resolves to an EncodedTx
*/
async buildTxFromSerializedArgs(
txType: TxType,
encodedSpecificTx: Uint8Array,
wrapperTxMsg: Uint8Array,
gasPayer: string
wrapperTxMsg: Uint8Array
): Promise<EncodedTx> {
const tx = await this.sdk.build_tx(
txType,
encodedSpecificTx,
wrapperTxMsg,
gasPayer
);
const tx = await this.sdk.build_tx(txType, encodedSpecificTx, wrapperTxMsg);

return new EncodedTx(wrapperTxMsg, tx);
}
Expand All @@ -75,69 +68,50 @@ export class Tx {
* @param txType - type of the transaction
* @param wrapperTxProps - transaction properties
* @param props - Props specific to type of Tx
* @param [gasPayer] - optional gas payer, defaults to source or sender
* @returns promise that resolves to an EncodedTx
*/
async buildTx(
txType: TxType,
wrapperTxProps: WrapperTxProps,
props: unknown,
gasPayer?: string
props: unknown
): Promise<EncodedTx> {
switch (txType) {
case TxType.Bond:
return await this.buildBond(
wrapperTxProps,
props as BondProps,
gasPayer
);
return await this.buildBond(wrapperTxProps, props as BondProps);
case TxType.Unbond:
return await this.buildUnbond(
wrapperTxProps,
props as UnbondProps,
gasPayer
);
return await this.buildUnbond(wrapperTxProps, props as UnbondProps);
case TxType.Withdraw:
return await this.buildWithdraw(
wrapperTxProps,
props as WithdrawProps,
gasPayer
);
return await this.buildWithdraw(wrapperTxProps, props as WithdrawProps);
case TxType.Redelegate:
return await this.buildRedelegate(
wrapperTxProps,
props as RedelegateProps,
gasPayer
props as RedelegateProps
);
case TxType.RevealPK:
const { publicKey } = wrapperTxProps;
if (!publicKey) {
throw new Error("For RevealPK you must provide a public key!");
}
return await this.buildRevealPk(wrapperTxProps, publicKey);
return await this.buildRevealPk(wrapperTxProps);
case TxType.Transfer:
return await this.buildTransparentTransfer(
wrapperTxProps,
props as TransferProps,
gasPayer
props as TransferProps
);
case TxType.IBCTransfer:
return await this.buildIbcTransfer(
wrapperTxProps,
props as IbcTransferProps,
gasPayer
props as IbcTransferProps
);
case TxType.VoteProposal:
return await this.buildVoteProposal(
wrapperTxProps,
props as VoteProposalProps,
gasPayer
props as VoteProposalProps
);
case TxType.EthBridgeTransfer:
return await this.buildEthBridgeTransfer(
wrapperTxProps,
props as EthBridgeTransferProps,
gasPayer
props as EthBridgeTransferProps
);
default:
throw new Error(`Unsupported Tx type: ${txType}`);
Expand All @@ -149,13 +123,11 @@ export class Tx {
* @async
* @param wrapperTxProps - properties of the transaction
* @param transferProps - properties of the transfer
* @param [gasPayer] - optional gas payer, if not provided, defaults to transferProps.source
* @returns promise that resolves to an EncodedTx
*/
async buildTransparentTransfer(
wrapperTxProps: WrapperTxProps,
transferProps: TransferProps,
gasPayer?: string
transferProps: TransferProps
): Promise<EncodedTx> {
const transferMsg = new Message<TransferMsgValue>();

Expand All @@ -167,29 +139,23 @@ export class Tx {
return await this.buildTxFromSerializedArgs(
TxType.Transfer,
encodedTransfer,
encodedTx,
gasPayer || transferProps.data[0].source
encodedTx
);
}

/**
* Build RevealPK Tx
* @async
* @param wrapperTxProps - properties of the transaction
* @param gasPayer - address for gas payer
* @returns promise that resolves to an EncodedTx
*/
async buildRevealPk(
wrapperTxProps: WrapperTxProps,
gasPayer: string
): Promise<EncodedTx> {
async buildRevealPk(wrapperTxProps: WrapperTxProps): Promise<EncodedTx> {
const encodedTx = this.encodeTxArgs(wrapperTxProps);

return await this.buildTxFromSerializedArgs(
TxType.RevealPK,
new Uint8Array(),
encodedTx,
gasPayer
encodedTx
);
}

Expand All @@ -198,13 +164,11 @@ export class Tx {
* @async
* @param wrapperTxProps - properties of the transaction
* @param bondProps - properties of the bond tx
* @param [gasPayer] - optional gas payer, if not provided, defaults to bondProps.source
* @returns promise that resolves to an EncodedTx
*/
async buildBond(
wrapperTxProps: WrapperTxProps,
bondProps: BondProps,
gasPayer?: string
bondProps: BondProps
): Promise<EncodedTx> {
const bondMsg = new Message<BondMsgValue>();
const encodedTx = this.encodeTxArgs(wrapperTxProps);
Expand All @@ -213,8 +177,7 @@ export class Tx {
return await this.buildTxFromSerializedArgs(
TxType.Bond,
encodedBond,
encodedTx,
gasPayer || bondProps.source
encodedTx
);
}

Expand All @@ -223,13 +186,11 @@ export class Tx {
* @async
* @param wrapperTxProps - properties of the transaction
* @param unbondProps - properties of the unbond tx
* @param [gasPayer] - optional gas payer, if not provided, defaults to unbondProps.source
* @returns promise that resolves to an EncodedTx
*/
async buildUnbond(
wrapperTxProps: WrapperTxProps,
unbondProps: UnbondProps,
gasPayer?: string
unbondProps: UnbondProps
): Promise<EncodedTx> {
const bondMsg = new Message<UnbondMsgValue>();
const encodedTx = this.encodeTxArgs(wrapperTxProps);
Expand All @@ -238,8 +199,7 @@ export class Tx {
return await this.buildTxFromSerializedArgs(
TxType.Unbond,
encodedUnbond,
encodedTx,
gasPayer || unbondProps.source
encodedTx
);
}

Expand All @@ -248,13 +208,11 @@ export class Tx {
* @async
* @param wrapperTxProps - properties of the transaction
* @param withdrawProps - properties of the withdraw tx
* @param [gasPayer] - optional gas payer, if not provided, defaults to withdrawProps.source
* @returns promise that resolves to an EncodedTx
*/
async buildWithdraw(
wrapperTxProps: WrapperTxProps,
withdrawProps: WithdrawProps,
gasPayer?: string
withdrawProps: WithdrawProps
): Promise<EncodedTx> {
const bondMsg = new Message<WithdrawProps>();
const encodedTx = this.encodeTxArgs(wrapperTxProps);
Expand All @@ -263,8 +221,7 @@ export class Tx {
return await this.buildTxFromSerializedArgs(
TxType.Withdraw,
encodedWithdraw,
encodedTx,
gasPayer || withdrawProps.source
encodedTx
);
}

Expand All @@ -273,13 +230,11 @@ export class Tx {
* @async
* @param wrapperTxProps - properties of the transaction
* @param redelegateProps - properties of the redelegate tx
* @param [gasPayer] - optional gas payer, if not provided, defaults to redelegateProps.owner
* @returns promise that resolves to an EncodedTx
*/
async buildRedelegate(
wrapperTxProps: WrapperTxProps,
redelegateProps: RedelegateProps,
gasPayer?: string
redelegateProps: RedelegateProps
): Promise<EncodedTx> {
const redelegateMsg = new Message<RedelegateMsgValue>();
const encodedTx = this.encodeTxArgs(wrapperTxProps);
Expand All @@ -290,8 +245,7 @@ export class Tx {
return await this.buildTxFromSerializedArgs(
TxType.Redelegate,
encodedRedelegate,
encodedTx,
gasPayer || redelegateProps.owner
encodedTx
);
}

Expand All @@ -300,13 +254,11 @@ export class Tx {
* @async
* @param wrapperTxProps - properties of the transaction
* @param ibcTransferProps - properties of the ibc transfer tx
* @param [gasPayer] - optional gas payer, if not provided, defaults to ibcTransferProps.source
* @returns promise that resolves to an EncodedTx
*/
async buildIbcTransfer(
wrapperTxProps: WrapperTxProps,
ibcTransferProps: IbcTransferProps,
gasPayer?: string
ibcTransferProps: IbcTransferProps
): Promise<EncodedTx> {
const ibcTransferMsg = new Message<IbcTransferProps>();
const encodedTx = this.encodeTxArgs(wrapperTxProps);
Expand All @@ -317,8 +269,7 @@ export class Tx {
return await this.buildTxFromSerializedArgs(
TxType.IBCTransfer,
encodedIbcTransfer,
encodedTx,
gasPayer || ibcTransferProps.source
encodedTx
);
}

Expand All @@ -327,13 +278,11 @@ export class Tx {
* @async
* @param wrapperTxProps - properties of the transaction
* @param ethBridgeTransferProps - properties of the eth bridge transfer tx
* @param [gasPayer] - optional gas payer, if not provided, defaults to ethBridgeTransferProps.sender
* @returns promise that resolves to an EncodedTx
*/
async buildEthBridgeTransfer(
wrapperTxProps: WrapperTxProps,
ethBridgeTransferProps: EthBridgeTransferProps,
gasPayer?: string
ethBridgeTransferProps: EthBridgeTransferProps
): Promise<EncodedTx> {
const ethBridgeTransferMsg = new Message<EthBridgeTransferProps>();
const encodedTx = this.encodeTxArgs(wrapperTxProps);
Expand All @@ -344,8 +293,7 @@ export class Tx {
return await this.buildTxFromSerializedArgs(
TxType.EthBridgeTransfer,
encodedEthBridgeTransfer,
encodedTx,
gasPayer || ethBridgeTransferProps.sender
encodedTx
);
}

Expand All @@ -354,13 +302,11 @@ export class Tx {
* @async
* @param wrapperTxProps - properties of the transaction
* @param voteProposalProps - properties of the vote proposal tx
* @param [gasPayer] - optional gas payer, if not provided, defaults to voteProposalProps.signer
* @returns promise that resolves to an EncodedTx
*/
async buildVoteProposal(
wrapperTxProps: WrapperTxProps,
voteProposalProps: VoteProposalProps,
gasPayer?: string
voteProposalProps: VoteProposalProps
): Promise<EncodedTx> {
const voteProposalMsg = new Message<VoteProposalProps>();
const encodedTx = this.encodeTxArgs(wrapperTxProps);
Expand All @@ -371,8 +317,7 @@ export class Tx {
return await this.buildTxFromSerializedArgs(
TxType.VoteProposal,
encodedVoteProposal,
encodedTx,
gasPayer || voteProposalProps.signer
encodedTx
);
}

Expand Down
Loading

0 comments on commit 798e4e8

Please sign in to comment.