@polkadot/params
Advanced tools
Comparing version 0.13.10 to 0.14.1
@@ -1,26 +0,26 @@ | ||
'use strict'; | ||
"use strict"; | ||
var u8aToHex = require('@polkadot/util/u8a/toHex'); // Copyright 2017-2018 Jaco Greeff | ||
// Copyright 2017-2018 Jaco Greeff | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const u8aToHex = require('@polkadot/util/u8a/toHex'); | ||
const decodeValue = require('./value'); | ||
var decodeValue = require('./value'); | ||
var decodeValues = require('./values'); | ||
const decodeValues = require('./values'); | ||
module.exports = function decode(type, input) { | ||
var final = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
module.exports = function decode(type, input, final = true) { | ||
const { | ||
length, | ||
value | ||
} = Array.isArray(type) ? decodeValues(decode, type, input) : decodeValue(decode, type, input); | ||
var _ref = Array.isArray(type) ? decodeValues(decode, type, input) : decodeValue(decode, type, input), | ||
length = _ref.length, | ||
value = _ref.value; | ||
if (final && length !== input.length) { | ||
console.error(type, ':: Expected ' + length + ' bytes, received ' + input.length + ' from ' + u8aToHex(input)); | ||
console.error(type, `:: Expected ${length} bytes, received ${input.length} from ${u8aToHex(input)}`); | ||
} | ||
return { | ||
length: length, | ||
value: value | ||
length, | ||
value | ||
}; | ||
}; |
@@ -1,1 +0,1 @@ | ||
'use strict'; | ||
"use strict"; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,11 +6,10 @@ // Copyright 2017-2018 Jaco Greeff | ||
// of the ISC license. See the LICENSE file for details. | ||
var u8aToBn = require('@polkadot/util/u8a/toBn'); | ||
const u8aToBn = require('@polkadot/util/u8a/toBn'); | ||
module.exports = function bn(decode, input, bitLength) { | ||
var length = bitLength / 8; | ||
const length = bitLength / 8; | ||
return { | ||
length: length, | ||
length, | ||
value: u8aToBn(input.subarray(0, length), true) | ||
}; | ||
}; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -3,0 +3,0 @@ // Copyright 2017-2018 Jaco Greeff |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -3,0 +3,0 @@ // Copyright 2017-2018 Jaco Greeff |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,7 +6,6 @@ // Copyright 2017-2018 Jaco Greeff | ||
// of the ISC license. See the LICENSE file for details. | ||
var u8aToBn = require('@polkadot/util/u8a/toBn'); | ||
const u8aToBn = require('@polkadot/util/u8a/toBn'); | ||
module.exports = function bytes(decode, input) { | ||
var length = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
const length = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
return { | ||
@@ -13,0 +12,0 @@ length: length + 4, |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -3,0 +3,0 @@ // Copyright 2017-2018 Jaco Greeff |
@@ -1,24 +0,22 @@ | ||
'use strict'; | ||
"use strict"; | ||
var u8aToBn = require('@polkadot/util/u8a/toBn'); // Copyright 2017-2018 Jaco Greeff | ||
// Copyright 2017-2018 Jaco Greeff | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const u8aToBn = require('@polkadot/util/u8a/toBn'); | ||
const bytes = require('./bytes'); | ||
var bytes = require('./bytes'); | ||
module.exports = function digest(decode, input) { | ||
// FIXME: We should be returning a digest object, not a raw | ||
var logLength = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
var value = { | ||
const logLength = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
const value = { | ||
logs: [] | ||
}; | ||
let length = 4; | ||
var length = 4; | ||
for (let index = 0; index < logLength; index++) { | ||
const decoded = bytes(decode, input.subarray(length)); | ||
length += decoded.length; // flowlint-next-line unclear-type:off | ||
for (var index = 0; index < logLength; index++) { | ||
var decoded = bytes(decode, input.subarray(length)); | ||
length += decoded.length; | ||
// flowlint-next-line unclear-type:off | ||
digest.logs.push(decoded.value); | ||
@@ -28,5 +26,5 @@ } | ||
return { | ||
length: length, | ||
value: value | ||
length, | ||
value | ||
}; | ||
}; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,14 +6,24 @@ // Copyright 2017-2018 Jaco Greeff | ||
// of the ISC license. See the LICENSE file for details. | ||
var bool = require('./bool'); | ||
var bn = require('./bn'); | ||
var byte = require('./byte'); | ||
var bytes = require('./bytes'); | ||
var code = require('./code'); | ||
var digest = require('./digest'); | ||
var keyValue = require('./keyValue'); | ||
var method = require('./method'); | ||
var misbehavior = require('./misbehavior'); | ||
var time = require('./time'); | ||
var u8a = require('./u8a'); | ||
const bool = require('./bool'); | ||
const bn = require('./bn'); | ||
const byte = require('./byte'); | ||
const bytes = require('./bytes'); | ||
const code = require('./code'); | ||
const digest = require('./digest'); | ||
const keyValue = require('./keyValue'); | ||
const method = require('./method'); | ||
const misbehavior = require('./misbehavior'); | ||
const time = require('./time'); | ||
const u8a = require('./u8a'); | ||
module.exports = function decodeValue(decode, type, input) { | ||
@@ -75,4 +85,5 @@ switch (type) { | ||
type; // eslint-disable-line no-unused-expressions | ||
throw new Error('No value decoder for type=\'' + type + '\''); | ||
throw new Error(`No value decoder for type='${type}'`); | ||
} | ||
}; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,18 +6,17 @@ // Copyright 2017-2018 Jaco Greeff | ||
// of the ISC license. See the LICENSE file for details. | ||
var u8aToBn = require('@polkadot/util/u8a/toBn'); | ||
const u8aToBn = require('@polkadot/util/u8a/toBn'); | ||
module.exports = function bytes(decode, input) { | ||
var keyLength = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
var key = input.subarray(4, keyLength + 4); | ||
var valLength = u8aToBn(input.subarray(keyLength, keyLength + 4), true).toNumber(); | ||
var length = valLength + keyLength + 8; | ||
var value = input.subarray(keyLength + 8, length); | ||
const keyLength = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
const key = input.subarray(4, keyLength + 4); | ||
const valLength = u8aToBn(input.subarray(keyLength, keyLength + 4), true).toNumber(); | ||
const length = valLength + keyLength + 8; | ||
const value = input.subarray(keyLength + 8, length); | ||
return { | ||
length: length, | ||
length, | ||
value: { | ||
key: key, | ||
value: value | ||
key, | ||
value | ||
} | ||
}; | ||
}; |
@@ -1,24 +0,19 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _values = require('babel-runtime/core-js/object/values'); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _values2 = _interopRequireDefault(_values); | ||
var _values = _interopRequireDefault(require("@babel/runtime/core-js/object/values")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// Copyright 2017-2018 Jaco Greeff | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
var extrinsics = require('@polkadot/extrinsics-substrate'); | ||
const extrinsics = require('@polkadot/extrinsics-substrate'); | ||
module.exports = function call(decode, input, isPublic) { | ||
// flowlint-next-line unclear-type:off | ||
var sections = (0, _values2.default)(extrinsics); | ||
var section = sections.find(function (section) { | ||
return section.index[0] === input[0]; | ||
}); | ||
const sections = (0, _values.default)(extrinsics); | ||
const section = sections.find(section => section.index[0] === input[0]); | ||
if (!section) { | ||
console.error(':: Unable to find section', input[0]); | ||
return { | ||
@@ -30,13 +25,10 @@ length: 0, | ||
}; | ||
} | ||
} // flowlint-next-line unclear-type:off | ||
// flowlint-next-line unclear-type:off | ||
var methods = (0, _values2.default)(section.methods[isPublic ? 'public' : 'private']); | ||
var extrinsic = methods.find(function (method) { | ||
return method.index[0] === input[1]; | ||
}); | ||
const methods = (0, _values.default)(section.methods[isPublic ? 'public' : 'private']); | ||
const extrinsic = methods.find(method => method.index[0] === input[1]); | ||
if (!extrinsic) { | ||
console.error(':: Unable to find method', input[1]); | ||
return { | ||
@@ -48,28 +40,27 @@ length: 0, | ||
}; | ||
} | ||
} // flowlint-next-line unclear-type:off | ||
// flowlint-next-line unclear-type:off | ||
var params = (0, _values2.default)(extrinsic.params); | ||
var result = { | ||
length: 2, // sectionId + methodId | ||
const params = (0, _values.default)(extrinsic.params); | ||
const result = { | ||
length: 2, | ||
// sectionId + methodId | ||
value: { | ||
extrinsic: extrinsic, | ||
extrinsic, | ||
params: [] | ||
} | ||
}; | ||
return params.reduce(function (_ref, _ref2) { | ||
var length = _ref.length, | ||
value = _ref.value; | ||
var type = _ref2.type; | ||
var decoded = decode(type, input.subarray(length), false); | ||
return params.reduce(({ | ||
length, | ||
value | ||
}, { | ||
type | ||
}) => { | ||
const decoded = decode(type, input.subarray(length), false); | ||
value.params.push(decoded.value); | ||
return { | ||
length: length + decoded.length, | ||
value: value | ||
value | ||
}; | ||
}, result); | ||
}; |
@@ -1,22 +0,21 @@ | ||
'use strict'; | ||
"use strict"; | ||
var u8aToBn = require('@polkadot/util/u8a/toBn'); // Copyright 2017-2018 Jaco Greeff | ||
// Copyright 2017-2018 Jaco Greeff | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const u8aToBn = require('@polkadot/util/u8a/toBn'); | ||
const O_PHASH = 0; | ||
const O_PNUM = 32; | ||
const O_AUTH = O_PNUM + 8; | ||
const O_TYPE = O_AUTH + 32; | ||
const A_HASH = O_TYPE + 1; | ||
const A_SIG = A_HASH + 32; | ||
const B_HASH = A_SIG + 64; | ||
const B_SIG = B_HASH + 32; | ||
const length = B_SIG + 64; | ||
var O_PHASH = 0; | ||
var O_PNUM = 32; | ||
var O_AUTH = O_PNUM + 8; | ||
var O_TYPE = O_AUTH + 32; | ||
var A_HASH = O_TYPE + 1; | ||
var A_SIG = A_HASH + 32; | ||
var B_HASH = A_SIG + 64; | ||
var B_SIG = B_HASH + 32; | ||
var length = B_SIG + 64; | ||
module.exports = function misbehavior(decode, input) { | ||
return { | ||
length: length, | ||
length, | ||
value: { | ||
@@ -23,0 +22,0 @@ parentHash: input.subarray(O_PHASH, O_PNUM), |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,3 +6,3 @@ // Copyright 2017-2018 Jaco Greeff | ||
// of the ISC license. See the LICENSE file for details. | ||
var u8aToBn = require('@polkadot/util/u8a/toBn'); | ||
const u8aToBn = require('@polkadot/util/u8a/toBn'); | ||
@@ -9,0 +9,0 @@ module.exports = function time(decode, input) { |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -7,8 +7,7 @@ // Copyright 2017-2018 Jaco Greeff | ||
module.exports = function u8a(decode, input, bitLength) { | ||
var length = bitLength / 8; | ||
const length = bitLength / 8; | ||
return { | ||
length: length, | ||
length, | ||
value: input.subarray(0, length) | ||
}; | ||
}; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,22 +6,19 @@ // Copyright 2017-2018 Jaco Greeff | ||
// of the ISC license. See the LICENSE file for details. | ||
var assert = require('@polkadot/util/assert'); | ||
var u8aToBn = require('@polkadot/util/u8a/toBn'); | ||
const assert = require('@polkadot/util/assert'); | ||
const u8aToBn = require('@polkadot/util/u8a/toBn'); | ||
module.exports = function decodeValues(decode, type, input) { | ||
assert(type.length !== 0, 'Expected Array input type to decode, found empty instead'); | ||
let value = []; | ||
let length = 0; // Arrays have single entries, Tuples will have multiple types | ||
var value = []; | ||
var length = 0; | ||
// Arrays have single entries, Tuples will have multiple types | ||
if (type.length === 1) { | ||
// $FlowFixMe yes, we have a single type internally | ||
var _type = type[0]; | ||
var arrayLength = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
const _type = type[0]; | ||
const arrayLength = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
length = 4; | ||
for (var index = 0; index < arrayLength; index++) { | ||
var decoded = decode(_type, input.subarray(length), false); | ||
for (let index = 0; index < arrayLength; index++) { | ||
const decoded = decode(_type, input.subarray(length), false); | ||
value.push(decoded.value); | ||
@@ -32,5 +29,4 @@ length += decoded.length; | ||
// $FlowFixMe yes, we have a single type internally | ||
type.forEach(function (_type) { | ||
var decoded = decode(_type, input.subarray(length), false); | ||
type.forEach(_type => { | ||
const decoded = decode(_type, input.subarray(length), false); | ||
value.push(decoded.value); | ||
@@ -41,6 +37,5 @@ length += decoded.length; | ||
assert(length <= input.length, 'Invalid parameter decoding input length, expected at least ' + length + ' bytes decoded, found ' + input.length); | ||
assert(length <= input.length, `Invalid parameter decoding input length, expected at least ${length} bytes decoded, found ${input.length}`); | ||
return { | ||
length: length, | ||
length, | ||
// flowlint-next-line unclear-type:off | ||
@@ -47,0 +42,0 @@ value: value |
{ | ||
"name": "@polkadot/params", | ||
"version": "0.13.10", | ||
"version": "0.14.1", | ||
"description": "Type defintions for parameters as passed in calls", | ||
@@ -32,8 +32,8 @@ "main": "index.js", | ||
"dependencies": { | ||
"@polkadot/extrinsics": "^0.13.10", | ||
"@polkadot/extrinsics-substrate": "^0.13.10", | ||
"@polkadot/primitives": "^0.13.10", | ||
"@polkadot/util": "^0.19.7", | ||
"babel-runtime": "^6.26.0" | ||
"@babel/runtime": "^7.0.0-beta.47", | ||
"@polkadot/extrinsics": "^0.14.1", | ||
"@polkadot/extrinsics-substrate": "^0.14.1", | ||
"@polkadot/primitives": "^0.14.1", | ||
"@polkadot/util": "^0.20.3" | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
'use strict'; | ||
"use strict"; |
28710
305
+ Added@polkadot/extrinsics@0.14.3(transitive)
+ Added@polkadot/extrinsics-substrate@0.14.3(transitive)
+ Added@polkadot/params@0.14.3(transitive)
+ Added@polkadot/primitives@0.14.3(transitive)
+ Added@polkadot/util@0.20.5(transitive)
- Removedbabel-runtime@^6.26.0
- Removed@polkadot/extrinsics@0.13.10(transitive)
- Removed@polkadot/extrinsics-substrate@0.13.10(transitive)
- Removed@polkadot/primitives@0.13.10(transitive)
- Removed@polkadot/util@0.19.9(transitive)
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedregenerator-runtime@0.11.1(transitive)
Updated@polkadot/extrinsics@^0.14.1
Updated@polkadot/primitives@^0.14.1
Updated@polkadot/util@^0.20.3