From 44d58f1ba15c521ca15bae6bd3c64607314b6c77 Mon Sep 17 00:00:00 2001 From: Raptor Date: Tue, 25 Aug 2020 12:27:20 -0700 Subject: [PATCH] Add txParams function to the harmony-js/staking --- .../harmony-staking/src/stakingTransaction.ts | 25 +++++++++++++++++++ packages/harmony-staking/src/types.ts | 22 ++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 packages/harmony-staking/src/types.ts diff --git a/packages/harmony-staking/src/stakingTransaction.ts b/packages/harmony-staking/src/stakingTransaction.ts index 7c3165c..1ff0f26 100644 --- a/packages/harmony-staking/src/stakingTransaction.ts +++ b/packages/harmony-staking/src/stakingTransaction.ts @@ -20,6 +20,7 @@ import { Messenger, RPCMethod } from '@harmony-js/network'; import { defaultMessenger, TransactionBase, TxStatus } from '@harmony-js/transaction'; import { numberToHex, Unit } from '@harmony-js/utils'; import { TextEncoder } from 'text-encoding'; +import { StakingTxParams } from './types'; /** @hidden */ export class StakingSettings { @@ -77,6 +78,30 @@ export class StakingTransaction extends TransactionBase { this.from = '0x'; } + /** + * get staking transaction params + * + * @example + * ``` + * const txParams = txn.txParams; + * console.log(txParams) + * ``` + */ + get txParams(): StakingTxParams { + return { + directive: this.directive, + stakeMsg: this.stakeMsg, + nonce: this.nonce || 0, + gasPrice: this.gasPrice || new Unit(0).asWei().toWei(), + gasLimit: this.gasLimit || new Unit(0).asWei().toWei(), + chainId: this.chainId || 0, + rawTransaction: this.rawTransaction || '0x', + unsignedRawTransaction: this.unsignedRawTransaction || '0x', + signature: this.signature || '0x', + from: this.from || '', + }; + } + encode(): [string, any[]] { const raw: Array> = []; // TODO: temporary hack for converting 0x00 to 0x diff --git a/packages/harmony-staking/src/types.ts b/packages/harmony-staking/src/types.ts new file mode 100644 index 0000000..660a07b --- /dev/null +++ b/packages/harmony-staking/src/types.ts @@ -0,0 +1,22 @@ +import { BN, Signature } from '@harmony-js/crypto'; +import { + Directive, + CreateValidator, + EditValidator, + Delegate, + Undelegate, + CollectRewards, +} from '@harmony-js/staking'; + +export interface StakingTxParams { + directive: Directive; + stakeMsg: CreateValidator | EditValidator | Delegate | Undelegate | CollectRewards; + nonce: number | string; + gasLimit: number | string | BN; + gasPrice: number | string | BN; + chainId: number; + rawTransaction: string; + unsignedRawTransaction: string; + signature: Signature; + from: string; +}