@polkadot/params
Advanced tools
Comparing version 0.17.28 to 0.18.2
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = decode; | ||
require("core-js/modules/web.dom.iterable"); | ||
var _toBn = _interopRequireDefault(require("@polkadot/util/u8a/toBn")); | ||
var _value = _interopRequireDefault(require("./value")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// 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 decodeValue = require('./value'); | ||
function decodeTuple(type, input, version) { | ||
@@ -27,3 +34,3 @@ const value = []; | ||
function decodeArray([type], input, version) { | ||
const arrayLength = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
const arrayLength = (0, _toBn.default)(input.subarray(0, 4), true).toNumber(); | ||
const value = []; | ||
@@ -54,5 +61,3 @@ let length = 4; | ||
return decodeValue(decode, type, input, version); | ||
} | ||
module.exports = decode; | ||
return (0, _value.default)(decode, type, input, version); | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = bn; | ||
var _toBn = _interopRequireDefault(require("@polkadot/util/u8a/toBn")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// 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'); | ||
module.exports = function bn(input, bitLength) { | ||
function bn(input, bitLength) { | ||
const length = bitLength / 8; | ||
return { | ||
length, | ||
value: u8aToBn(input.subarray(0, length), true) | ||
value: (0, _toBn.default)(input.subarray(0, length), true) | ||
}; | ||
}; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = bool; | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
module.exports = function bool(input) { | ||
function bool(input) { | ||
return { | ||
@@ -11,2 +16,2 @@ length: 1, | ||
}; | ||
}; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = byte; | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
module.exports = function byte(input) { | ||
function byte(input) { | ||
return { | ||
@@ -11,2 +16,2 @@ length: 1, | ||
}; | ||
}; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = bytes; | ||
var _toBn = _interopRequireDefault(require("@polkadot/util/u8a/toBn")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// 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'); | ||
module.exports = function bytes(input) { | ||
const length = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
function bytes(input) { | ||
const length = (0, _toBn.default)(input.subarray(0, 4), true).toNumber(); | ||
return { | ||
@@ -14,2 +21,2 @@ length: length + 4, | ||
}; | ||
}; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = code; | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
module.exports = function code(input) { | ||
function code(input) { | ||
return { | ||
@@ -11,2 +16,2 @@ length: input.length, | ||
}; | ||
}; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = digest; | ||
var _toBn = _interopRequireDefault(require("@polkadot/util/u8a/toBn")); | ||
var _bytes = _interopRequireDefault(require("./bytes")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// 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'); | ||
module.exports = function digest(input) { | ||
const logLength = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
function digest(input) { | ||
const logLength = (0, _toBn.default)(input.subarray(0, 4), true).toNumber(); | ||
const value = { | ||
@@ -18,3 +25,3 @@ logs: [] | ||
for (let index = 0; index < logLength; index++) { | ||
const decoded = bytes(input.subarray(length)); | ||
const decoded = (0, _bytes.default)(input.subarray(length)); | ||
length += decoded.length; // flowlint-next-line unclear-type:off | ||
@@ -29,2 +36,2 @@ | ||
}; | ||
}; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = header; | ||
var _decode = _interopRequireDefault(require("@polkadot/primitives-codec/header/decode")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const decodeHeader = require('@polkadot/primitives-codec/header/decode'); | ||
module.exports = function header(input) { | ||
function header(input) { | ||
// FIXME We don't have a way to determine the length atm | ||
const length = input.length; | ||
const value = decodeHeader(input); | ||
const value = (0, _decode.default)(input); | ||
return { | ||
@@ -16,2 +23,2 @@ length, | ||
}; | ||
}; | ||
} |
"use strict"; | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const sizes = require('@polkadot/primitives/sizes'); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
const bool = require('./bool'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = decodeValue; | ||
const bn = require('./bn'); | ||
var _sizes = _interopRequireDefault(require("@polkadot/primitives/sizes")); | ||
const byte = require('./byte'); | ||
var _bool = _interopRequireDefault(require("./bool")); | ||
const bytes = require('./bytes'); | ||
var _bn = _interopRequireDefault(require("./bn")); | ||
const code = require('./code'); | ||
var _byte = _interopRequireDefault(require("./byte")); | ||
const digest = require('./digest'); | ||
var _bytes = _interopRequireDefault(require("./bytes")); | ||
const header = require('./header'); | ||
var _code = _interopRequireDefault(require("./code")); | ||
const keyValue = require('./keyValue'); | ||
var _digest = _interopRequireDefault(require("./digest")); | ||
const method = require('./method'); | ||
var _header = _interopRequireDefault(require("./header")); | ||
const misbehavior = require('./misbehavior'); | ||
var _keyValue = _interopRequireDefault(require("./keyValue")); | ||
const passThrough = require('./passThrough'); | ||
var _method = _interopRequireDefault(require("./method")); | ||
const string = require('./string'); | ||
var _misbehavior = _interopRequireDefault(require("./misbehavior")); | ||
const time = require('./time'); | ||
var _passThrough = _interopRequireDefault(require("./passThrough")); | ||
const u8a = require('./u8a'); | ||
var _string = _interopRequireDefault(require("./string")); | ||
module.exports = function decodeValue(decode, type, input, version) { | ||
var _time = _interopRequireDefault(require("./time")); | ||
var _u8a = _interopRequireDefault(require("./u8a")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
function decodeValue(decode, type, input, version) { | ||
try { | ||
@@ -41,6 +48,6 @@ switch (type) { | ||
case 'AccountId': | ||
return u8a(input, 256, version === 'poc-1' ? 0 : 1); | ||
return (0, _u8a.default)(input, 256, version === 'poc-1' ? 0 : 1); | ||
case 'Balance': | ||
return bn(input, sizes.Balance); | ||
return (0, _bn.default)(input, _sizes.default.Balance); | ||
@@ -50,38 +57,38 @@ case 'BlockNumber': | ||
case 'u64': | ||
return bn(input, 64); | ||
return (0, _bn.default)(input, 64); | ||
case 'bool': | ||
return bool(input); | ||
return (0, _bool.default)(input); | ||
case 'Bytes': | ||
return bytes(input); | ||
return (0, _bytes.default)(input); | ||
case 'Call': | ||
case 'Proposal': | ||
return method(decode, input, type === 'Call', version); | ||
return (0, _method.default)(decode, input, type === 'Call', version); | ||
case 'Code': | ||
return code(input); | ||
return (0, _code.default)(input); | ||
case 'CandidateReceipt': | ||
return passThrough(input); | ||
return (0, _passThrough.default)(input); | ||
case 'Digest': | ||
return digest(input); | ||
return (0, _digest.default)(input); | ||
case 'Header': | ||
return header(input); | ||
return (0, _header.default)(input); | ||
case 'Hash': | ||
return u8a(input, 256, 0); | ||
return (0, _u8a.default)(input, 256, 0); | ||
case 'Index': | ||
return bn(input, sizes.Index); | ||
return (0, _bn.default)(input, _sizes.default.Index); | ||
case 'KeyValue': | ||
case 'KeyValueStorage': | ||
return keyValue(input); | ||
return (0, _keyValue.default)(input); | ||
case 'MisbehaviorReport': | ||
return misbehavior(input); | ||
return (0, _misbehavior.default)(input); | ||
@@ -93,18 +100,18 @@ case 'ParachainId': | ||
case 'VoteIndex': | ||
return bn(input, 32); | ||
return (0, _bn.default)(input, 32); | ||
case 'Signature': | ||
return u8a(input, 512, 0); | ||
return (0, _u8a.default)(input, 512, 0); | ||
case 'String': | ||
return string(input); | ||
return (0, _string.default)(input); | ||
case 'Timestamp': | ||
return time(input); | ||
return (0, _time.default)(input); | ||
case 'u128': | ||
return bn(input, 128); | ||
return (0, _bn.default)(input, 128); | ||
case 'VoteThreshold': | ||
return byte(input); | ||
return (0, _byte.default)(input); | ||
@@ -121,2 +128,2 @@ default: | ||
} | ||
}; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = bytes; | ||
var _toBn = _interopRequireDefault(require("@polkadot/util/u8a/toBn")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// 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'); | ||
module.exports = function bytes(input) { | ||
const keyLength = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
function bytes(input) { | ||
const keyLength = (0, _toBn.default)(input.subarray(0, 4), true).toNumber(); | ||
const key = input.subarray(4, keyLength + 4); | ||
const valLength = u8aToBn(input.subarray(keyLength, keyLength + 4), true).toNumber(); | ||
const valLength = (0, _toBn.default)(input.subarray(keyLength, keyLength + 4), true).toNumber(); | ||
const length = valLength + keyLength + 8; | ||
@@ -21,2 +28,2 @@ const value = input.subarray(keyLength + 8, length); | ||
}; | ||
}; | ||
} |
@@ -5,12 +5,17 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = call; | ||
var _keys = _interopRequireDefault(require("@babel/runtime/core-js/object/keys")); | ||
var _extrinsics = _interopRequireDefault(require("@polkadot/extrinsics")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const extrinsics = require('@polkadot/extrinsics'); | ||
function call(decode, input, isPublic, version) { | ||
const section = (0, _keys.default)(_extrinsics.default).find(name => _extrinsics.default[name].index[0] === input[0]); | ||
module.exports = function call(decode, input, isPublic, version) { | ||
const section = (0, _keys.default)(extrinsics).find(name => extrinsics[name].index[0] === input[0]); | ||
if (section === undefined) { | ||
@@ -20,3 +25,3 @@ throw new Error(`Unable to find extrinsic section ${input[0]}`); | ||
const methods = isPublic ? extrinsics[section].public : extrinsics[section].private; | ||
const methods = isPublic ? _extrinsics.default[section].public : _extrinsics.default[section].private; | ||
const method = (0, _keys.default)(methods).find(name => methods[name].index[1] === input[1]); | ||
@@ -50,2 +55,2 @@ | ||
}, result); | ||
}; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = misbehavior; | ||
var _toBn = _interopRequireDefault(require("@polkadot/util/u8a/toBn")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// 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; | ||
@@ -18,3 +25,3 @@ const O_PNUM = 32; | ||
module.exports = function misbehavior(input) { | ||
function misbehavior(input) { | ||
return { | ||
@@ -24,3 +31,3 @@ length, | ||
parentHash: input.subarray(O_PHASH, O_PNUM), | ||
number: u8aToBn(input.subarray(O_PNUM, O_AUTH), true), | ||
number: (0, _toBn.default)(input.subarray(O_PNUM, O_AUTH), true), | ||
authorityId: input.subarray(O_AUTH, O_TYPE), | ||
@@ -37,2 +44,2 @@ type: input[O_TYPE], | ||
}; | ||
}; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = passThrough; | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
module.exports = function passThrough(input) { | ||
function passThrough(input) { | ||
return { | ||
@@ -11,2 +16,2 @@ length: input.length, | ||
}; | ||
}; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = string; | ||
var _toBn = _interopRequireDefault(require("@polkadot/util/u8a/toBn")); | ||
var _toUtf = _interopRequireDefault(require("@polkadot/util/u8a/toUtf8")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// 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 u8aToUtf8 = require('@polkadot/util/u8a/toUtf8'); | ||
module.exports = function string(input) { | ||
const length = u8aToBn(input.subarray(0, 4), true).toNumber(); | ||
function string(input) { | ||
const length = (0, _toBn.default)(input.subarray(0, 4), true).toNumber(); | ||
return { | ||
length: length + 4, | ||
value: u8aToUtf8(input.subarray(4, length + 4)) | ||
value: (0, _toUtf.default)(input.subarray(4, length + 4)) | ||
}; | ||
}; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = time; | ||
var _toBn = _interopRequireDefault(require("@polkadot/util/u8a/toBn")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// 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'); | ||
module.exports = function time(input) { | ||
function time(input) { | ||
return { | ||
length: 8, | ||
value: new Date(u8aToBn(input.subarray(0, 8), true).imuln(1000).toNumber()) | ||
value: new Date((0, _toBn.default)(input.subarray(0, 8), true).imuln(1000).toNumber()) | ||
}; | ||
}; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = u8a; | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
module.exports = function u8a(input, bitLength, offset) { | ||
function u8a(input, bitLength, offset) { | ||
const length = bitLength / 8 + offset; | ||
@@ -12,2 +17,2 @@ return { | ||
}; | ||
}; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = encodeParams; | ||
var _assert = _interopRequireDefault(require("@polkadot/util/assert")); | ||
var _concat = _interopRequireDefault(require("@polkadot/util/u8a/concat")); | ||
var _param = _interopRequireDefault(require("./param")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const assert = require('@polkadot/util/assert'); | ||
const u8aConcat = require('@polkadot/util/u8a/concat'); | ||
const encodeParam = require('./param'); | ||
module.exports = function encodeParams(params, values, version) { | ||
assert(params.length === values.length, `Expected values to have ${params.length} items, found ${values.length} instead`); | ||
return u8aConcat.apply(null, params.map((param, index) => encodeParam(param, values[index], version))); | ||
}; | ||
function encodeParams(params, values, version) { | ||
(0, _assert.default)(params.length === values.length, `Expected values to have ${params.length} items, found ${values.length} instead`); | ||
return _concat.default.apply(null, params.map((param, index) => (0, _param.default)(param, values[index], version))); | ||
} |
"use strict"; | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const assert = require('@polkadot/util/assert'); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
const u8aConcat = require('@polkadot/util/u8a/concat'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = encodeParam; | ||
const bnToU8a = require('@polkadot/util/bn/toU8a'); | ||
var _assert = _interopRequireDefault(require("@polkadot/util/assert")); | ||
const typeToString = require('../typeToString'); | ||
var _concat = _interopRequireDefault(require("@polkadot/util/u8a/concat")); | ||
const encodeType = require('./type'); // flowlint-next-line unclear-type:off | ||
var _toU8a = _interopRequireDefault(require("@polkadot/util/bn/toU8a")); | ||
var _typeToString = _interopRequireDefault(require("../typeToString")); | ||
module.exports = function encodeParam(param, value, version = 'latest') { | ||
var _type = _interopRequireDefault(require("./type")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
// flowlint-next-line unclear-type:off | ||
function encodeParam(param, value, version = 'latest') { | ||
if (Array.isArray(param.type)) { | ||
assert(Array.isArray(value), () => `Expected array values of type '${typeToString(param.type)}'`); // flowlint-next-line unclear-type:off | ||
(0, _assert.default)(Array.isArray(value), () => `Expected array values of type '${(0, _typeToString.default)(param.type)}'`); // flowlint-next-line unclear-type:off | ||
@@ -26,6 +33,6 @@ const arr = value; // $FlowFixMe we have determined that it is an array above | ||
if (types.length === 1) { | ||
return u8aConcat(bnToU8a(arr.length, 32, true), u8aConcat.apply(null, arr.map((v, index) => encodeType(types[0], v, version)))); | ||
return (0, _concat.default)((0, _toU8a.default)(arr.length, 32, true), _concat.default.apply(null, arr.map((v, index) => (0, _type.default)(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 | ||
return (0, _concat.default)((0, _toU8a.default)(arr.length, 32, true), _concat.default.apply(null, arr.map((v, index) => // NOTE since we may have embedded again, move to Param shape | ||
encodeParam({ | ||
@@ -36,3 +43,3 @@ type: types[index] | ||
return encodeType(param.type, value, version); | ||
}; | ||
return (0, _type.default)(param.type, value, version); | ||
} |
"use strict"; | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const addrPrefixes = require('@polkadot/extrinsics-codec/encode/prefixes'); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
const bnToU8a = require('@polkadot/util/bn/toU8a'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = encodeType; | ||
const u8aConcat = require('@polkadot/util/u8a/concat'); | ||
var _prefixes = _interopRequireDefault(require("@polkadot/extrinsics-codec/encode/prefixes")); | ||
const u8aFromString = require('@polkadot/util/u8a/fromString'); | ||
var _toU8a = _interopRequireDefault(require("@polkadot/util/bn/toU8a")); | ||
const u8aToU8a = require('@polkadot/util/u8a/toU8a'); | ||
var _concat = _interopRequireDefault(require("@polkadot/util/u8a/concat")); | ||
const addressDecode = require('@polkadot/util-keyring/address/decode'); | ||
var _fromString = _interopRequireDefault(require("@polkadot/util/u8a/fromString")); | ||
const sizes = require('../../sizes'); // flowlint-next-line unclear-type:off | ||
var _toU8a2 = _interopRequireDefault(require("@polkadot/util/u8a/toU8a")); | ||
var _decode = _interopRequireDefault(require("@polkadot/util-keyring/address/decode")); | ||
module.exports = function encodeType(type, value, version) { | ||
var _sizes = _interopRequireDefault(require("../../sizes")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
// flowlint-next-line unclear-type:off | ||
function encodeType(type, value, version) { | ||
try { | ||
switch (type) { | ||
case 'AccountId': | ||
return u8aConcat(version === 'poc-1' ? addrPrefixes.none : addrPrefixes.publicKey, addressDecode(value)); | ||
return (0, _concat.default)(version === 'poc-1' ? _prefixes.default.none : _prefixes.default.publicKey, (0, _decode.default)(value)); | ||
case 'Balance': | ||
return bnToU8a(value, sizes.Balance[version], true); | ||
return (0, _toU8a.default)(value, _sizes.default.Balance[version], true); | ||
@@ -33,10 +40,10 @@ case 'BlockNumber': | ||
case 'u64': | ||
return bnToU8a(value, 64, true); | ||
return (0, _toU8a.default)(value, 64, true); | ||
case 'bool': | ||
return bnToU8a(value ? 1 : 0, 8, true); | ||
return (0, _toU8a.default)(value ? 1 : 0, 8, true); | ||
case 'Bytes': | ||
case 'Code': | ||
return u8aToU8a(value); | ||
return (0, _toU8a2.default)(value); | ||
// FIXME Here we should pass through the actual objects | ||
@@ -52,3 +59,3 @@ | ||
case 'Proposal': | ||
return u8aToU8a(value); | ||
return (0, _toU8a2.default)(value); | ||
// TODO Here we should do actual length conversions, i.e. 256/512 | ||
@@ -58,6 +65,6 @@ | ||
case 'Signature': | ||
return u8aToU8a(value); | ||
return (0, _toU8a2.default)(value); | ||
case 'Index': | ||
return bnToU8a(value, sizes.Index[version], true); | ||
return (0, _toU8a.default)(value, _sizes.default.Index[version], true); | ||
@@ -69,8 +76,8 @@ case 'ParachainId': | ||
case 'u32': | ||
return bnToU8a(value, 32, true); | ||
return (0, _toU8a.default)(value, 32, true); | ||
case 'String': | ||
return (() => { | ||
const u8a = u8aFromString(value); | ||
return u8aConcat(bnToU8a(u8a.length, 32, true), u8a); | ||
const u8a = (0, _fromString.default)(value); | ||
return (0, _concat.default)((0, _toU8a.default)(u8a.length, 32, true), u8a); | ||
})(); | ||
@@ -83,10 +90,10 @@ | ||
return bnToU8a(value, 64, true); | ||
return (0, _toU8a.default)(value, 64, true); | ||
case 'u128': | ||
return bnToU8a(value, 128, true); | ||
return (0, _toU8a.default)(value, 128, true); | ||
// TODO enums? | ||
case 'VoteThreshold': | ||
return bnToU8a(value || 0, 8, true); | ||
return (0, _toU8a.default)(value || 0, 8, true); | ||
@@ -103,2 +110,2 @@ default: | ||
} | ||
}; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = createMethod; | ||
var _toU8a = _interopRequireDefault(require("@polkadot/util/bn/toU8a")); | ||
var _concat = _interopRequireDefault(require("@polkadot/util/u8a/concat")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const bnToU8a = require('@polkadot/util/bn/toU8a'); | ||
const u8aConcat = require('@polkadot/util/u8a/concat'); | ||
module.exports = function createMethod(section, sectionIndex) { | ||
function createMethod(section, sectionIndex) { | ||
return (name, index = 0) => ({ | ||
@@ -23,3 +30,3 @@ description, | ||
description, | ||
index: u8aConcat(sectionIndex, bnToU8a(index, 8)), | ||
index: (0, _concat.default)(sectionIndex, (0, _toU8a.default)(index, 8)), | ||
isDeprecated, | ||
@@ -36,2 +43,2 @@ isHidden, | ||
}); | ||
}; | ||
} |
{ | ||
"name": "@polkadot/params", | ||
"version": "0.17.28", | ||
"version": "0.18.2", | ||
"description": "Type defintions for parameters as passed in calls", | ||
@@ -37,7 +37,7 @@ "main": "index.js", | ||
"@babel/runtime": "^7.0.0-beta.47", | ||
"@polkadot/extrinsics": "^0.17.28", | ||
"@polkadot/extrinsics-codec": "^0.17.28", | ||
"@polkadot/primitives": "^0.17.28", | ||
"@polkadot/util": "^0.22.11" | ||
"@polkadot/extrinsics": "^0.18.2", | ||
"@polkadot/extrinsics-codec": "^0.18.2", | ||
"@polkadot/primitives": "^0.18.2", | ||
"@polkadot/util": "^0.23.1" | ||
} | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = createParam; | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
module.exports = function createParam(name, type, { | ||
function createParam(name, type, { | ||
isOptional = false | ||
@@ -14,2 +19,2 @@ } = {}) { | ||
}; | ||
}; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = createSection; | ||
var _toU8a = _interopRequireDefault(require("@polkadot/util/bn/toU8a")); | ||
var _method = _interopRequireDefault(require("./method")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const bnToU8a = require('@polkadot/util/bn/toU8a'); | ||
function createSection(name, _index = 0) { | ||
const index = (0, _toU8a.default)(_index, 8); | ||
const createMethod = require('./method'); | ||
module.exports = function createSection(name, _index = 0) { | ||
const index = bnToU8a(_index, 8); | ||
const creator = optOrFn => { | ||
if (typeof optOrFn === 'function') { | ||
return creator(optOrFn(createMethod(name, index))); | ||
return creator(optOrFn((0, _method.default)(name, index))); | ||
} | ||
@@ -35,2 +42,2 @@ | ||
return creator; | ||
}; | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = signature; | ||
var _typeToString = _interopRequireDefault(require("./typeToString")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const typeToString = require('./typeToString'); | ||
/** | ||
@@ -18,5 +27,3 @@ @name signature | ||
*/ | ||
module.exports = function signature({ | ||
function signature({ | ||
name, | ||
@@ -29,4 +36,4 @@ params, | ||
type | ||
}) => `${name}: ${typeToString(type)}`).join(', '); | ||
return `${name} (${inputs}): ${typeToString(type)}`; | ||
}; | ||
}) => `${name}: ${(0, _typeToString.default)(type)}`).join(', '); | ||
return `${name} (${inputs}): ${(0, _typeToString.default)(type)}`; | ||
} |
20
sizes.js
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _sizes = _interopRequireDefault(require("@polkadot/primitives/sizes")); | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
const sizes = require('@polkadot/primitives/sizes'); | ||
const Balance = { | ||
'latest': sizes.Balance, | ||
'latest': _sizes.default.Balance, | ||
'poc-1': 64 | ||
}; | ||
const Index = { | ||
'latest': sizes.Index, | ||
'latest': _sizes.default.Index, | ||
'poc-1': 64 | ||
}; | ||
module.exports = { | ||
var _default = { | ||
Balance, | ||
Index | ||
}; | ||
}; | ||
exports.default = _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = typeToString; | ||
// Copyright 2017-2018 @polkadot/params authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
module.exports = function typeToString(type) { | ||
function typeToString(type) { | ||
if (!Array.isArray(type)) { | ||
@@ -13,2 +18,2 @@ return type; | ||
return type.length !== 1 ? `(${text})` : `Array<${text}>`; | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
55798
684
+ Added@polkadot/extrinsics@0.18.2(transitive)
+ Added@polkadot/extrinsics-codec@0.18.2(transitive)
+ Added@polkadot/primitives@0.18.2(transitive)
+ Added@polkadot/util@0.23.2(transitive)
+ Added@polkadot/util-crypto@0.23.2(transitive)
+ Added@polkadot/util-keyring@0.23.2(transitive)
- Removed@polkadot/extrinsics@0.17.28(transitive)
- Removed@polkadot/extrinsics-codec@0.17.28(transitive)
- Removed@polkadot/primitives@0.17.28(transitive)
- Removed@polkadot/util@0.22.11(transitive)
- Removed@polkadot/util-crypto@0.22.11(transitive)
- Removed@polkadot/util-keyring@0.22.11(transitive)
Updated@polkadot/extrinsics@^0.18.2
Updated@polkadot/primitives@^0.18.2
Updated@polkadot/util@^0.23.1