Add txParams function to the harmony-js/staking

staking_tnx_params
Raptor 4 years ago
parent 17bcd47f37
commit 44d58f1ba1
  1. 25
      packages/harmony-staking/src/stakingTransaction.ts
  2. 22
      packages/harmony-staking/src/types.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<string | Uint8Array | Array<string | Uint8Array>> = [];
// TODO: temporary hack for converting 0x00 to 0x

@ -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;
}
Loading…
Cancel
Save