@faast/ethereum-payments
Version:
Library to assist in processing ethereum payments, such as deriving addresses and sweeping funds
36 lines • 1.73 kB
JavaScript
import { PaymentsFactory } from '@faast/payments-common';
import { assertType } from '@faast/ts-common';
import { EthereumPaymentsUtilsConfig, HdEthereumPaymentsConfig, KeyPairEthereumPaymentsConfig, HdErc20PaymentsConfig, KeyPairErc20PaymentsConfig, } from './types';
import { PACKAGE_NAME } from './constants';
import { EthereumConnectionManager } from './EthereumConnectionManager';
import { EthereumPaymentsUtils } from './EthereumPaymentsUtils';
import { HdEthereumPayments } from './HdEthereumPayments';
import { KeyPairEthereumPayments } from './KeyPairEthereumPayments';
import { HdErc20Payments } from './erc20/HdErc20Payments';
export class EthereumPaymentsFactory extends PaymentsFactory {
constructor() {
super(...arguments);
this.packageName = PACKAGE_NAME;
this.connectionManager = new EthereumConnectionManager();
}
newPayments(config) {
if (HdErc20PaymentsConfig.is(config)) {
return new HdErc20Payments(config);
}
if (KeyPairErc20PaymentsConfig.is(config)) {
throw new Error(`Cannot instantiate ${this.packageName} for unsupported KeyPairErc20PaymentsConfig`);
}
if (HdEthereumPaymentsConfig.is(config)) {
return new HdEthereumPayments(config);
}
if (KeyPairEthereumPaymentsConfig.is(config)) {
return new KeyPairEthereumPayments(config);
}
throw new Error(`Cannot instantiate ${this.packageName} for unsupported config`);
}
newUtils(config) {
return new EthereumPaymentsUtils(assertType(EthereumPaymentsUtilsConfig, config, 'config'));
}
}
export default EthereumPaymentsFactory;
//# sourceMappingURL=EthereumPaymentsFactory.js.map