Skip to content

Commit

Permalink
update node to v16
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangxn committed Jan 4, 2022
1 parent bba397f commit 63061e3
Show file tree
Hide file tree
Showing 24 changed files with 2,945 additions and 8,542 deletions.
6 changes: 3 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"env": {
"browser": true,
"node": true,
Expand All @@ -12,9 +12,9 @@
}
},
"rules": {
"no-unused-vars": ["error", { "vars": "all", "args": "after-used" }],
"no-unused-vars": ["error", {"vars": "all", "args": "after-used"}],
"comma-dangle": 0,
"indent": ["error", 4, {SwitchCase: 1}],
"indent": ["error", 4, {"SwitchCase": 1}],
"quotes": [2, "double", "avoid-escape"],
"semi": [2, "always"],
"camelcase": [0],
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ This script uses the [`bitsharesjs-ws`](https://github.com/bitshares/bitsharesjs
This script requires Node to run; install Node locally and run:

```
npm install
npm start myUsername [debug] [no_grouping] [op_type_filter]
yarn
yarn start myUsername [debug] [no_grouping] [op_type_filter]
```

Replace `myUsername` with the Bitshares user you wish to make a report for. Since Bitshares data is completely open, there are no login credentials needed to get a full transaction report on any user.
Expand Down
8 changes: 3 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ const {groupEntries, parseData} = require("./src/parser");

const {resolveBlockTimes, resolveAssets} = require("./src/api/nodeApi");

const {
getAccountHistoryES,
getAccountHistory
} = require("./src/api/getAccountHistory")(true);
const {getAccountHistoryES, getAccountHistory} =
require("./src/api/getAccountHistory")(true);

module.exports = {
groupEntries,
parseData,
getAccountHistoryES,
getAccountHistory,
resolveBlockTimes,
resolveAssets
resolveAssets,
};
16 changes: 8 additions & 8 deletions dist/src/api/getAccountHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const bts = require("bitsharesjs-ws");

let fetchClient;

module.exports = function(isBrowser) {
module.exports = function (isBrowser) {
if (isBrowser) fetchClient = fetch;
else {
fetchClient = require("node-fetch");
Expand All @@ -22,9 +22,9 @@ module.exports = function(isBrowser) {
fetchClient(
`${esNode}/get_account_history?account_id=${account_id}&from_=${start}&size=${limit}&sort_by=block_data.block_time&type=data&agg_field=operation_type`
)
.then(res => res.json())
.then(result => {
let ops = result.map(r => {
.then((res) => res.json())
.then((result) => {
let ops = result.map((r) => {
if ("amount_" in r.operation_history.op_object) {
r.operation_history.op_object.amount =
r.operation_history.op_object.amount_;
Expand All @@ -38,12 +38,12 @@ module.exports = function(isBrowser) {
r.operation_history.operation_result
),
block_num: r.block_data.block_num,
block_time: r.block_data.block_time + "Z"
block_time: r.block_data.block_time + "Z",
};
});
resolve(ops);
})
.catch(err => {
.catch((err) => {
console.log("getAccountHistory errror:", err);
resolve([]);
});
Expand All @@ -55,7 +55,7 @@ module.exports = function(isBrowser) {
bts.Apis.instance()
.history_api()
.exec("get_account_history", [account_id, stop, limit, start])
.then(operations => {
.then((operations) => {
resolve(operations);
})
.catch(reject);
Expand All @@ -64,6 +64,6 @@ module.exports = function(isBrowser) {

return {
getAccountHistory,
getAccountHistoryES
getAccountHistoryES,
};
};
40 changes: 18 additions & 22 deletions dist/src/api/nodeApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ let blockData = {};
let assetData = {};

function connect() {
return new Promise(resolve => {
return new Promise((resolve) => {
bts.Apis.instance(config.apiNode, true)
.init_promise.then(res => {
.init_promise.then((res) => {
ChainStore.init(false).then(() => {
resolve(res);
});
})
.catch(err => {
.catch((err) => {
console.error("Error connection to node:", err);
});
});
Expand All @@ -30,9 +30,9 @@ function disconnect() {
function getUser(name) {
return new Promise((resolve, reject) => {
FetchChain("getAccount", name, undefined, {
[name]: false
[name]: false,
})
.then(result => {
.then((result) => {
let account = result.toJS();
if (!account.balances) account.balances = {};
if (!account.call_orders) account.call_orders = [];
Expand All @@ -56,7 +56,7 @@ function getUser(name) {
resolve({
accountId: account.id,
assets,
balances: account.balances
balances: account.balances,
});
})
.catch(reject);
Expand All @@ -69,7 +69,7 @@ function getBlockTime(block) {
bts.Apis.instance()
.db_api()
.exec("get_block", [block])
.then(result => {
.then((result) => {
blockData[block] = new Date(result.timestamp + "Z");
resolve(blockData[block]);
})
Expand All @@ -81,35 +81,33 @@ function getAssetData(asset) {
return new Promise((resolve, reject) => {
if (assetData[asset]) return resolve(assetData[asset]);
FetchChain("getObject", asset, undefined, {
[asset]: false
[asset]: false,
})
.then(result => {
.then((result) => {
let a = result.toJS();
assetData[asset] = {
symbol: a.symbol.replace(
/OPEN\.|BRIDGE\.|RUDEX\.|GDEX\.|BLOCK\./,
""
),
precision: a.precision
precision: a.precision,
};
resolve(assetData[asset]);
})
.catch(err => {
.catch((err) => {
reject();
});
});
}

function resolveBlockTimes(operations) {
return new Promise((resolve, reject) => {
let promises = operations.map(op => {
let promises = operations.map((op) => {
if (op.block_time)
blockData[op.block_num] = new Date(op.block_time);
return getBlockTime(op.block_num);
});
Promise.all(promises)
.then(resolve)
.catch(reject);
Promise.all(promises).then(resolve).catch(reject);
});
}

Expand All @@ -119,7 +117,7 @@ function resolveAssets(operations, list) {
let assets = {};

if (operations) {
operations.forEach(record => {
operations.forEach((record) => {
const type = ops[record.op[0]];

switch (type) {
Expand Down Expand Up @@ -151,19 +149,17 @@ function resolveAssets(operations, list) {
}

if (list) {
list.forEach(entry => {
list.forEach((entry) => {
assets[entry] = true;
});
}

Object.keys(assets).forEach(asset_id => {
Object.keys(assets).forEach((asset_id) => {
if (!assetData[asset_id] && !!asset_id) {
promises.push(getAssetData(asset_id));
}
});
Promise.all(promises)
.then(resolve)
.catch(reject);
Promise.all(promises).then(resolve).catch(reject);
});
}

Expand All @@ -184,5 +180,5 @@ module.exports = {
resolveAssets,
resolveBlockTimes,
getAsset,
getBlock
getBlock,
};
14 changes: 7 additions & 7 deletions dist/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async function doWork() {
// accountBalances[amount.currency] = amount;
// })

result.map(function(record) {
result.map(function (record) {
const trx_id = record.id;
let timestamp = api.getBlock(record.block_num);
const type = ops[record.operation_type];
Expand All @@ -100,7 +100,7 @@ async function doWork() {
recordData[trx_id] = {
timestamp,
type,
data
data,
};
}
});
Expand All @@ -127,7 +127,7 @@ async function doWork() {
// });

if (CHECK) {
Object.keys(runningBalance).forEach(asset => {
Object.keys(runningBalance).forEach((asset) => {
if (!runningBalance[asset][0]) return;
runningBalance[asset].sort(
(a, b) => a[2].getTime() - b[2].getTime()
Expand All @@ -142,22 +142,22 @@ async function doWork() {
}
});
console.log("");
assetsToCheck.forEach(assetToCheck => {
assetsToCheck.forEach((assetToCheck) => {
console.log(
`**** Asset movement by type for ${assetToCheck}: ****\n`
);
getFinalBalance(assetToCheck);

function getTotal(array) {
let sum = 0;
array.forEach(i => {
array.forEach((i) => {
sum += i;
});
return sum;
}

if (movementTypes[assetToCheck]) {
Object.keys(movementTypes[assetToCheck]).forEach(type => {
Object.keys(movementTypes[assetToCheck]).forEach((type) => {
let deposit = getTotal(
movementTypes[assetToCheck][type].deposit
);
Expand All @@ -177,7 +177,7 @@ async function doWork() {
// Output the CSV

if (CHECK) {
assetsToCheck.forEach(assetToCheck => {
assetsToCheck.forEach((assetToCheck) => {
fs.open(
`output/${user}-${assetToCheck}-running-balances.csv`,
"w",
Expand Down
2 changes: 1 addition & 1 deletion dist/src/config.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = {
useES: true,
// use elastic search
esNode: "https://wrapper.elasticsearch.bitshares.ws",
botPaymentAccounts: []
botPaymentAccounts: [],
};
2 changes: 1 addition & 1 deletion dist/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = {
useES: true,
// use elastic search
esNode: "https://wrapper.elasticsearch.bitshares.ws",
botPaymentAccounts: []
botPaymentAccounts: [],
};
Loading

0 comments on commit 63061e3

Please sign in to comment.