USize is now non-constructable (#1022)
* USize is now unconstructable * usize CHANGELOG entry
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# 0.82.0-beta.x
|
||||
|
||||
- **Breaking change** The `ContractsAbi` type has been moved from `@polkadot/types` to `import { Abi } from '@polkadot/api-contract`. This paves the way for an enhanced contracts interface, instead of dealing with low-level API calls.
|
||||
- **Breaking change** `usize` is now a blacklisted type that will throw on construction. Since it is platform-specific, it creates incompatibilities between native (generally u64) and WASM (always u32) code. Use one of the `u32` or `u64` types explicitly.
|
||||
- Update with latest substrate 2.x types
|
||||
|
||||
# 0.81.1
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Constructor } from './types';
|
||||
import * as Classes from './index.types';
|
||||
|
||||
const Types = Classes as { [index: string]: Constructor };
|
||||
const UNCONSTRUCTABLE = ['origin', 'usize'];
|
||||
|
||||
describe('types', () => {
|
||||
describe('default creation', () => {
|
||||
@@ -16,7 +17,7 @@ describe('types', () => {
|
||||
const constructFn = () =>
|
||||
new Types[name]();
|
||||
|
||||
if (name === 'Origin') {
|
||||
if (UNCONSTRUCTABLE.includes(name.toLowerCase())) {
|
||||
expect(constructFn).toThrow();
|
||||
} else {
|
||||
expect(constructFn).not.toThrow();
|
||||
@@ -33,7 +34,7 @@ describe('types', () => {
|
||||
const constructFn = () =>
|
||||
new Types[name](new Types.Bytes());
|
||||
|
||||
if (name === 'Origin') {
|
||||
if (UNCONSTRUCTABLE.includes(name.toLowerCase())) {
|
||||
expect(constructFn).toThrow();
|
||||
} else {
|
||||
expect(constructFn).not.toThrow();
|
||||
|
||||
@@ -8,9 +8,16 @@ import U32 from './U32';
|
||||
* @name USize
|
||||
* @description
|
||||
* A System default unsigned number, typically used in RPC to report non-consensus
|
||||
* data. It is a wrapper for [[U32]] as a WASM default (as generated by Rust bindings)
|
||||
* data. It is a wrapper for [[U32]] as a WASM default (as generated by Rust bindings).
|
||||
* It is not to be used, since it created consensus mismatches.
|
||||
*/
|
||||
export default class USize extends U32 {
|
||||
constructor (value?: any) {
|
||||
super(value);
|
||||
|
||||
throw new Error('The `usize` type should not be used. Since it is platform-specific, it creates incompatibilities between native (generally u64) and WASM (always u32) code. Use one of the `u32` or `u64` types explicitly.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import Struct from '../codec/Struct';
|
||||
import Bool from '../primitive/Bool';
|
||||
import USize from '../primitive/USize';
|
||||
import U64 from '../primitive/U64';
|
||||
|
||||
/**
|
||||
* @name Health
|
||||
@@ -14,7 +14,7 @@ import USize from '../primitive/USize';
|
||||
export default class Health extends Struct {
|
||||
constructor (value?: any) {
|
||||
super({
|
||||
peers: USize,
|
||||
peers: U64,
|
||||
isSyncing: Bool,
|
||||
shouldHavePeers: Bool
|
||||
}, value);
|
||||
@@ -28,10 +28,10 @@ export default class Health extends Struct {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The numbers of peers as [[U32]]
|
||||
* @description The numbers of peers as [[U64]]
|
||||
*/
|
||||
get peers (): USize {
|
||||
return this.get('peers') as USize;
|
||||
get peers (): U64 {
|
||||
return this.get('peers') as U64;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user