Skip to content

Commit

Permalink
Merge branch 'cleanup' of github.com:kajoseph/bitcore
Browse files Browse the repository at this point in the history
  • Loading branch information
kajoseph committed Sep 27, 2023
2 parents 00753b6 + f055e23 commit 2f2b9ff
Show file tree
Hide file tree
Showing 37 changed files with 193 additions and 140 deletions.
17 changes: 16 additions & 1 deletion packages/bitcore-wallet-client/src/lib/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ var log = require('./log');
* @constructor
*/
export class Verifier {
private static _useRegtest: boolean = false;

static useRegtest() {
this._useRegtest = true;
}

static useTestnet() {
this._useRegtest = false;
}

/**
* Check address
*
Expand All @@ -28,12 +38,17 @@ export class Verifier {
'Failed state: credentials at <checkAddress>'
);

let network = credentials.network;
if (network === 'testnet' && this._useRegtest) {
network = 'regtest';
}

var local = Utils.deriveAddress(
address.type || credentials.addressType,
credentials.publicKeyRing,
address.path,
credentials.m,
credentials.network,
network,
credentials.chain,
escrowInputs
);
Expand Down
15 changes: 10 additions & 5 deletions packages/bitcore-wallet-service/bws.example.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,44 @@ module.exports = {
url: 'https://api.bitcore.io'
},
testnet: {
url: 'https://api.bitcore.io'
url: 'https://api.bitcore.io',
regtestEnabled: false
}
},
eth: {
livenet: {
url: 'https://api-eth.bitcore.io'
},
testnet: {
url: 'https://api-eth.bitcore.io'
url: 'https://api-eth.bitcore.io',
regtestEnabled: false
}
},
xrp: {
livenet: {
url: 'https://api-xrp.bitcore.io'
},
testnet: {
url: 'https://api-xrp.bitcore.io'
url: 'https://api-xrp.bitcore.io',
regtestEnabled: false
}
},
doge: {
livenet: {
url: 'https://api.bitcore.io'
},
testnet: {
url: 'https://api.bitcore.io'
url: 'https://api.bitcore.io',
regtestEnabled: false
}
},
ltc: {
livenet: {
url: 'https://api.bitcore.io'
},
testnet: {
url: 'https://api.bitcore.io'
url: 'https://api.bitcore.io',
regtestEnabled: false
}
},
socketApiKey: 'socketApiKey'
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcore-wallet-service/src/bcmonitor/bcmonitor.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env node
import _ from 'lodash';
import config from '../config';
import { BlockchainMonitor } from '../lib/blockchainmonitor';
import logger from '../lib/logger';

const config = require('../config');
const bcm = new BlockchainMonitor();
bcm.start(config, err => {
if (err) throw err;
Expand Down
7 changes: 3 additions & 4 deletions packages/bitcore-wallet-service/src/bws.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env node
import cluster from 'cluster';
import * as fs from 'fs';
import 'source-map-support/register';
import logger from './lib/logger';

import config from './config';
import { ExpressApp } from './lib/expressapp';
import logger from './lib/logger';

const config = require('./config');
const port = process.env.BWS_PORT || config.port || 3232;
const cluster = require('cluster');
const serverModule = config.https ? require('https') : require('http');

const serverOpts: {
Expand Down
4 changes: 2 additions & 2 deletions packages/bitcore-wallet-service/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
import { logger } from './lib/logger';

const Config = () => {
const Config = (): any => {
let defaultConfig = {
basePath: '/bws/api',
disableLogs: false,
Expand Down Expand Up @@ -390,4 +390,4 @@ const Config = () => {
return defaultConfig;
};

module.exports = Config();
export default Config();
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = (wallet, appName, appVersion) => {
export const serverMessages = (wallet, appName, appVersion) => {
if (!appVersion || !appName) return;

if (wallet.network == 'livenet' && appVersion.major == 5) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import config from '../config';
import { EmailService } from '../lib/emailservice';
import logger from '../lib/logger';
var config = require('../config');
const EmailService = require('../lib/emailservice');

const emailService = new EmailService();
emailService.start(config, err => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env node

import logger from '../lib/logger';
const config = require('../config');

import config from '../config';
import { FiatRateService } from '../lib/fiatrateservice';
import logger from '../lib/logger';

const service = new FiatRateService();
service.init(config, err => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,3 @@ export class BCHAddressTranslator {
else return ret[0];
}
}

module.exports = BCHAddressTranslator;
39 changes: 14 additions & 25 deletions packages/bitcore-wallet-service/src/lib/blockchainexplorer.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import _ from 'lodash';
import { V8 } from './blockchainexplorers/v8';
import { ChainService } from './chain/index';
import { Common } from './common';

const $ = require('preconditions').singleton();
const Defaults = Common.Defaults;

const PROVIDERS = {
v8: {
btc: {
livenet: 'https://api.bitpay.com',
testnet: 'https://api.bitpay.com'
livenet: 'https://api.bitcore.io',
testnet: 'https://api.bitcore.io'
},
bch: {
livenet: 'https://api.bitpay.com',
testnet: 'https://api.bitpay.com'
livenet: 'https://api.bitcore.io',
testnet: 'https://api.bitcore.io'
},
eth: {
livenet: 'https://api-eth.bitcore.io',
Expand All @@ -28,12 +26,12 @@ const PROVIDERS = {
testnet: 'https://api-xrp.bitcore.io'
},
doge: {
livenet: 'https://api.bitpay.com',
testnet: 'https://api.bitpay.com'
livenet: 'https://api.bitcore.io',
testnet: 'https://api.bitcore.io'
},
ltc: {
livenet: 'https://api.bitpay.com',
testnet: 'https://api.bitpay.com'
livenet: 'https://api.bitcore.io',
testnet: 'https://api.bitcore.io'
}
}
};
Expand All @@ -44,20 +42,12 @@ export function BlockChainExplorer(opts) {
const provider = opts.provider || 'v8';
const chain = opts.chain?.toLowerCase() || ChainService.getChain(opts.coin); // getChain -> backwards compatibility
const network = opts.network || 'livenet';
const url = opts.url || PROVIDERS[provider]?.[chain]?.[network];

$.checkState(PROVIDERS[provider], 'Provider ' + provider + ' not supported');
$.checkState(_.includes(_.keys(PROVIDERS[provider]), chain), 'Chain ' + chain + ' not supported by this provider');

$.checkState(
_.includes(_.keys(PROVIDERS[provider][chain]), network),
'Network ' + network + ' not supported by this provider for chain ' + chain
);

const url = opts.url || PROVIDERS[provider][chain][network];
$.checkState(url, `No url found for provider: ${provider}:${chain}:${network}`);

if (chain != 'bch' && opts.addressFormat) throw new Error('addressFormat only supported for bch');

if (chain == 'bch' && !opts.addressFormat) opts.addressFormat = 'cashaddr';
if (chain != 'bch' && opts.addressFormat) { throw new Error('addressFormat only supported for bch'); }
if (chain == 'bch' && !opts.addressFormat) { opts.addressFormat = 'cashaddr'; }

switch (provider) {
case 'v8':
Expand All @@ -69,8 +59,7 @@ export function BlockChainExplorer(opts) {
userAgent: opts.userAgent,
addressFormat: opts.addressFormat
});

default:
throw new Error('Provider ' + provider + ' not supported.');
throw new Error(`Provider not supported: ${provider}`);
}
}
Loading

0 comments on commit 2f2b9ff

Please sign in to comment.