Skip to content
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

Update deps #39

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

41 changes: 0 additions & 41 deletions .eslintrc.js

This file was deleted.

5 changes: 4 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ function initServices() {
const api = require('./modules/api');
const txParser = require('./modules/incomingTxsParser');

api.socket.initSocket({ socket: config.socket, wsType: config.ws_type, onNewMessage: txParser, admAddress: config.address });
if (config.socket) {
api.initSocket({ wsType: config.ws_type, admAddress: config.address });
api.socket.on(txParser);
}
}

// Debug and health API init
Expand Down
58 changes: 58 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const js = require('@eslint/js');
const google = require('eslint-config-google');
const globals = require('globals');
const babelParser = require('@babel/eslint-parser');

module.exports = [
js.configs.recommended,
google,
{
languageOptions: {
ecmaVersion: 2021,
sourceType: 'commonjs',
globals: {
...globals.node,
},
parser: babelParser,
parserOptions: {
sourceType: 'script',
ecmaVersion: 2021,
},
},
rules: {
quotes: [
'error',
'single',
{
allowTemplateLiterals: true,
},
],
'prefer-arrow-callback': ['error'],
'object-shorthand': ['error', 'always'],
'quote-props': ['error', 'as-needed'],
'object-curly-spacing': ['error', 'always'],
'max-len': ['error',
{ code: 133,
ignoreTrailingComments: true,
ignoreComments: true,
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true,
}],
'require-jsdoc': ['off'],
'valid-jsdoc': ['off'],
'no-array-constructor': ['off'],
'no-caller': ['off'],
'prefer-promise-reject-errors': ['off'],
'guard-for-in': ['off'],
'padded-blocks': ['off'],
'new-cap': ['off'],
camelcase: ['off'],
eqeqeq: ['error', 'always'],
},
},
{
ignores: ['trade/settings/', 'trade/tests/', 'trade/cs/test/', 'trade/cs/web_legacy/', '*.spec.js'],
},
];
47 changes: 25 additions & 22 deletions helpers/cryptos/adm_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const log = require('../../helpers/log');
const constants = require('../const');
const config = require('../../modules/config/reader');
const utils = require('../utils');
const { MessageType } = require('adamant-api');

const baseCoin = require('./baseCoin');

Expand Down Expand Up @@ -35,10 +36,10 @@ module.exports = class admCoin extends baseCoin {
if (cached) {
return cached;
}
const blocks = await api.get('blocks', { limit: 1 });
const blocks = await api.getBlocks({ limit: 1 });
if (blocks.success) {
this.cache.cacheData('lastBlock', blocks.data.blocks[0]);
return blocks.data.blocks[0];
this.cache.cacheData('lastBlock', blocks.blocks[0]);
return blocks.blocks[0];
} else {
log.warn(`Failed to get last block in getLastBlock() of ${utils.getModuleName(module.id)} module. ${blocks.errorMessage}.`);
}
Expand All @@ -62,10 +63,10 @@ module.exports = class admCoin extends baseCoin {
if (cached) {
return utils.satsToADM(cached);
}
const account = await api.get('accounts', { address: config.address });
const account = await api.getAccountBalance(config.address);
if (account.success) {
this.cache.cacheData('balance', account.data.account.balance);
return utils.satsToADM(account.data.account.balance);
this.cache.cacheData('balance', account.balance);
return utils.satsToADM(account.balance);
} else {
log.warn(`Failed to get account info in getBalance() of ${utils.getModuleName(module.id)} module; returning outdated cached balance. ${account.errorMessage}.`);
return utils.satsToADM(cached);
Expand Down Expand Up @@ -100,20 +101,20 @@ module.exports = class admCoin extends baseCoin {
* Not used, additional info: hash (already known), blockId, fee
*/
async getTransaction(txid) {
const tx = await api.get('transactions/get', { id: txid });
const tx = await api.getTransaction(txid);
if (tx.success) {
log.log(`Tx status: ${this.formTxMessage(tx.data.transaction)}.`);
log.log(`Tx status: ${this.formTxMessage(tx.transaction)}.`);
return {
status: tx.data.transaction.confirmations > 0 ? true : undefined,
height: tx.data.transaction.height,
blockId: tx.data.transaction.blockId,
timestamp: utils.toTimestamp(tx.data.transaction.timestamp),
hash: tx.data.transaction.id,
senderId: tx.data.transaction.senderId,
recipientId: tx.data.transaction.recipientId,
confirmations: tx.data.transaction.confirmations,
amount: utils.satsToADM(tx.data.transaction.amount), // in ADM
fee: utils.satsToADM(tx.data.transaction.fee), // in ADM
status: tx.transaction.confirmations > 0 ? true : undefined,
height: tx.transaction.height,
blockId: tx.transaction.blockId,
timestamp: utils.toTimestamp(tx.transaction.timestamp),
hash: tx.transaction.id,
senderId: tx.transaction.senderId,
recipientId: tx.transaction.recipientId,
confirmations: tx.transaction.confirmations,
amount: utils.satsToADM(tx.transaction.amount), // in ADM
fee: utils.satsToADM(tx.transaction.fee), // in ADM
};
} else {
log.warn(`Unable to get Tx ${txid} in getTransaction() of ${utils.getModuleName(module.id)} module. It's expected, if the Tx is new. ${tx.errorMessage}.`);
Expand All @@ -122,15 +123,17 @@ module.exports = class admCoin extends baseCoin {
}

async send(params) {
const isAmountInADM = true; // Sending ADM

params.try = params.try || 1;
const tryString = ` (try number ${params.try})`;
const { address, value, comment } = params;
const payment = await api.sendMessage(config.passPhrase, address, comment, 'basic', value);
const payment = await api.sendMessage(config.passPhrase, address, comment, MessageType.Chat, value, isAmountInADM);
if (payment.success) {
log.log(`Successfully sent ${value} ADM to ${address} with comment '${comment}'${tryString}, Tx hash: ${payment.data.transactionId}.`);
log.log(`Successfully sent ${value} ADM to ${address} with comment '${comment}'${tryString}, Tx hash: ${payment.transactionId}.`);
return {
success: payment.data.success,
hash: payment.data.transactionId,
success: payment.success,
hash: payment.transactionId,
};
} else {
log.warn(`Failed to send ${value} ADM to ${address} with comment '${comment}'${tryString} in send() of ${utils.getModuleName(module.id)} module. ${payment.errorMessage}.`);
Expand Down
3 changes: 2 additions & 1 deletion modules/api.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const config = require('./config/reader');
const log = require('../helpers/log');
const { AdamantApi } = require('adamant-api');

if (config.passPhrase) {
module.exports = require('adamant-api')({ node: config.node_ADM, logLevel: config.log_level }, log);
module.exports = new AdamantApi({ nodes: config.node_ADM, logLevel: config.log_level, logger: log });
} else {
module.exports = {
sendMessage: () => {
Expand Down
15 changes: 9 additions & 6 deletions modules/checkerTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const log = require('../helpers/log');
const config = require('./config/reader');
const constants = require('../helpers/const');
const utils = require('../helpers/utils');
const { TransactionType } = require('adamant-api');

async function check() {

Expand All @@ -17,16 +18,18 @@ async function check() {
}

const queryParams = {
'and:recipientId': config.address, // get only Txs for the bot
'and:types': '0,8', // get direct transfers and messages
'and:fromHeight': lastProcessedBlockHeight + 1, // from current height if the first run, or from the last processed block
returnAsset: '1', // get messages' contents
and: {
recipientId: config.address,
types: [TransactionType.SEND, TransactionType.CHAT_MESSAGE],
fromHeight: lastProcessedBlockHeight + 1,
},
returnAsset: 1, // get messages' contents
orderBy: 'timestamp:desc', // latest Txs
};

const txTrx = await api.get('transactions', queryParams);
const txTrx = await api.getTransactions(queryParams);
if (txTrx.success) {
for (const tx of txTrx.data.transactions) {
for (const tx of txTrx.transactions) {
await txParser(tx);
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions modules/config/reader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const jsonminify = require('jsonminify');
const fs = require('fs');
const path = require('path');
const keys = require('adamant-api/src/helpers/keys');
const { createKeypairFromPassphrase, createAddressFromPublicKey } = require('adamant-api');

const { version, name } = require('../../package.json');

Expand Down Expand Up @@ -104,12 +104,12 @@ try {

if (config.passPhrase) {
try {
keyPair = keys.createKeypairFromPassPhrase(config.passPhrase);
keyPair = createKeypairFromPassphrase(config.passPhrase);
} catch (e) {
exit(`Bot's config is wrong. Invalid passPhrase. Error: ${e}. Cannot start the Bot.`);
}

address = keys.createAddressFromPublicKey(keyPair.publicKey);
address = createAddressFromPublicKey(keyPair.publicKey);
config.keyPair = keyPair;
config.publicKey = keyPair.publicKey.toString('hex');
config.address = address;
Expand Down
3 changes: 2 additions & 1 deletion modules/incomingTxsParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const log = require('../helpers/log');
const notify = require('../helpers/notify');
const utils = require('../helpers/utils');
const api = require('./api');
const { decodeMessage } = require('adamant-api');
const config = require('./config/reader');
const constants = require('../helpers/const');
const transferTxs = require('./transferTxs');
Expand Down Expand Up @@ -35,7 +36,7 @@ module.exports = async (tx) => {
let decryptedMessage = '';
const chat = tx.asset ? tx.asset.chat : '';
if (chat) {
decryptedMessage = api.decodeMsg(chat.message, tx.senderPublicKey, config.passPhrase, chat.own_message).trim();
decryptedMessage = decodeMessage(chat.message, tx.senderPublicKey, config.passPhrase, chat.own_message).trim();
}

let commandFix = '';
Expand Down
Loading