Fix c-like enums type encoding (#2703)
* Fix c-like enums type encoding * Update packages/api-contract/src/ContractRegistry.ts * Update packages/types/src/codec/utils/encodeTypes.ts
This commit is contained in:
@@ -53,7 +53,14 @@ export default class ContractRegistry {
|
||||
}
|
||||
|
||||
public setTypeDef (id: MtLookupTypeId): void {
|
||||
this.typeDefs[getRegistryOffset(id)] = this.extractType(this.getAbiType(id), id) as TypeDef;
|
||||
const typeDef = this.extractType(this.getAbiType(id), id) as TypeDef;
|
||||
|
||||
this.typeDefs[getRegistryOffset(id)] = typeDef;
|
||||
|
||||
// we have a displayName for non-primitives and non-results
|
||||
if (typeDef.displayName) {
|
||||
this.registry.register({ [typeDef.displayName]: typeDef.type });
|
||||
}
|
||||
}
|
||||
|
||||
private extractType (inkType: MtType, id: MtLookupTypeId): Pick<TypeDef, never> {
|
||||
|
||||
@@ -5,7 +5,9 @@ import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import { AnyJson, Registry } from '@polkadot/types/types';
|
||||
import { ApiObject } from '../types';
|
||||
|
||||
import { TypeRegistry } from '@polkadot/types';
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import Abi from '../Abi';
|
||||
|
||||
export default abstract class Base<ApiType extends ApiTypes> {
|
||||
@@ -18,11 +20,11 @@ export default abstract class Base<ApiType extends ApiTypes> {
|
||||
protected readonly _decorateMethod: DecorateMethod<ApiType>;
|
||||
|
||||
constructor (api: ApiObject<ApiType>, abi: AnyJson | Abi, decorateMethod: DecorateMethod<ApiType>) {
|
||||
this.registry = new TypeRegistry();
|
||||
this.abi = abi instanceof Abi
|
||||
? abi
|
||||
: new Abi(api.registry, abi);
|
||||
: new Abi(this.registry, abi);
|
||||
this.api = api;
|
||||
this.registry = api.registry;
|
||||
this._decorateMethod = decorateMethod;
|
||||
|
||||
assert(this.api.rx.tx.contracts && this.api.rx.tx.contracts.putCode, 'You need to connect to a node with the contracts module, the metadata does not enable api.tx.contracts on this instance');
|
||||
|
||||
Reference in New Issue
Block a user