@polkadot/params
Advanced tools
Comparing version 0.17.12 to 0.17.13
@@ -12,11 +12,23 @@ "use strict"; | ||
const typeToString = require('../typeToString'); | ||
const encodeType = require('./type'); // flowlint-next-line unclear-type:off | ||
module.exports = function encodeParam(param, value, version) { | ||
module.exports = function encodeParam(param, value, version = 'latest') { | ||
if (Array.isArray(param.type)) { | ||
assert(Array.isArray(value) && value.length === param.type.length, `Expected array values, with length matching ${param.type.length}`); // flowlint-next-line unclear-type:off | ||
assert(Array.isArray(value), () => `Expected array values of type '${typeToString(param.type)}'`); // flowlint-next-line unclear-type:off | ||
const arr = value; | ||
return u8aConcat(bnToU8a(arr.length, 32, true), u8aConcat.apply(null, arr.map((v, index) => encodeParam(param.type[index], v, version)))); | ||
const arr = value; // $FlowFixMe we have determined that it is an array above | ||
const types = param.type; | ||
if (types.length === 1) { | ||
return u8aConcat(bnToU8a(arr.length, 32, true), u8aConcat.apply(null, arr.map((v, index) => encodeType(types[0], v, version)))); | ||
} | ||
return u8aConcat(bnToU8a(arr.length, 32, true), u8aConcat.apply(null, arr.map((v, index) => // NOTE since we may have embedded again, move to Param shape | ||
encodeParam({ | ||
type: types[index] | ||
}, v, version)))); | ||
} | ||
@@ -23,0 +35,0 @@ |
{ | ||
"name": "@polkadot/params", | ||
"version": "0.17.12", | ||
"version": "0.17.13", | ||
"description": "Type defintions for parameters as passed in calls", | ||
@@ -33,6 +33,6 @@ "main": "index.js", | ||
"@babel/runtime": "^7.0.0-beta.47", | ||
"@polkadot/extrinsics": "^0.17.12", | ||
"@polkadot/primitives": "^0.17.12", | ||
"@polkadot/extrinsics": "^0.17.13", | ||
"@polkadot/primitives": "^0.17.13", | ||
"@polkadot/util": "^0.22.4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
48304
564