Calculate hash on pass-through (#70)

This commit is contained in:
Jaco Greeff
2018-04-20 15:25:37 +02:00
committed by GitHub
parent 02659e3fdc
commit 7074036064
8 changed files with 41 additions and 24 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
"test": "jest --coverage"
},
"devDependencies": {
"@polkadot/dev": "^0.17.6",
"@polkadot/dev": "^0.17.9",
"lerna": "^2.5.1"
}
}
+2 -1
View File
@@ -34,7 +34,8 @@
},
"dependencies": {
"@polkadot/primitives-json": "^0.10.1",
"@polkadot/util": "^0.18.6",
"@polkadot/util": "^0.19.1",
"@polkadot/util-crypto": "^0.19.1",
"babel-runtime": "^6.26.0"
}
}
+16 -2
View File
@@ -10,6 +10,7 @@ const bytesDecode = require('@polkadot/primitives-json/bytes/decode');
const headerDecode = require('@polkadot/primitives-json/header/decode');
const isNull = require('@polkadot/util/is/null');
const isUndefined = require('@polkadot/util/is/undefined');
const blake2Asu8a256 = require('@polkadot/util-crypto/blake2/asU8a256');
const format = require('./format');
@@ -20,10 +21,23 @@ const formatters = {
'U64': bnDecode
};
module.exports = function formatOutput (output: InterfaceOutputType, value?: mixed): ?mixed {
module.exports = function formatOutput ({ type, withHash }: InterfaceOutputType, value?: mixed): ?mixed {
if (isUndefined(value) || isNull(value)) {
return value;
}
return format(formatters, [output.type], [value])[0];
const decoded = format(formatters, [type], [value])[0];
// flowlint-next-line sketchy-null-bool:off
if (!withHash) {
return decoded;
}
// flowlint-next-line unclear-type:off
const hash = blake2Asu8a256(((value: any): Uint8Array));
return {
[type.toLowerCase()]: decoded,
hash
};
};
+2 -1
View File
@@ -16,6 +16,7 @@ module.exports = ({
isSubscription: true,
inputs: [],
output: {
type: 'Header'
type: 'Header',
withHash: true
}
}: InterfaceMethodDefinition);
+2 -1
View File
@@ -16,7 +16,8 @@ export type InterfaceInputType = {
};
export type InterfaceOutputType = {
type: FormatOutputType
type: FormatOutputType,
withHash?: boolean
};
export type InterfaceMethodDefinition$Subscribe = {
+3 -3
View File
@@ -34,9 +34,9 @@
"nock": "^9.1.0"
},
"dependencies": {
"@polkadot/util": "^0.18.6",
"@polkadot/util-crypto": "^0.18.6",
"@polkadot/util-keyring": "^0.18.6",
"@polkadot/util": "^0.19.1",
"@polkadot/util-crypto": "^0.19.1",
"@polkadot/util-keyring": "^0.19.1",
"babel-runtime": "^6.26.0",
"isomorphic-fetch": "^2.2.1",
"websocket": "^1.0.25"
+1 -1
View File
@@ -33,7 +33,7 @@
"@polkadot/api-format": "^0.8.14",
"@polkadot/api-jsonrpc": "^0.8.14",
"@polkadot/api-provider": "^0.8.14",
"@polkadot/util": "^0.18.6",
"@polkadot/util": "^0.19.1",
"babel-runtime": "^6.26.0"
}
}
+14 -14
View File
@@ -79,9 +79,9 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"
"@polkadot/dev@^0.17.6":
version "0.17.6"
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.17.6.tgz#8935c83ee71d32bf343e83fe537deb20b5764be0"
"@polkadot/dev@^0.17.9":
version "0.17.9"
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.17.9.tgz#12316416384eb3da5e926f2e875902a3c8e4e5a3"
dependencies:
babel-cli "^6.26.0"
babel-core "^6.26.0"
@@ -176,9 +176,9 @@
tweetnacl "^1.0.0"
xxhashjs "^0.2.2"
"@polkadot/util-crypto@^0.18.6":
version "0.18.6"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.18.6.tgz#57735d2056d178a3e741ca402ea1ae43267d81f8"
"@polkadot/util-crypto@^0.19.1":
version "0.19.1"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.19.1.tgz#95927de2f8a4384f05b872132e00bfd34aa1ea77"
dependencies:
babel-runtime "^6.26.0"
blakejs "^1.1.0"
@@ -194,12 +194,12 @@
"@polkadot/util-crypto" "^0.18.4"
babel-runtime "^6.26.0"
"@polkadot/util-keyring@^0.18.6":
version "0.18.6"
resolved "https://registry.yarnpkg.com/@polkadot/util-keyring/-/util-keyring-0.18.6.tgz#983b58ac371a5866adcc0469d8c03a24a7a77f06"
"@polkadot/util-keyring@^0.19.1":
version "0.19.1"
resolved "https://registry.yarnpkg.com/@polkadot/util-keyring/-/util-keyring-0.19.1.tgz#dbf6e9efbe1dd4de982367c279b3193584db414f"
dependencies:
"@polkadot/util" "^0.18.6"
"@polkadot/util-crypto" "^0.18.6"
"@polkadot/util" "^0.19.1"
"@polkadot/util-crypto" "^0.19.1"
babel-runtime "^6.26.0"
"@polkadot/util-rlp@^0.18.4":
@@ -227,9 +227,9 @@
deasync "^0.1.12"
ip-regex "^2.1.0"
"@polkadot/util@^0.18.6":
version "0.18.6"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.18.6.tgz#dd3ea07d67d31de02a154dd54665ce9779a73211"
"@polkadot/util@^0.19.1":
version "0.19.1"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.19.1.tgz#e19dc51b3d998b489ed26738a3a1e0cded65c020"
dependencies:
babel-runtime "^6.26.0"
bn.js "^4.11.8"