UNPKG

@wavesenterprise/generator-cli

Version:

Waves Enterprise transactions generator CLI

60 lines (54 loc) 1.79 kB
import { IConfig, TxType } from "../interfaces"; import { ISeed } from "../generator"; export interface Tx104Body { contractId: string; contractVersion: string; fee: string; params: any } export class TxGeneratorService { constructor(private config: IConfig, private wavesApi: any) { this.wavesApi = wavesApi this.config = config } public createTx104 = (txData: Tx104Body, seed: ISeed) => { const { contractId, contractVersion, fee, params = [] } = txData const txBody = { authorPublicKey: seed.keyPair.publicKey, contractId, contractVersion: Number(contractVersion), timestamp: Date.now(), params, fee }; return this.wavesApi.API.Transactions.CallContract.V4(txBody) } public generateSignedTxs = async (accounts: ISeed[]) => { const { generator: { txsFormat, txsNumber, distribution, templates } } = this.config const signedPromises: any[] = [] const txs = Object.entries(distribution) for (let i = 0; i < txs.length; i++) { const [txType, percentage] = txs[i] let txTypeCount = Math.floor((txsNumber * (Number(percentage) / 100))) if (txTypeCount < 1) { txTypeCount = 1 } for (let j = 0; j < txTypeCount; j++) { const account = accounts[(i + 1) * j] switch (txType) { case TxType.DockerCall: { const txBody = templates[txType] const tx = this.createTx104(txBody, account) if (txsFormat === 'grpc') { signedPromises.push(tx.getSignedGrpcTx(account.keyPair)) } else { signedPromises.push(tx.getSignedTx(account.keyPair)) } } } } } const signedTxs = await Promise.all(signedPromises) return signedTxs } }