Skip to content

Commit b5b97ca

Browse files
authored
Merge pull request #276 from HathorNetwork/dev
Release v1.17.0-alpha
2 parents c3e558c + 8aafe4c commit b5b97ca

22 files changed

+249
-142
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
module.exports = {
4+
up: async (queryInterface, Sequelize) => {
5+
await queryInterface.addIndex(
6+
'address_tx_history',
7+
['timestamp'],
8+
{
9+
name: 'address_tx_history_timestamp_idx',
10+
fields: 'timestamp',
11+
},
12+
);
13+
14+
await queryInterface.addIndex(
15+
'address_balance',
16+
['updated_at'],
17+
{
18+
name: 'address_balance_updated_at_idx',
19+
fields: 'updated_at',
20+
},
21+
);
22+
23+
await queryInterface.addColumn('address_balance', 'total_received', {
24+
type: Sequelize.BIGINT.UNSIGNED,
25+
allowNull: false,
26+
defaultValue: 0,
27+
});
28+
},
29+
30+
down: async (queryInterface, Sequelize) => {
31+
await queryInterface.removeIndex('address_tx_history', 'address_tx_history_timestamp_idx');
32+
await queryInterface.removeIndex('address_balance', 'address_balance_updated_at_idx');
33+
await queryInterface.removeColumn('address_balance', 'total_received');
34+
},
35+
};

db/models/addressbalance.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ module.exports = (sequelize, DataTypes) => {
3434
allowNull: false,
3535
primaryKey: true,
3636
},
37+
total_received: {
38+
type: DataTypes.BIGINT.UNSIGNED,
39+
allowNull: false,
40+
},
3741
unlocked_balance: {
3842
type: DataTypes.BIGINT.UNSIGNED,
3943
allowNull: false,
@@ -60,12 +64,12 @@ module.exports = (sequelize, DataTypes) => {
6064
type: DataTypes.INTEGER.UNSIGNED,
6165
allowNull: false,
6266
},
63-
createdAt: {
67+
created_at: {
6468
type: 'TIMESTAMP',
6569
allowNull: false,
6670
defaultValue: DataTypes.literal('CURRENT_TIMESTAMP'),
6771
},
68-
updatedAt: {
72+
updated_at: {
6973
type: 'TIMESTAMP',
7074
allowNull: false,
7175
defaultValue: DataTypes.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
@@ -75,6 +79,10 @@ module.exports = (sequelize, DataTypes) => {
7579
modelName: 'AddressBalance',
7680
tableName: 'address_balance',
7781
timestamps: false,
82+
indexes: [{
83+
name: 'address_balance_updated_at_idx',
84+
fields: ['updated_at'],
85+
}],
7886
});
7987
return AddressBalance;
8088
};

db/models/addresstxhistory.js

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ module.exports = (sequelize, DataTypes) => {
5353
}, {
5454
name: 'address_tx_history_tokenid_idx',
5555
fields: ['token_id'],
56+
}, {
57+
name: 'address_tx_history_timestamp_idx',
58+
fields: ['timestamp'],
5659
}],
5760
});
5861
return AddressTxHistory;

db/models/token.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ module.exports = (sequelize, DataTypes) => {
3030
type: DataTypes.STRING(5),
3131
allowNull: false,
3232
},
33-
createdAt: {
33+
created_at: {
3434
type: 'TIMESTAMP',
3535
allowNull: false,
3636
defaultValue: DataTypes.literal('CURRENT_TIMESTAMP'),
3737
},
38-
updatedAt: {
38+
updated_at: {
3939
type: 'TIMESTAMP',
4040
allowNull: false,
4141
defaultValue: DataTypes.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),

db/models/transaction.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ module.exports = (sequelize, DataTypes) => {
4848
allowNull: true,
4949
defaultValue: null,
5050
},
51-
createdAt: {
51+
created_at: {
5252
type: 'TIMESTAMP',
5353
allowNull: false,
5454
defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
5555
},
56-
updatedAt: {
56+
updated_at: {
5757
type: 'TIMESTAMP',
5858
allowNull: false,
5959
defaultValue: sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hathor-wallet-service",
3-
"version": "1.16.0-alpha",
3+
"version": "1.17.0-alpha",
44
"description": "",
55
"scripts": {
66
"postinstall": "npm dedupe",

src/api/auth.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {
2828
} from '@src/utils';
2929
import middy from '@middy/core';
3030
import cors from '@middy/http-cors';
31+
import createDefaultLogger from '@src/logger';
32+
import { Logger } from 'winston';
3133

3234
const EXPIRATION_TIME_IN_SECONDS = 1800;
3335

@@ -155,7 +157,7 @@ export const tokenHandler: APIGatewayProxyHandler = middy(async (event) => {
155157
/**
156158
* Generates a aws policy document to allow/deny access to the resource
157159
*/
158-
const _generatePolicy = (principalId: string, effect: string, resource: string) => {
160+
const _generatePolicy = (principalId: string, effect: string, resource: string, logger: Logger) => {
159161
const resourcePrefix = `${resource.split('/').slice(0, 2).join('/')}/*`;
160162
const policyDocument: PolicyDocument = {
161163
Version: '2012-10-17',
@@ -182,12 +184,12 @@ const _generatePolicy = (principalId: string, effect: string, resource: string)
182184
authResponse.context = context;
183185

184186
// XXX: to get the resulting policy on the logs, since we can't check the cached policy
185-
// eslint-disable-next-line
186-
console.info('Generated policy:', authResponse);
187+
logger.info('Generated policy:', authResponse);
187188
return authResponse;
188189
};
189190

190191
export const bearerAuthorizer: APIGatewayTokenAuthorizerHandler = middy(async (event) => {
192+
const logger = createDefaultLogger();
191193
const { authorizationToken } = event;
192194
if (!authorizationToken) {
193195
throw new Error('Unauthorized'); // returns a 401
@@ -210,8 +212,7 @@ export const bearerAuthorizer: APIGatewayTokenAuthorizerHandler = middy(async (e
210212
} else if (e.name === 'TokenExpiredError') {
211213
throw new Error('Unauthorized');
212214
} else {
213-
// eslint-disable-next-line
214-
console.log('Error on bearerAuthorizer: ', e);
215+
logger.warn('Error on bearerAuthorizer: ', e);
215216
throw e;
216217
}
217218
}
@@ -227,8 +228,8 @@ export const bearerAuthorizer: APIGatewayTokenAuthorizerHandler = middy(async (e
227228
const verified = verifySignature(signature, timestamp, address, walletId);
228229

229230
if (verified && Math.floor(Date.now() / 1000) <= expirationTs) {
230-
return _generatePolicy(walletId, 'Allow', event.methodArn);
231+
return _generatePolicy(walletId, 'Allow', event.methodArn, logger);
231232
}
232233

233-
return _generatePolicy(walletId, 'Deny', event.methodArn);
234+
return _generatePolicy(walletId, 'Deny', event.methodArn, logger);
234235
}).use(cors());

src/api/wallet.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { walletIdProxyHandler } from '@src/commons';
3737
import middy from '@middy/core';
3838
import cors from '@middy/http-cors';
3939
import Joi from 'joi';
40+
import createDefaultLogger from '@src/logger';
4041

4142
const mysql = getDbConnection();
4243

@@ -250,6 +251,7 @@ export const changeAuthXpub: APIGatewayProxyHandler = middy(async (event) => {
250251
* This lambda is called by API Gateway on POST /wallet
251252
*/
252253
export const load: APIGatewayProxyHandler = middy(async (event) => {
254+
const logger = createDefaultLogger();
253255
const eventBody = (function parseBody(body) {
254256
try {
255257
return JSON.parse(body);
@@ -349,8 +351,7 @@ export const load: APIGatewayProxyHandler = middy(async (event) => {
349351
*/
350352
await invokeLoadWalletAsync(xpubkeyStr, maxGap);
351353
} catch (e) {
352-
// eslint-disable-next-line
353-
console.error('Error on lambda wallet invoke', e);
354+
logger.error('Error on lambda wallet invoke', e);
354355

355356
const newRetryCount = wallet.retryCount ? wallet.retryCount + 1 : 1;
356357
// update wallet status to 'error'
@@ -388,6 +389,7 @@ interface LoadResult {
388389
* This lambda is called async by another lambda, the one reponsible for the load wallet API
389390
*/
390391
export const loadWallet: Handler<LoadEvent, LoadResult> = async (event) => {
392+
const logger = createDefaultLogger();
391393
// Can't use a middleware on this event, so we should just check the source (added by the warmup plugin) as
392394
// our default middleware does
393395
if (event.source === 'serverless-plugin-warmup') {
@@ -428,8 +430,7 @@ export const loadWallet: Handler<LoadEvent, LoadResult> = async (event) => {
428430
xpubkey,
429431
};
430432
} catch (e) {
431-
// eslint-disable-next-line
432-
console.error('Erroed on loadWalletAsync: ', e);
433+
logger.error('Erroed on loadWalletAsync: ', e);
433434

434435
const wallet = await getWallet(mysql, walletId);
435436
const newRetryCount = wallet.retryCount ? wallet.retryCount + 1 : 1;

src/commons.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export const getWalletBalances = async (
267267
/**
268268
* Updates the wallet-lib constants if needed.
269269
*
270-
* @returns A promise that resolves when the wallet-lib constants have been set.
270+
* @returns {Promise<void>} A promise that resolves when the wallet-lib constants have been set.
271271
*/
272272
export const maybeRefreshWalletConstants = async (mysql: ServerlessMysql): Promise<void> => {
273273
const lastVersionData: FullNodeVersionData = await getVersionData(mysql);
@@ -573,13 +573,13 @@ export const walletIdProxyHandler = (handler: WalletProxyHandler): APIGatewayPro
573573
}
574574
);
575575

576-
export const prepareOutputs = (outputs: TxOutput[], txId: string): TxOutputWithIndex[] => {
576+
export const prepareOutputs = (outputs: TxOutput[], txId: string, logger: Logger): TxOutputWithIndex[] => {
577577
const preparedOutputs: [number, TxOutputWithIndex[]] = outputs.reduce(
578578
([currIndex, newOutputs]: [number, TxOutputWithIndex[]], output: TxOutput): [number, TxOutputWithIndex[]] => {
579579
if (!output.decoded
580580
|| output.decoded.type === null
581581
|| output.decoded.type === undefined) {
582-
console.warn(`Ignoring tx output with index ${currIndex} from tx ${txId} as script couldn't be decoded.`);
582+
logger.warn(`Ignoring tx output with index ${currIndex} from tx ${txId} as script couldn't be decoded.`);
583583
return [currIndex + 1, newOutputs];
584584
}
585585

0 commit comments

Comments
 (0)