Skip to content

Commit 2fe31b4

Browse files
Merge pull request #61 from ostdotcom/develop
Merging develop to release
2 parents 6b3b226 + 969b2bb commit 2fe31b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1611
-866
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
## ost-block-scanner v1.0.1
2+
- Upgraded node version to 10.x
3+
- Version bump for dependencies.
4+
15
## ost-block-scanner v1.0.0
26
- OST Block Scanner 1.0.0 is the first release of ost-block-scanner. It scans chain and stores blocks, transactions and transfers data in AWS DynamoDB.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.0
1+
1.0.1

config.json.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
]
9999
}
100100
],
101+
"nonDDBDataSource": {
102+
"transactionDetails": "chain"
103+
},
101104
"extraStorageColumns": {
102105
"chains": {
103106
"chainName": {

config/coreConstants.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ class CoreConstants {
5151
get icNameSpace() {
5252
return 'ost-block-scanner';
5353
}
54+
55+
/**
56+
* Return zero address.
57+
*
58+
* @return {String}
59+
*/
60+
get zeroAddress() {
61+
return '0x0000000000000000000000000000000000000000';
62+
}
5463
}
5564

5665
module.exports = new CoreConstants();

helpers/basic.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,23 @@ class BasicHelperKlass {
419419
throw 'Transaction Status is not supported (' + status + ')';
420420
}
421421
}
422+
423+
/**
424+
* Checks whether the object is empty or not.
425+
*
426+
* @param {object} obj
427+
*
428+
* @return {boolean}
429+
*/
430+
isEmptyObject(obj) {
431+
for (const property in obj) {
432+
if (Object.prototype.hasOwnProperty.call(obj, property)) {
433+
return false;
434+
}
435+
}
436+
437+
return true;
438+
}
422439
}
423440

424441
module.exports = new BasicHelperKlass();

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require(rootPrefix + '/lib/models/shared/ShardByTransaction');
2323
require(rootPrefix + '/lib/models/sharded/byEconomyAddress/EconomyAddressTransfer');
2424
require(rootPrefix + '/lib/models/shared/ChainCronData');
2525
require(rootPrefix + '/lib/models/sharded/byChainId/PendingTransaction');
26+
require(rootPrefix + '/lib/models/shared/LatestPricePoint');
2627

2728
// Model services
2829
require(rootPrefix + '/services/AddChain');
@@ -71,6 +72,7 @@ require(rootPrefix + '/lib/cacheMultiManagement/shared/shardIdentifier/ByEconomy
7172
require(rootPrefix + '/lib/cacheManagement/chainSpecific/EconomyAddressTransfer');
7273
require(rootPrefix + '/lib/cacheMultiManagement/chainSpecific/PendingTransactionByHash');
7374
require(rootPrefix + '/lib/cacheMultiManagement/chainSpecific/PendingTransactionByUuid');
75+
require(rootPrefix + '/lib/cacheManagement/shared/LatestPricePoints');
7476

7577
require(rootPrefix + '/services/economy/Create');
7678
require(rootPrefix + '/services/economy/Aggregator');
@@ -116,6 +118,7 @@ class OSTBlockScanner {
116118
coreConstants.icNameSpace,
117119
'PendingTransactionModel'
118120
);
121+
model.LatestPricePoint = instanceComposer.getShadowedClassFor(coreConstants.icNameSpace, 'LatestPricePointModel');
119122

120123
const service = (oThis.service = {});
121124
// Add services here
@@ -201,6 +204,8 @@ class OSTBlockScanner {
201204
coreConstants.icNameSpace,
202205
'PendingTransactionByUuidCache'
203206
);
207+
208+
cache.LatestPricePoint = instanceComposer.getShadowedClassFor(coreConstants.icNameSpace, 'LatestPricePointsCache');
204209
}
205210
}
206211

lib/block/CheckIfProcessable.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class CheckIfProcessable {
4848
async perform() {
4949
const oThis = this;
5050

51+
logger.log('======Before calling getHighestBlockFromChain');
52+
5153
// get the highest block from the chain nodes
5254
await oThis.getHighestBlockFromChain();
5355

@@ -76,6 +78,7 @@ class CheckIfProcessable {
7678
result['nodesWithBlock'] = oThis.nodesWithBlock;
7779
}
7880

81+
logger.log('======returning from check if processable====');
7982
return responseHelper.successWithData(result);
8083
}
8184

@@ -95,6 +98,8 @@ class CheckIfProcessable {
9598
let provider = providers[i];
9699
await oThis.refreshHighestBlock(provider);
97100
}
101+
102+
logger.log('====Highest block fetched===');
98103
}
99104

100105
/**

lib/block/DistributeTransactions.js

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
* Class file for handling transaction parser and token transfer parser calls for a block
55
*/
66

7+
const OSTBase = require('@ostdotcom/base');
8+
79
const rootPrefix = '../..',
8-
OSTBase = require('@ostdotcom/base'),
9-
logger = require(rootPrefix + '/lib/logger/customConsoleLogger'),
10-
coreConstants = require(rootPrefix + '/config/coreConstants'),
11-
responseHelper = require(rootPrefix + '/lib/formatter/response'),
1210
basicHelper = require(rootPrefix + '/helpers/basic'),
13-
errorConfig = basicHelper.getErrorConfig();
11+
coreConstants = require(rootPrefix + '/config/coreConstants'),
12+
logger = require(rootPrefix + '/lib/logger/customConsoleLogger'),
13+
responseHelper = require(rootPrefix + '/lib/formatter/response');
1414

15-
const InstanceComposer = OSTBase.InstanceComposer;
15+
const errorConfig = basicHelper.getErrorConfig(),
16+
InstanceComposer = OSTBase.InstanceComposer;
1617

1718
require(rootPrefix + '/services/transaction/Parser');
1819
require(rootPrefix + '/services/transfer/Parser');
@@ -31,6 +32,8 @@ class DistributeTransactions {
3132
oThis.chainId = params.chainId;
3233
oThis.rawCurrentBlock = params.rawCurrentBlock;
3334
oThis.nodesWithBlock = params.nodesWithBlock;
35+
36+
oThis.transactionReceiptMap = {};
3437
}
3538

3639
/**
@@ -105,55 +108,58 @@ class DistributeTransactions {
105108

106109
promiseArray.push(
107110
new Promise(function(onResolve, onReject) {
108-
transactionParser
109-
.perform()
110-
.then(function(txParserResponse) {
111-
// If transaction parser was successful then only token transfer parser would work.
112-
if (txParserResponse.isSuccess()) {
113-
let transactionReceiptMap = txParserResponse.data.transactionReceiptMap || {},
114-
unprocessedItems = txParserResponse.data.unprocessedTransactions || [],
115-
processedReceipts = {};
116-
117-
let unprocessedItemsMap = {},
118-
tokenParserNeeded = false;
119-
120-
for (let i = 0; i < unprocessedItems.length; i++) {
121-
unprocessedItemsMap[unprocessedItems[i]] = 1;
122-
}
123-
124-
for (let txHash in transactionReceiptMap) {
125-
if (!unprocessedItemsMap[txHash] && transactionReceiptMap[txHash]) {
126-
processedReceipts[txHash] = transactionReceiptMap[txHash];
127-
tokenParserNeeded = true;
128-
}
129-
}
130-
131-
if (tokenParserNeeded) {
132-
new oThis.TokenTransferParser(
133-
oThis.chainId,
134-
oThis.rawCurrentBlock,
135-
processedReceipts,
136-
oThis.nodesWithBlock
137-
)
138-
.perform()
139-
.then(function(ttpResp) {
140-
onResolve();
141-
})
142-
.catch(function(ttpErr) {
143-
onResolve();
144-
});
145-
} else {
146-
onResolve();
147-
}
148-
} else {
149-
logger.error('Transaction Parser returns error: ', txParserResponse.toHash());
150-
onResolve();
111+
transactionParser.perform().then(function(txParserResponse) {
112+
// If transaction parser was successful then only token transfer parser would work.
113+
if (txParserResponse.isSuccess()) {
114+
let transactionReceiptMap = txParserResponse.data.transactionReceiptMap || {},
115+
unprocessedItems = txParserResponse.data.unprocessedTransactions || [];
116+
117+
if (unprocessedItems.length > 0) {
118+
logger.error('Transaction parser returned unprocessed items: ', unprocessedItems);
119+
return onReject(
120+
responseHelper.error({
121+
internal_error_identifier: 'l_b_dt_2',
122+
api_error_identifier: 'something_went_wrong',
123+
debug_options: 'Transaction parser returned unprocessed items.'
124+
})
125+
);
151126
}
152-
})
153-
.catch(function(err) {
154-
logger.error(' Transaction Parser failed ');
155-
onResolve();
156-
});
127+
// Merge all receipts in global map
128+
Object.assign(oThis.transactionReceiptMap, transactionReceiptMap);
129+
130+
// Start with transfer parser as Transaction parser completed its work.
131+
new oThis.TokenTransferParser(
132+
oThis.chainId,
133+
oThis.rawCurrentBlock,
134+
transactionReceiptMap,
135+
oThis.nodesWithBlock
136+
)
137+
.perform()
138+
.then(function(ttpResp) {
139+
if (ttpResp.isSuccess()) {
140+
const injectionFailedTransactionHashes = ttpResp.data.injectionFailedTransactionHashes || [];
141+
142+
if (injectionFailedTransactionHashes.length > 0) {
143+
logger.error(
144+
'Token transfer parser returned injectionFailedTransactionHashes: ',
145+
injectionFailedTransactionHashes
146+
);
147+
return onReject(ttpResp);
148+
}
149+
onResolve(ttpResp);
150+
} else {
151+
logger.error('Token Transfer Parser returns error: ', ttpResp.toHash());
152+
onReject(ttpResp);
153+
}
154+
})
155+
.catch(function(ttpErr) {
156+
onReject(ttpErr);
157+
});
158+
} else {
159+
logger.error('Transaction Parser returns error: ', txParserResponse.toHash());
160+
onReject(txParserResponse);
161+
}
162+
});
157163
})
158164
);
159165

@@ -169,7 +175,7 @@ class DistributeTransactions {
169175
await Promise.all(promiseArray);
170176
}
171177

172-
return responseHelper.successWithData({});
178+
return responseHelper.successWithData({ transactionReceiptMap: oThis.transactionReceiptMap });
173179
}
174180
}
175181

0 commit comments

Comments
 (0)