bitcore-wallet-service
Version:
A service for Mutisig HD Bitcoin Wallets
140 lines • 5.09 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChainService = void 0;
const common_1 = require("../common");
const logger_1 = __importDefault(require("./../logger"));
const arb_1 = require("./arb");
const base_1 = require("./base");
const bch_1 = require("./bch");
const btc_1 = require("./btc");
const doge_1 = require("./doge");
const eth_1 = require("./eth");
const ltc_1 = require("./ltc");
const matic_1 = require("./matic");
const op_1 = require("./op");
const sol_1 = require("./sol");
const xrp_1 = require("./xrp");
const Constants = common_1.Common.Constants;
const Defaults = common_1.Common.Defaults;
const chains = {
BTC: new btc_1.BtcChain(),
BCH: new bch_1.BchChain(),
ETH: new eth_1.EthChain(),
MATIC: new matic_1.MaticChain(),
ARB: new arb_1.ArbChain(),
BASE: new base_1.BaseChain(),
OP: new op_1.OpChain(),
XRP: new xrp_1.XrpChain(),
DOGE: new doge_1.DogeChain(),
LTC: new ltc_1.LtcChain(),
SOL: new sol_1.SolChain()
};
class ChainProxy {
get(chain) {
const normalizedChain = chain.toUpperCase();
return chains[normalizedChain];
}
getChain(coin) {
try {
if (coin === undefined) {
return Defaults.CHAIN;
}
let normalizedChain = coin.toLowerCase();
if (Constants.BITPAY_SUPPORTED_ETH_ERC20[normalizedChain.toUpperCase()] ||
!Constants.CHAINS[normalizedChain.toUpperCase()]) {
normalizedChain = 'eth';
}
return normalizedChain;
}
catch (err) {
logger_1.default.error(`Error getting chain for coin ${coin}: %o`, err.stack || err.message || err);
return Defaults.CHAIN;
}
}
getWalletBalance(server, wallet, opts, cb) {
return this.get(wallet.chain).getWalletBalance(server, wallet, opts, cb);
}
getWalletSendMaxInfo(server, wallet, opts, cb) {
return this.get(wallet.chain).getWalletSendMaxInfo(server, wallet, opts, cb);
}
getDustAmountValue(chain) {
return this.get(chain).getDustAmountValue();
}
getTransactionCount(server, wallet, from) {
return this.get(wallet.chain).getTransactionCount(server, wallet, from);
}
getChangeAddress(server, wallet, opts) {
return this.get(wallet.chain).getChangeAddress(server, wallet, opts);
}
checkDust(chain, output, opts) {
return this.get(chain).checkDust(output, opts);
}
checkScriptOutput(chain, output) {
return this.get(chain).checkScriptOutput(output);
}
getFee(server, wallet, opts) {
return this.get(wallet.chain).getFee(server, wallet, opts);
}
getBitcoreTx(txp, opts = { signed: true }) {
return this.get(txp.chain).getBitcoreTx(txp, { signed: opts.signed });
}
convertFeePerKb(chain, p, feePerKb) {
return this.get(chain).convertFeePerKb(p, feePerKb);
}
addressToStorageTransform(chain, network, address) {
return this.get(chain).addressToStorageTransform(network, address);
}
addressFromStorageTransform(chain, network, address) {
return this.get(chain).addressFromStorageTransform(network, address);
}
checkTx(server, txp) {
return this.get(txp.chain).checkTx(server, txp);
}
checkTxUTXOs(server, txp, opts, cb) {
return this.get(txp.chain).checkTxUTXOs(server, txp, opts, cb);
}
selectTxInputs(server, txp, wallet, opts, cb) {
return this.get(txp.chain).selectTxInputs(server, txp, wallet, opts, cb);
}
checkUtxos(chain, opts) {
return this.get(chain).checkUtxos(opts);
}
checkValidTxAmount(chain, output) {
return this.get(chain).checkValidTxAmount(output);
}
isUTXOChain(chain) {
return this.get(chain).isUTXOChain();
}
isSingleAddress(chain) {
return this.get(chain).isSingleAddress();
}
notifyConfirmations(chain, network) {
return this.get(chain).notifyConfirmations(network);
}
supportsMultisig(chain) {
return this.get(chain).supportsMultisig();
}
addSignaturesToBitcoreTx(chain, tx, inputs, inputPaths, signatures, xpub, signingMethod) {
this.get(chain).addSignaturesToBitcoreTx(tx, inputs, inputPaths, signatures, xpub, signingMethod);
}
validateAddress(wallet, inaddr, opts) {
return this.get(wallet.chain).validateAddress(wallet, inaddr, opts);
}
onCoin(chain, coinData) {
return this.get(chain).onCoin(coinData);
}
onTx(chain, tx) {
return this.get(chain).onTx(tx);
}
getReserve(server, wallet, cb) {
return this.get(wallet.chain).getReserve(server, wallet, cb);
}
refreshTxData(server, txp, opts, cb) {
return this.get(txp.chain).refreshTxData(server, txp, opts, cb);
}
}
exports.ChainService = new ChainProxy();
//# sourceMappingURL=index.js.map