From c86ec65971459c2ac0723c0d0d9f0a567603a04c Mon Sep 17 00:00:00 2001 From: jsalyers <jsalyers@syncad.com> Date: Thu, 22 Oct 2020 16:33:10 -0400 Subject: [PATCH] [JES] Updates to hive-js for an updated get_account_history API call --- package.json | 1 + src/api/methods.js | 5 +++++ src/api/transports/http.js | 14 +++++++++++++- src/auth/serializer/index.js | 4 ++++ src/auth/serializer/src/ChainTypes.js | 6 +++--- src/auth/serializer/src/makeBitMaskFilter.js | 9 +++++++++ yarn.lock | 5 +++++ 7 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/auth/serializer/src/makeBitMaskFilter.js diff --git a/package.json b/package.json index be14cf0..f38dd2b 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "debug": "^2.6.8", "detect-node": "^2.0.3", "ecurve": "^1.0.5", + "jsbi": "^3.1.4", "lodash": "^4.16.4", "retry": "^0.12.0", "secure-random": "^1.1.2", diff --git a/src/api/methods.js b/src/api/methods.js index 377a719..8997b4c 100644 --- a/src/api/methods.js +++ b/src/api/methods.js @@ -214,6 +214,11 @@ export default [ "method": "get_account_history", "params": ["account", "from", "limit"] }, + { + "api": "database_api", + "method": "get_account_history", + "params": ["account", "from", "limit", "operation_filter_low", "operation_filter_high"], + }, { "api": "database_api", "method": "get_owner_history", diff --git a/src/api/transports/http.js b/src/api/transports/http.js index 9ce59e7..7a23b2d 100644 --- a/src/api/transports/http.js +++ b/src/api/transports/http.js @@ -58,7 +58,19 @@ export default class HttpTransport extends Transport { } debug('Steem::send', api, data); const id = data.id || this.id++; - const params = [api, data.method, data.params]; + let params = [api, data.method, data.params]; + //SPECIAL CODE - can be removed after all API node operators upgrade to get the updated get_account_history api call + if (this.options.uri !== 'https://api.hive.blog' && data.method === 'get_account_history' && data.params.length >= 4) + { + //We are experimenting with a new version of get_account_history that can now take up to 5 params + //but this is only deployed on api.hive.blog nodes, so if this particular request is going to a different + //backend, just strip the extra parameters off the call to avoid breaking it. Once all API nodes have upgraded + //this code can be removed. + while (data.params.length > 3) + data.params.pop(); + params = [api, data.method, data.params]; + } + //END SPECIAL CODE const retriable = this.retriable(api, data); const fetchMethod = this.options.fetchMethod; if (retriable) { diff --git a/src/auth/serializer/index.js b/src/auth/serializer/index.js index 72bf102..b7dd671 100644 --- a/src/auth/serializer/index.js +++ b/src/auth/serializer/index.js @@ -16,4 +16,8 @@ module.exports = { template: require('./src/template'), number_utils: require('./src/number_utils'), + + ChainTypes: require ('./src/ChainTypes'), + + makeBitMaskFilter: require('./src/makeBitMaskFilter'), } diff --git a/src/auth/serializer/src/ChainTypes.js b/src/auth/serializer/src/ChainTypes.js index 4bb7706..d82fba8 100644 --- a/src/auth/serializer/src/ChainTypes.js +++ b/src/auth/serializer/src/ChainTypes.js @@ -1,6 +1,4 @@ -var ChainTypes; - -module.exports = ChainTypes = {}; +var ChainTypes = {}; ChainTypes.reserved_spaces = { relative_protocol_ids: 0, @@ -86,3 +84,5 @@ ChainTypes.object_type = { "null": 0, base: 1, }; + +module.exports = ChainTypes; diff --git a/src/auth/serializer/src/makeBitMaskFilter.js b/src/auth/serializer/src/makeBitMaskFilter.js new file mode 100644 index 0000000..33aac65 --- /dev/null +++ b/src/auth/serializer/src/makeBitMaskFilter.js @@ -0,0 +1,9 @@ +import JSBI from 'jsbi'; + +let makeBitMaskFilter = (allowedOperations) => { + return allowedOperations.reduce(([low, high], allowedOperation) => allowedOperation < 64 ? [JSBI.bitwiseOr(low, JSBI.leftShift(JSBI.BigInt(1), JSBI.BigInt(allowedOperation))), high] + : [low, JSBI.bitwiseOr(high, JSBI.leftShift(JSBI.BigInt(1), JSBI.BigInt(allowedOperation-64)))], + [JSBI.BigInt(0), JSBI.BigInt(0)]).map(value => JSBI.notEqual(value, JSBI.BigInt(0)) ? value.toString() : null); +}; + +module.exports = makeBitMaskFilter; \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 7e5e097..92efaf1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1997,6 +1997,11 @@ js-yaml@^3.5.1: argparse "^1.0.7" esprima "^4.0.0" +jsbi@^3.1.4: + version "3.1.4" + resolved "https://registry.yarnpkg.com/jsbi/-/jsbi-3.1.4.tgz#9654dd02207a66a4911b4e4bb74265bc2cbc9dd0" + integrity sha512-52QRRFSsi9impURE8ZUbzAMCLjPm4THO7H2fcuIvaaeFTbSysvkodbQQXIVsNgq/ypDbq6dJiuGKL0vZ/i9hUg== + jsbn@~0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" -- GitLab