You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
import { getContractAddress, getAddress } from '@harmony-js/crypto';
|
|
import { Messenger } from '@harmony-js/network';
|
|
import { Transaction } from './transaction';
|
|
import { TxParams, TxStatus } from './types';
|
|
|
|
export class TransactionFactory {
|
|
static getContractAddress(tx: Transaction) {
|
|
const { from, nonce } = tx.txParams;
|
|
return getAddress(getContractAddress(from, Number.parseInt(`${nonce}`, 10)))
|
|
.checksum;
|
|
}
|
|
|
|
messenger: Messenger;
|
|
constructor(messenger: Messenger) {
|
|
this.messenger = messenger;
|
|
}
|
|
setMessenger(messenger: Messenger) {
|
|
this.messenger = messenger;
|
|
}
|
|
|
|
newTx(txParams?: TxParams | any): Transaction {
|
|
return new Transaction(txParams, this.messenger, TxStatus.INTIALIZED);
|
|
}
|
|
|
|
clone(transaction: Transaction): Transaction {
|
|
return new Transaction(
|
|
transaction.txParams,
|
|
this.messenger,
|
|
TxStatus.INTIALIZED,
|
|
);
|
|
}
|
|
|
|
recover(txHash: string): Transaction {
|
|
const newTxn = new Transaction({}, this.messenger, TxStatus.INTIALIZED);
|
|
newTxn.recover(txHash);
|
|
return newTxn;
|
|
}
|
|
}
|
|
|