@dedot/contracts 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Contract.d.ts CHANGED
@@ -7,6 +7,7 @@ export declare class Contract<ContractApi extends GenericContractApi = GenericCo
7
7
  #private;
8
8
  constructor(api: ISubstrateClient, metadata: ContractMetadata | string, address: AccountId32Like);
9
9
  decodeEvent(eventRecord: IEventRecord): ContractEvent;
10
+ decodeEvents(eventRecords: IEventRecord[]): ContractEvent[];
10
11
  get metadata(): ContractMetadata;
11
12
  get address(): AccountId32;
12
13
  get registry(): TypinkRegistry;
package/Contract.js CHANGED
@@ -17,6 +17,9 @@ export class Contract {
17
17
  decodeEvent(eventRecord) {
18
18
  return this.#registry.decodeEvent(eventRecord);
19
19
  }
20
+ decodeEvents(eventRecords) {
21
+ return this.#registry.decodeEvents(eventRecords);
22
+ }
20
23
  get metadata() {
21
24
  return this.#metadata;
22
25
  }
@@ -5,5 +5,6 @@ export declare class TypinkRegistry extends TypeRegistry {
5
5
  #private;
6
6
  constructor(metadata: ContractMetadata);
7
7
  get metadata(): ContractMetadata;
8
+ decodeEvents(records: IEventRecord[]): ContractEvent[];
8
9
  decodeEvent(eventRecord: IEventRecord): ContractEvent;
9
10
  }
package/TypinkRegistry.js CHANGED
@@ -11,6 +11,11 @@ export class TypinkRegistry extends TypeRegistry {
11
11
  get metadata() {
12
12
  return this.#metadata;
13
13
  }
14
+ decodeEvents(records) {
15
+ return records
16
+ .filter(({ event }) => this.#isContractEmittedEvent(event)) // prettier-end-here
17
+ .map((record) => this.decodeEvent(record));
18
+ }
14
19
  decodeEvent(eventRecord) {
15
20
  const { version } = this.#metadata;
16
21
  switch (version) {
@@ -22,9 +27,9 @@ export class TypinkRegistry extends TypeRegistry {
22
27
  throw new DedotError('Unsupported metadata version!');
23
28
  }
24
29
  }
25
- #isContractEmittedEvent(eventRecord) {
30
+ #isContractEmittedEvent(event) {
26
31
  // @ts-ignore
27
- return eventRecord.pallet === 'Contracts' && eventRecord.palletEvent.name === 'ContractEmitted';
32
+ return event.pallet === 'Contracts' && event.palletEvent.name === 'ContractEmitted';
28
33
  }
29
34
  #decodeEventV4(eventRecord) {
30
35
  assert(this.#metadata.version === '4', 'Invalid metadata version!');
package/cjs/Contract.js CHANGED
@@ -20,6 +20,9 @@ class Contract {
20
20
  decodeEvent(eventRecord) {
21
21
  return this.#registry.decodeEvent(eventRecord);
22
22
  }
23
+ decodeEvents(eventRecords) {
24
+ return this.#registry.decodeEvents(eventRecords);
25
+ }
23
26
  get metadata() {
24
27
  return this.#metadata;
25
28
  }
@@ -37,6 +37,11 @@ class TypinkRegistry extends codecs_1.TypeRegistry {
37
37
  get metadata() {
38
38
  return this.#metadata;
39
39
  }
40
+ decodeEvents(records) {
41
+ return records
42
+ .filter(({ event }) => this.#isContractEmittedEvent(event)) // prettier-end-here
43
+ .map((record) => this.decodeEvent(record));
44
+ }
40
45
  decodeEvent(eventRecord) {
41
46
  const { version } = this.#metadata;
42
47
  switch (version) {
@@ -48,9 +53,9 @@ class TypinkRegistry extends codecs_1.TypeRegistry {
48
53
  throw new utils_1.DedotError('Unsupported metadata version!');
49
54
  }
50
55
  }
51
- #isContractEmittedEvent(eventRecord) {
56
+ #isContractEmittedEvent(event) {
52
57
  // @ts-ignore
53
- return eventRecord.pallet === 'Contracts' && eventRecord.palletEvent.name === 'ContractEmitted';
58
+ return event.pallet === 'Contracts' && event.palletEvent.name === 'ContractEmitted';
54
59
  }
55
60
  #decodeEventV4(eventRecord) {
56
61
  (0, utils_1.assert)(this.#metadata.version === '4', 'Invalid metadata version!');
package/cjs/errors.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isContractInstantiateLangError = exports.isContractInstantiateDispatchError = exports.isContractInstantiateError = exports.isContractLangError = exports.isContractDispatchError = exports.isContractExecutionError = exports.ContractLangError = exports.ContractDispatchError = exports.ContractExecutionError = exports.ContractInstantiateLangError = exports.ContractInstantiateDispatchError = exports.ContractInstantiateError = void 0;
4
4
  const utils_1 = require("@dedot/utils");
5
+ const utils_js_1 = require("./utils.js");
5
6
  /**
6
7
  * Represents an error that occurred during the instantiation of a smart contract.
7
8
  * This class extends the base `DedotError` and includes a `raw` property of type `ContractInstantiateResult`.
@@ -66,6 +67,10 @@ class ContractInstantiateLangError extends ContractInstantiateError {
66
67
  * The language-specific error that occurred during the instantiation.
67
68
  */
68
69
  langError;
70
+ /**
71
+ * Decoded `ReturnFlags` from contract call result.
72
+ */
73
+ flags;
69
74
  /**
70
75
  * Constructs a new `ContractInstantiateLangError` instance.
71
76
  *
@@ -73,8 +78,10 @@ class ContractInstantiateLangError extends ContractInstantiateError {
73
78
  * @param raw - The raw result of the contract instantiation.
74
79
  */
75
80
  constructor(err, raw) {
81
+ (0, utils_1.assert)(raw.result.isOk, 'Should not throw DispatchError!');
76
82
  super(raw);
77
83
  this.langError = err;
84
+ this.flags = (0, utils_js_1.toReturnFlags)(raw.result.value.result.flags.bits);
78
85
  }
79
86
  }
80
87
  exports.ContractInstantiateLangError = ContractInstantiateLangError;
@@ -142,6 +149,10 @@ class ContractLangError extends ContractExecutionError {
142
149
  * The language-specific error that occurred during the execution.
143
150
  */
144
151
  langError;
152
+ /**
153
+ * Decoded `ReturnFlags` from contract call result.
154
+ */
155
+ flags;
145
156
  /**
146
157
  * Constructs a new `ContractLangError` instance.
147
158
  *
@@ -149,8 +160,10 @@ class ContractLangError extends ContractExecutionError {
149
160
  * @param raw - The raw result of the contract call.
150
161
  */
151
162
  constructor(err, raw) {
163
+ (0, utils_1.assert)(raw.result.isOk, 'Should not throw DispatchError!');
152
164
  super(raw);
153
165
  this.langError = err;
166
+ this.flags = (0, utils_js_1.toReturnFlags)(raw.result.value.flags.bits);
154
167
  }
155
168
  }
156
169
  exports.ContractLangError = ContractLangError;
@@ -35,10 +35,12 @@ class ConstructorQueryExecutor extends Executor_js_1.Executor {
35
35
  if (data.isErr) {
36
36
  throw new errors_js_1.ContractInstantiateLangError(data.err, raw);
37
37
  }
38
+ const bits = raw.result.value.result.flags.bits;
38
39
  return {
39
- raw,
40
40
  data: data.value,
41
+ raw,
41
42
  address: raw.result.value.accountId,
43
+ flags: (0, utils_js_1.toReturnFlags)(bits),
42
44
  };
43
45
  };
44
46
  callFn.meta = meta;
@@ -1,26 +1,51 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EventExecutor = void 0;
4
- const Executor_js_1 = require("./Executor.js");
4
+ const api_1 = require("@dedot/api");
5
5
  const utils_1 = require("@dedot/utils");
6
+ const Executor_js_1 = require("./Executor.js");
6
7
  class EventExecutor extends Executor_js_1.Executor {
7
8
  doExecute(eventName) {
8
- const eventMeta = this.#findEventMeta(eventName);
9
- (0, utils_1.assert)(eventMeta, "Contract event metadata not found!");
9
+ const meta = this.#findEventMeta(eventName);
10
+ (0, utils_1.assert)(meta, 'Contract event metadata not found!');
10
11
  const is = (event) => {
12
+ if ((0, api_1.isEventRecord)(event)) {
13
+ try {
14
+ event = this.registry.decodeEvent(event);
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ }
11
20
  return event.name === eventName;
12
21
  };
13
- const as = (event) => {
14
- return is(event) ? event : undefined;
22
+ const find = (events) => {
23
+ if (!events || events.length === 0)
24
+ return undefined;
25
+ if ((0, api_1.isEventRecord)(events[0])) {
26
+ return this.registry.decodeEvents(events).find(is);
27
+ }
28
+ else {
29
+ return events.find(is);
30
+ }
31
+ };
32
+ const filter = (events) => {
33
+ if ((0, api_1.isEventRecord)(events[0])) {
34
+ return this.registry.decodeEvents(events).filter(is);
35
+ }
36
+ else {
37
+ return events.filter(is);
38
+ }
15
39
  };
16
40
  return {
17
41
  is,
18
- as,
19
- meta: eventMeta,
42
+ find,
43
+ filter,
44
+ meta,
20
45
  };
21
46
  }
22
47
  #findEventMeta(eventName) {
23
- return this.registry.metadata.spec.events.find(one => (0, utils_1.stringPascalCase)(one.label) === eventName);
48
+ return this.registry.metadata.spec.events.find((one) => (0, utils_1.stringPascalCase)(one.label) === eventName);
24
49
  }
25
50
  }
26
51
  exports.EventExecutor = EventExecutor;
@@ -25,9 +25,11 @@ class QueryExecutor extends Executor_js_1.Executor {
25
25
  if (data.isErr) {
26
26
  throw new errors_js_1.ContractLangError(data.err, raw);
27
27
  }
28
+ const bits = raw.result.value.flags.bits;
28
29
  return {
29
30
  data: data.value,
30
31
  raw,
32
+ flags: (0, utils_js_1.toReturnFlags)(bits),
31
33
  };
32
34
  };
33
35
  callFn.meta = meta;
package/cjs/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeLabel = exports.ensureSupportContractsPallet = exports.newProxyChain = exports.parseRawMetadata = exports.normalizeContractTypeDef = exports.extractContractTypes = void 0;
3
+ exports.toReturnFlags = exports.normalizeLabel = exports.ensureSupportContractsPallet = exports.newProxyChain = exports.parseRawMetadata = exports.normalizeContractTypeDef = exports.extractContractTypes = void 0;
4
4
  const utils_1 = require("@dedot/utils");
5
5
  const extractContractTypes = (contractMetadata) => {
6
6
  const { types } = contractMetadata;
@@ -106,3 +106,12 @@ function normalizeLabel(label) {
106
106
  return (0, utils_1.stringCamelCase)(label.replaceAll('::', '_'));
107
107
  }
108
108
  exports.normalizeLabel = normalizeLabel;
109
+ // https://github.com/paritytech/polkadot-sdk/blob/d2fd53645654d3b8e12cbf735b67b93078d70113/substrate/frame/contracts/uapi/src/flags.rs#L23-L26
110
+ const REVERT_FLAG = 1;
111
+ function toReturnFlags(bits) {
112
+ return {
113
+ bits,
114
+ revert: bits === REVERT_FLAG,
115
+ };
116
+ }
117
+ exports.toReturnFlags = toReturnFlags;
package/errors.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DispatchError } from '@dedot/codecs';
2
2
  import { DedotError } from '@dedot/utils';
3
- import { ContractCallResult, ContractInstantiateResult, GenericContractApi } from './types';
3
+ import { ContractCallResult, ContractInstantiateResult, GenericContractApi, ReturnFlags } from './types/index.js';
4
4
  /**
5
5
  * Represents an error that occurred during the instantiation of a smart contract.
6
6
  * This class extends the base `DedotError` and includes a `raw` property of type `ContractInstantiateResult`.
@@ -57,6 +57,10 @@ export declare class ContractInstantiateLangError<ContractApi extends GenericCon
57
57
  * The language-specific error that occurred during the instantiation.
58
58
  */
59
59
  langError: ContractApi['types']['LangError'];
60
+ /**
61
+ * Decoded `ReturnFlags` from contract call result.
62
+ */
63
+ flags: ReturnFlags;
60
64
  /**
61
65
  * Constructs a new `ContractInstantiateLangError` instance.
62
66
  *
@@ -121,6 +125,10 @@ export declare class ContractLangError<ContractApi extends GenericContractApi =
121
125
  * The language-specific error that occurred during the execution.
122
126
  */
123
127
  langError: ContractApi['types']['LangError'];
128
+ /**
129
+ * Decoded `ReturnFlags` from contract call result.
130
+ */
131
+ flags: ReturnFlags;
124
132
  /**
125
133
  * Constructs a new `ContractLangError` instance.
126
134
  *
package/errors.js CHANGED
@@ -1,4 +1,5 @@
1
- import { DedotError } from '@dedot/utils';
1
+ import { DedotError, assert } from '@dedot/utils';
2
+ import { toReturnFlags } from './utils.js';
2
3
  /**
3
4
  * Represents an error that occurred during the instantiation of a smart contract.
4
5
  * This class extends the base `DedotError` and includes a `raw` property of type `ContractInstantiateResult`.
@@ -61,6 +62,10 @@ export class ContractInstantiateLangError extends ContractInstantiateError {
61
62
  * The language-specific error that occurred during the instantiation.
62
63
  */
63
64
  langError;
65
+ /**
66
+ * Decoded `ReturnFlags` from contract call result.
67
+ */
68
+ flags;
64
69
  /**
65
70
  * Constructs a new `ContractInstantiateLangError` instance.
66
71
  *
@@ -68,8 +73,10 @@ export class ContractInstantiateLangError extends ContractInstantiateError {
68
73
  * @param raw - The raw result of the contract instantiation.
69
74
  */
70
75
  constructor(err, raw) {
76
+ assert(raw.result.isOk, 'Should not throw DispatchError!');
71
77
  super(raw);
72
78
  this.langError = err;
79
+ this.flags = toReturnFlags(raw.result.value.result.flags.bits);
73
80
  }
74
81
  }
75
82
  /**
@@ -134,6 +141,10 @@ export class ContractLangError extends ContractExecutionError {
134
141
  * The language-specific error that occurred during the execution.
135
142
  */
136
143
  langError;
144
+ /**
145
+ * Decoded `ReturnFlags` from contract call result.
146
+ */
147
+ flags;
137
148
  /**
138
149
  * Constructs a new `ContractLangError` instance.
139
150
  *
@@ -141,8 +152,10 @@ export class ContractLangError extends ContractExecutionError {
141
152
  * @param raw - The raw result of the contract call.
142
153
  */
143
154
  constructor(err, raw) {
155
+ assert(raw.result.isOk, 'Should not throw DispatchError!');
144
156
  super(raw);
145
157
  this.langError = err;
158
+ this.flags = toReturnFlags(raw.result.value.flags.bits);
146
159
  }
147
160
  }
148
161
  /**
@@ -1,6 +1,6 @@
1
1
  import { assert, concatU8a, hexToU8a, isWasm, u8aToHex } from '@dedot/utils';
2
2
  import { ContractInstantiateDispatchError, ContractInstantiateLangError } from '../errors.js';
3
- import { normalizeLabel } from '../utils.js';
3
+ import { normalizeLabel, toReturnFlags } from '../utils.js';
4
4
  import { Executor } from './Executor.js';
5
5
  export class ConstructorQueryExecutor extends Executor {
6
6
  code;
@@ -32,10 +32,12 @@ export class ConstructorQueryExecutor extends Executor {
32
32
  if (data.isErr) {
33
33
  throw new ContractInstantiateLangError(data.err, raw);
34
34
  }
35
+ const bits = raw.result.value.result.flags.bits;
35
36
  return {
36
- raw,
37
37
  data: data.value,
38
+ raw,
38
39
  address: raw.result.value.accountId,
40
+ flags: toReturnFlags(bits),
39
41
  };
40
42
  };
41
43
  callFn.meta = meta;
@@ -1,6 +1,6 @@
1
- import { GenericSubstrateApi } from "@dedot/types";
2
- import { Executor } from "./Executor.js";
3
- import { GenericContractEvent } from "../types/index.js";
1
+ import { GenericSubstrateApi } from '@dedot/types';
2
+ import { GenericContractEvent } from '../types/index.js';
3
+ import { Executor } from './Executor.js';
4
4
  export declare class EventExecutor<ChainApi extends GenericSubstrateApi> extends Executor<ChainApi> {
5
5
  #private;
6
6
  doExecute(eventName: string): GenericContractEvent;
@@ -1,22 +1,47 @@
1
- import { Executor } from "./Executor.js";
2
- import { assert, stringPascalCase } from "@dedot/utils";
1
+ import { isEventRecord } from '@dedot/api';
2
+ import { assert, stringPascalCase } from '@dedot/utils';
3
+ import { Executor } from './Executor.js';
3
4
  export class EventExecutor extends Executor {
4
5
  doExecute(eventName) {
5
- const eventMeta = this.#findEventMeta(eventName);
6
- assert(eventMeta, "Contract event metadata not found!");
6
+ const meta = this.#findEventMeta(eventName);
7
+ assert(meta, 'Contract event metadata not found!');
7
8
  const is = (event) => {
9
+ if (isEventRecord(event)) {
10
+ try {
11
+ event = this.registry.decodeEvent(event);
12
+ }
13
+ catch {
14
+ return false;
15
+ }
16
+ }
8
17
  return event.name === eventName;
9
18
  };
10
- const as = (event) => {
11
- return is(event) ? event : undefined;
19
+ const find = (events) => {
20
+ if (!events || events.length === 0)
21
+ return undefined;
22
+ if (isEventRecord(events[0])) {
23
+ return this.registry.decodeEvents(events).find(is);
24
+ }
25
+ else {
26
+ return events.find(is);
27
+ }
28
+ };
29
+ const filter = (events) => {
30
+ if (isEventRecord(events[0])) {
31
+ return this.registry.decodeEvents(events).filter(is);
32
+ }
33
+ else {
34
+ return events.filter(is);
35
+ }
12
36
  };
13
37
  return {
14
38
  is,
15
- as,
16
- meta: eventMeta,
39
+ find,
40
+ filter,
41
+ meta,
17
42
  };
18
43
  }
19
44
  #findEventMeta(eventName) {
20
- return this.registry.metadata.spec.events.find(one => stringPascalCase(one.label) === eventName);
45
+ return this.registry.metadata.spec.events.find((one) => stringPascalCase(one.label) === eventName);
21
46
  }
22
47
  }
@@ -1,6 +1,6 @@
1
1
  import { assert, concatU8a, hexToU8a, u8aToHex } from '@dedot/utils';
2
2
  import { ContractDispatchError, ContractLangError } from '../errors.js';
3
- import { normalizeLabel } from '../utils.js';
3
+ import { normalizeLabel, toReturnFlags } from '../utils.js';
4
4
  import { Executor } from './Executor.js';
5
5
  export class QueryExecutor extends Executor {
6
6
  doExecute(message) {
@@ -22,9 +22,11 @@ export class QueryExecutor extends Executor {
22
22
  if (data.isErr) {
23
23
  throw new ContractLangError(data.err, raw);
24
24
  }
25
+ const bits = raw.result.value.flags.bits;
25
26
  return {
26
27
  data: data.value,
27
28
  raw,
29
+ flags: toReturnFlags(bits),
28
30
  };
29
31
  };
30
32
  callFn.meta = meta;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/contracts",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Delightful ink! Contract APIs",
5
5
  "author": "Tung Vu <tung@coongcrafts.io>",
6
6
  "homepage": "https://github.com/dedotdev/dedot/tree/main/packages/contracts",
@@ -18,17 +18,17 @@
18
18
  "test": "vitest --watch=false"
19
19
  },
20
20
  "dependencies": {
21
- "@dedot/api": "0.2.0",
22
- "@dedot/codecs": "0.2.0",
23
- "@dedot/types": "0.2.0",
24
- "@dedot/utils": "0.2.0"
21
+ "@dedot/api": "0.3.0",
22
+ "@dedot/codecs": "0.3.0",
23
+ "@dedot/types": "0.3.0",
24
+ "@dedot/utils": "0.3.0"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public",
28
28
  "directory": "dist"
29
29
  },
30
30
  "license": "Apache-2.0",
31
- "gitHead": "f29e8784997251518df1e33ef782f1d87207b126",
31
+ "gitHead": "40d0f3c7eee292b7615649e6a5d54887bee75fe2",
32
32
  "module": "./index.js",
33
33
  "types": "./index.d.ts",
34
34
  "exports": {
package/types/index.d.ts CHANGED
@@ -1,20 +1,27 @@
1
1
  import { SubstrateApi } from '@dedot/api/chaintypes';
2
2
  import { AccountId32, AccountId32Like, BytesLike, Weight } from '@dedot/codecs';
3
- import { AnyFunc, AsyncMethod, GenericSubstrateApi, RpcVersion, VersionedGenericSubstrateApi } from '@dedot/types';
3
+ import { AnyFunc, AsyncMethod, GenericSubstrateApi, IEventRecord, RpcVersion, VersionedGenericSubstrateApi } from '@dedot/types';
4
4
  import { ContractCallMessage, ContractConstructorMessage } from './shared.js';
5
5
  import { ContractEventV4, ContractMetadataV4 } from './v4.js';
6
6
  import { ContractEventV5, ContractMetadataV5 } from './v5.js';
7
7
  export * from './shared.js';
8
8
  export type ContractEventMeta = ContractEventV4 | ContractEventV5;
9
- export type GenericContractCallResult<DecodedData = any, ContractResult = any> = {
10
- data: DecodedData;
11
- raw: ContractResult;
9
+ /**
10
+ * Flags used by a contract to customize exit behaviour.
11
+ * Ref: https://github.com/paritytech/polkadot-sdk/blob/d2fd53645654d3b8e12cbf735b67b93078d70113/substrate/frame/contracts/uapi/src/flags.rs#L23-L26
12
+ */
13
+ export type ReturnFlags = {
14
+ bits: number;
15
+ revert: boolean;
12
16
  };
13
- export type GenericConstructorCallResult<DecodedData = any, ContractResult = any> = {
17
+ export interface GenericContractCallResult<DecodedData = any, ContractResult = any> {
14
18
  data: DecodedData;
15
19
  raw: ContractResult;
20
+ flags: ReturnFlags;
21
+ }
22
+ export interface GenericConstructorCallResult<DecodedData = any, ContractResult = any> extends GenericContractCallResult<DecodedData, ContractResult> {
16
23
  address: AccountId32;
17
- };
24
+ }
18
25
  export type ContractCallResult<ChainApi extends GenericSubstrateApi> = Awaited<ReturnType<ChainApi['call']['contractsApi']['call']>>;
19
26
  export type ContractInstantiateResult<ChainApi extends GenericSubstrateApi> = Awaited<ReturnType<ChainApi['call']['contractsApi']['instantiate']>>;
20
27
  export type ContractSubmittableExtrinsic<ChainApi extends GenericSubstrateApi> = ReturnType<ChainApi['tx']['contracts']['call']>;
@@ -72,8 +79,9 @@ export type ContractEvent<EventName extends string = string, Data extends any =
72
79
  data: Data;
73
80
  };
74
81
  export interface GenericContractEvent<EventName extends string = string, Data extends any = any> {
75
- is: (event: ContractEvent) => event is ContractEvent<EventName, Data>;
76
- as: (event: ContractEvent) => ContractEvent<EventName, Data> | undefined;
82
+ is: (event: IEventRecord | ContractEvent) => event is ContractEvent<EventName, Data>;
83
+ find: (events: IEventRecord[] | ContractEvent[]) => ContractEvent<EventName, Data> | undefined;
84
+ filter: (events: IEventRecord[] | ContractEvent[]) => ContractEvent<EventName, Data>[];
77
85
  meta: ContractEventMeta;
78
86
  }
79
87
  export interface GenericContractEvents<_ extends GenericSubstrateApi> {
package/utils.d.ts CHANGED
@@ -2,10 +2,11 @@ import { ISubstrateClient } from '@dedot/api';
2
2
  import { PortableType, TypeDef } from '@dedot/codecs';
3
3
  import { GenericSubstrateApi } from '@dedot/types';
4
4
  import { Executor } from './executor/index.js';
5
- import { ContractMetadata, ContractTypeDef } from './types/index.js';
5
+ import { ContractMetadata, ContractTypeDef, ReturnFlags } from './types/index.js';
6
6
  export declare const extractContractTypes: (contractMetadata: ContractMetadata) => PortableType[];
7
7
  export declare const normalizeContractTypeDef: (def: ContractTypeDef) => TypeDef;
8
8
  export declare const parseRawMetadata: (rawMetadata: string) => ContractMetadata;
9
9
  export declare function newProxyChain<ChainApi extends GenericSubstrateApi>(carrier: Executor<ChainApi>): unknown;
10
10
  export declare function ensureSupportContractsPallet<ChainApi extends GenericSubstrateApi>(api: ISubstrateClient<ChainApi>): void;
11
11
  export declare function normalizeLabel(label?: string): string;
12
+ export declare function toReturnFlags(bits: number): ReturnFlags;
package/utils.js CHANGED
@@ -97,3 +97,11 @@ export function normalizeLabel(label) {
97
97
  return '';
98
98
  return stringCamelCase(label.replaceAll('::', '_'));
99
99
  }
100
+ // https://github.com/paritytech/polkadot-sdk/blob/d2fd53645654d3b8e12cbf735b67b93078d70113/substrate/frame/contracts/uapi/src/flags.rs#L23-L26
101
+ const REVERT_FLAG = 1;
102
+ export function toReturnFlags(bits) {
103
+ return {
104
+ bits,
105
+ revert: bits === REVERT_FLAG,
106
+ };
107
+ }