Skip to content

feat: allow setting tx mining service apikey #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions __tests__/config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { config as hathorLibConfig } from '@hathor/wallet-lib';

import { initHathorLib } from '../src/index';

describe('wallet lib config', () => {
it('correctly sets the tx-mining-service api-key', () => {
const currentApiKey = hathorLibConfig.getTxMiningApiKey();
expect(currentApiKey).toBeUndefined();

global.config.txMiningApiKey = '123123';

initHathorLib();

const newApiKey = hathorLibConfig.getTxMiningApiKey();
expect(newApiKey).toEqual('123123');
});
});
2 changes: 1 addition & 1 deletion __tests__/multisig-pubkey.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TestUtils from './test-utils';

describe.only('multisig-pubkey api', () => {
describe('multisig-pubkey api', () => {
beforeAll(() => TestUtils.stopWallet());

it('should not return the xpubkey without seedKey', async () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/start.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TestUtils from './test-utils';

describe.only('start api', () => {
describe('start api', () => {
beforeAll(() => TestUtils.stopWallet());

it('should not start a wallet with an invalid seedKey', async () => {
Expand Down
3 changes: 2 additions & 1 deletion config.js.docker
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const config = {
network: getParam('network', 'mainnet'),
server: getParam('server', 'https://node1.mainnet.hathor.network/v1a/'),

txMiningUrl: getParam('tx_mining_url', 'https://txmining.mainnet.hathor.network'),
txMiningUrl: getParam('tx_mining_url', null),
txMiningApiKey: getParam('tx_mining_api_key', null),

http_api_key: getParam('api_key'),
httpLogFormat: getParam('http_log_format'),
Expand Down
4 changes: 4 additions & 0 deletions config.js.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ module.exports = {
// Use it only if you want to use your own tx mining service, e.g. 'https://mytxmining.domain/'
txMiningUrl: null,

// ApiKey to use with Tx Mining Service
// This is optional. You should set it only if you have an api-key.
txMiningApiKey: null,

// Wallet seeds
seeds: {
default: '',
Expand Down
81 changes: 64 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@babel/node": "^7.13.0",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/preset-env": "^7.13.5",
"@hathor/wallet-lib": "^0.33.1",
"@hathor/wallet-lib": "^0.34.0",
"express": "^4.17.1",
"express-validator": "^6.10.0",
"morgan": "^1.10.0",
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/index.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function start(req, res) {
if (!allowPassphrase) {
// To use a passphrase on /start POST request the configuration of the headless must
// explicitly allow it
console.log('Failed to start wallet because using a passphrase is not allowed by '
console.error('Failed to start wallet because using a passphrase is not allowed by '
+ 'the current config. See allowPassphrase.');
res.send({
success: false,
Expand All @@ -160,7 +160,7 @@ function start(req, res) {
// We already have a wallet for this key
// so we log that it won't start a new one because
// it must first stop the old wallet and then start the new
console.log('Error starting wallet because this wallet-id is already in use. You must stop the wallet first.');
console.error('Error starting wallet because this wallet-id is already in use. You must stop the wallet first.');
res.send({
success: false,
message: `Failed to start wallet with wallet id ${walletID}`,
Expand All @@ -176,7 +176,7 @@ function start(req, res) {
success: true,
});
}, error => {
console.log('Error:', error);
console.error('Error:', error);
res.send({
success: false,
message: `Failed to start wallet with wallet id ${req.body['wallet-id']}`,
Expand Down
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ import version from './version';
import mainRouter from './routes/index.routes';

// Initializing Hathor Lib
(() => {
export const initHathorLib = () => {
if (config.txMiningUrl) {
hathorLibConfig.setTxMiningUrl(config.txMiningUrl);
}
})();

if (config.txMiningApiKey) {
hathorLibConfig.setTxMiningApiKey(config.txMiningApiKey);
}
};

initHathorLib();

// Initializing ExpressJS
const app = express();
Expand Down