Expand types & tests (#166)
* RegEx for alias * Expand tests * Cleanup naming * Options & Struct tests * Cleanup Length with tests * Enum tests * TODO... expand/question assumption * Remove extra line * Hashin tests (commented, encoding change) * Export Type on Vector & Struct * Test Type & Base * Address FIXME & additional test * Cleanup TODOs * Add MisbehaviorReport * Add index.ts combinators * typo in export * Comment typo * Update index.ts * Update MisbehaviorReport.ts * Update MisbehaviorReport.spec.js * Extract Bft, add SignedBlock (allow anonymous structures) * <foo>Struct -> <foo>Value (for constructor args) * AnyNumber/U8a types for inputs (PR comment) * Comment struct generics * Typo in comment * Simplify StorageFunctionType construction * Fix liniting (wtf?) * Fix linting & tests, make more robust
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { AnyNumber } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import isHex from '@polkadot/util/is/hex';
|
||||
import isString from '@polkadot/util/is/string';
|
||||
@@ -24,7 +26,7 @@ type BitLength = 8 | 16 | 32 | 64 | 128 | 256;
|
||||
export default class UInt extends Base<BN> {
|
||||
private _bitLength: BitLength;
|
||||
|
||||
constructor (value: UInt | BN | string | number = 0, bitLength: BitLength = 64) {
|
||||
constructor (value: AnyNumber = 0, bitLength: BitLength = 64) {
|
||||
super(
|
||||
UInt.decode(value)
|
||||
);
|
||||
@@ -32,7 +34,7 @@ export default class UInt extends Base<BN> {
|
||||
this._bitLength = bitLength;
|
||||
}
|
||||
|
||||
static decode (value: UInt | BN | string | number): BN {
|
||||
static decode (value: AnyNumber): BN {
|
||||
if (value instanceof UInt) {
|
||||
return value.raw;
|
||||
} else if (isHex(value)) {
|
||||
@@ -60,6 +62,10 @@ export default class UInt extends Base<BN> {
|
||||
return this;
|
||||
}
|
||||
|
||||
toHex (): string {
|
||||
return bnToHex(this.raw, this._bitLength);
|
||||
}
|
||||
|
||||
toJSON (): any {
|
||||
return this.toString();
|
||||
}
|
||||
@@ -69,7 +75,7 @@ export default class UInt extends Base<BN> {
|
||||
}
|
||||
|
||||
toString (): string {
|
||||
return bnToHex(this.raw, this._bitLength);
|
||||
return this.toHex();
|
||||
}
|
||||
|
||||
toBn (): BN {
|
||||
|
||||
Reference in New Issue
Block a user