Calculate hash on pass-through (#70)
This commit is contained in:
@@ -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
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user