import { BitcoinClient } from "./chains/bitcoin/bitcoinClient" ; import config from "./config" ; import { EthereumClient } from "./chains/ethereum/ethereumClient" ; import { BlockchainClient } from "./chains/blockchainClient" ; import { Currency } from "./common" ; import { Transaction } from "./chains/transaction" ; import { BitcoinTransaction } from "./chains/bitcoin/bitcoinTransaction" ; import { EthereumTransaction } from "./chains/ethereum/ethereumTransaction" ; export class BlockchainManager { private bitcoinClient : BlockchainClient ; private ethereumClient : BlockchainClient ; constructor ( ) { } public async init ( ) { this . bitcoinClient = new BitcoinClient ( config ) ; this . ethereumClient = new EthereumClient ( config ) ; await Promise . all ( [ this . bitcoinClient . init ( ) , this . ethereumClient . init ( ) ] ) ; } public async close ( ) { await Promise . all ( [ this . bitcoinClient . close ( ) , this . ethereumClient . close ( ) ] ) ; } public getAddress ( currency , publicKey ) { return this . getClient ( currency ) . getAddress ( publicKey ) ; } public buildTransaction ( currency , fromPublicKey , amount , toPublicKey ) { return this . getClient ( currency ) . buildTransaction ( fromPublicKey , amount , toPublicKey ) ; } public getBalance ( currency , publicKey ) { return this . getClient ( currency ) . getBalance ( publicKey ) ; } public sendSignedTransaction ( currency , txHex ) { return this . getClient ( currency ) . sendSignedTransaction ( txHex ) ; } public transactionFromBuffer ( currency , buffer ) { let tx ; switch ( currency ) { case "BTC" : tx = BitcoinTransaction . fromBuffer ( buffer ) ; break ; case "ETH" : tx = EthereumTransaction . fromBuffer ( buffer ) ; break ; } return tx ; } private getClient ( currency ) { let client ; switch ( currency ) { case "BTC" : client = this . bitcoinClient ; break ; case "ETH" : client = this . ethereumClient ; break ; } return client ; } }