Expose event meta (#372)
This commit is contained in:
@@ -10,23 +10,29 @@ import Struct from './codec/Struct';
|
|||||||
import Tuple from './codec/Tuple';
|
import Tuple from './codec/Tuple';
|
||||||
import U8aFixed from './codec/U8aFixed';
|
import U8aFixed from './codec/U8aFixed';
|
||||||
import { TypeDef, getTypeClass, getTypeDef } from './codec/createType';
|
import { TypeDef, getTypeClass, getTypeDef } from './codec/createType';
|
||||||
import Metadata from './Metadata';
|
import Metadata, { EventMetadata } from './Metadata';
|
||||||
|
|
||||||
const EventTypes: { [index: string]: Constructor<EventData> } = {};
|
const EventTypes: { [index: string]: Constructor<EventData> } = {};
|
||||||
|
|
||||||
class EventData extends Tuple {
|
class EventData extends Tuple {
|
||||||
|
private _meta: EventMetadata;
|
||||||
private _method: string;
|
private _method: string;
|
||||||
private _section: string;
|
private _section: string;
|
||||||
private _typeDef: Array<TypeDef>;
|
private _typeDef: Array<TypeDef>;
|
||||||
|
|
||||||
constructor (Types: ConstructorDef, value: Uint8Array, typeDef: Array<TypeDef>, section: string, method: string) {
|
constructor (Types: ConstructorDef, value: Uint8Array, typeDef: Array<TypeDef>, meta: EventMetadata, section: string, method: string) {
|
||||||
super(Types, value);
|
super(Types, value);
|
||||||
|
|
||||||
|
this._meta = meta;
|
||||||
this._method = method;
|
this._method = method;
|
||||||
this._section = section;
|
this._section = section;
|
||||||
this._typeDef = typeDef;
|
this._typeDef = typeDef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get meta (): EventMetadata {
|
||||||
|
return this._meta;
|
||||||
|
}
|
||||||
|
|
||||||
get method (): string {
|
get method (): string {
|
||||||
return this._method;
|
return this._method;
|
||||||
}
|
}
|
||||||
@@ -82,10 +88,10 @@ export default class Event extends Struct {
|
|||||||
metadata.events.forEach((section, sectionIndex) => {
|
metadata.events.forEach((section, sectionIndex) => {
|
||||||
const sectionName = stringCamelCase(section.name.toString());
|
const sectionName = stringCamelCase(section.name.toString());
|
||||||
|
|
||||||
section.events.forEach((event, methodIndex) => {
|
section.events.forEach((meta, methodIndex) => {
|
||||||
const methodName = event.name.toString();
|
const methodName = meta.name.toString();
|
||||||
const eventIndex = new Uint8Array([sectionIndex, methodIndex]);
|
const eventIndex = new Uint8Array([sectionIndex, methodIndex]);
|
||||||
const typeDef = event.arguments.map((arg) => getTypeDef(arg));
|
const typeDef = meta.arguments.map((arg) => getTypeDef(arg));
|
||||||
const Types = typeDef.reduce((result, def, index) => {
|
const Types = typeDef.reduce((result, def, index) => {
|
||||||
result[index] = getTypeClass(def);
|
result[index] = getTypeClass(def);
|
||||||
|
|
||||||
@@ -94,7 +100,7 @@ export default class Event extends Struct {
|
|||||||
|
|
||||||
EventTypes[eventIndex.toString()] = class extends EventData {
|
EventTypes[eventIndex.toString()] = class extends EventData {
|
||||||
constructor (value: Uint8Array) {
|
constructor (value: Uint8Array) {
|
||||||
super(Types, value, typeDef, sectionName, methodName);
|
super(Types, value, typeDef, meta, sectionName, methodName);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -109,6 +115,10 @@ export default class Event extends Struct {
|
|||||||
return this.get('index') as EventIndex;
|
return this.get('index') as EventIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get meta (): EventMetadata {
|
||||||
|
return this.data.meta;
|
||||||
|
}
|
||||||
|
|
||||||
get method (): string {
|
get method (): string {
|
||||||
return this.data.method;
|
return this.data.method;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user