Skip to content

Commit e22e124

Browse files
committed
Resolve conflict
1 parent 3eab899 commit e22e124

File tree

13 files changed

+49
-35
lines changed

13 files changed

+49
-35
lines changed

packages/api/src/executor/ErrorExecutor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ErrorExecutor<ChainApi extends GenericSubstrateApi = GenericSubstra
1414
const errorTypeId = targetPallet.error;
1515
assert(errorTypeId, new UnknownApiError(`Not found error with id ${errorTypeId} in pallet ${pallet}`));
1616

17-
const errorDef = this.#getErrorDef(errorTypeId, errorName);
17+
const errorDef = this.#getErrorDef(errorTypeId.typeId, errorName);
1818

1919
return {
2020
meta: {

packages/api/src/executor/EventExecutor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class EventExecutor<ChainApi extends GenericSubstrateApi = GenericSubstra
1515
const eventTypeId = targetPallet.event;
1616
assert(eventTypeId, new UnknownApiError(`Not found event with id ${eventTypeId} in pallet ${pallet}`));
1717

18-
const eventDef = this.#getEventDef(eventTypeId, eventName);
18+
const eventDef = this.#getEventDef(eventTypeId.typeId, eventName);
1919

2020
const is = (event: IEventRecord | PalletEvent): event is PalletEvent => {
2121
if (isEventRecord(event)) {

packages/api/src/executor/TxExecutor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class TxExecutor<ChainApi extends GenericSubstrateApi = GenericSubstrateA
1515

1616
assert(targetPallet.calls, new UnknownApiError(`Tx calls are not available for pallet ${targetPallet.name}`));
1717

18-
const txType = this.metadata.types[targetPallet.calls]!;
18+
const txType = this.metadata.types[targetPallet.calls.typeId]!;
1919

2020
assert(txType.typeDef.type === 'Enum', new UnknownApiError('Tx type defs should be enum'));
2121

packages/api/src/extrinsic/extensions/ExtraSignedExtension.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { DEFAULT_EXTRINSIC_VERSION, type SignedExtensionDefLatest } from '@dedot/codecs';
12
import * as $ from '@dedot/shape';
23
import { SignerPayloadJSON, SignerPayloadRaw } from '@dedot/types';
34
import { ensurePresence, HexString, u8aToHex } from '@dedot/utils';
4-
import { ISignedExtension, SignedExtension } from './SignedExtension.js';
55
import { FallbackSignedExtension, isEmptyStructOrTuple } from './FallbackSignedExtension.js';
6+
import { ISignedExtension, SignedExtension } from './SignedExtension.js';
67
import { knownSignedExtensions } from './known/index.js';
7-
import type { SignedExtensionDefLatest } from '@dedot/codecs';
88

99
export class ExtraSignedExtension extends SignedExtension<any[], any[]> {
1010
#signedExtensions?: ISignedExtension[];
@@ -23,13 +23,11 @@ export class ExtraSignedExtension extends SignedExtension<any[], any[]> {
2323
}
2424

2525
get $Data(): $.AnyShape {
26-
const { extraTypeId } = this.registry.metadata.extrinsic;
27-
28-
return ensurePresence(this.registry.findCodec(extraTypeId));
26+
return ensurePresence(this.registry.createExtraCodec(DEFAULT_EXTRINSIC_VERSION));
2927
}
3028

3129
get $AdditionalSigned(): $.AnyShape {
32-
const $AdditionalSignedCodecs = this.#signedExtensionDefs.map((se) => this.registry.findCodec(se.additionalSigned));
30+
const $AdditionalSignedCodecs = this.#signedExtensionDefs.map((se) => this.registry.findCodec(se.implicit));
3331

3432
return $.Tuple(...$AdditionalSignedCodecs);
3533
}
@@ -42,16 +40,16 @@ export class ExtraSignedExtension extends SignedExtension<any[], any[]> {
4240
}
4341

4442
get #signedExtensionDefs() {
45-
return this.registry.metadata.extrinsic.signedExtensions;
43+
return this.registry.metadata.extrinsic.transactionExtensions;
4644
}
4745

4846
#getSignedExtensions() {
4947
return this.#signedExtensionDefs.map((extDef) => {
5048
const { signedExtensions: userSignedExtensions = {} } = this.client.options;
5149

5250
const Extension =
53-
userSignedExtensions[extDef.ident as keyof typeof knownSignedExtensions] ||
54-
knownSignedExtensions[extDef.ident as keyof typeof knownSignedExtensions];
51+
userSignedExtensions[extDef.identifier as keyof typeof knownSignedExtensions] ||
52+
knownSignedExtensions[extDef.identifier as keyof typeof knownSignedExtensions];
5553

5654
if (Extension) {
5755
return new Extension(this.client, {
@@ -65,12 +63,12 @@ export class ExtraSignedExtension extends SignedExtension<any[], any[]> {
6563
...ensurePresence(this.options),
6664
def: extDef,
6765
},
68-
extDef.ident
66+
extDef.identifier,
6967
);
7068
}
7169

7270
// For extensions that require input but aren't implemented, throw an error
73-
throw new Error(`SignedExtension for ${extDef.ident} requires input but is not implemented`);
71+
throw new Error(`SignedExtension for ${extDef.identifier} requires input but is not implemented`);
7472
});
7573
}
7674

@@ -80,10 +78,7 @@ export class ExtraSignedExtension extends SignedExtension<any[], any[]> {
8078
* @returns boolean
8179
*/
8280
private isRequireNoExternalInputs(extDef: SignedExtensionDefLatest): boolean {
83-
return (
84-
isEmptyStructOrTuple(this.registry, extDef.typeId) &&
85-
isEmptyStructOrTuple(this.registry, extDef.additionalSigned)
86-
);
81+
return isEmptyStructOrTuple(this.registry, extDef.typeId) && isEmptyStructOrTuple(this.registry, extDef.implicit);
8782
}
8883

8984
toPayload(call: HexString = '0x'): SignerPayloadJSON {

packages/api/src/extrinsic/extensions/SignedExtension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ export abstract class SignedExtension<Data extends any = {}, AdditionalSigned ex
4141
}
4242

4343
get identifier(): string {
44-
return this.signedExtensionDef.ident;
44+
return this.signedExtensionDef.identifier;
4545
}
4646

4747
get $Data(): $.AnyShape {
4848
return ensurePresence(this.registry.findCodec(this.signedExtensionDef.typeId));
4949
}
5050

5151
get $AdditionalSigned(): $.AnyShape {
52-
return ensurePresence(this.registry.findCodec(this.signedExtensionDef.additionalSigned));
52+
return ensurePresence(this.registry.findCodec(this.signedExtensionDef.implicit));
5353
}
5454

5555
get registry() {

packages/codecs/src/codecs/extrinsic/Extrinsic.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import { $ExtrinsicVersion } from './ExtrinsicVersion.js';
77
// TODO extrinsic versioning
88
export class Extrinsic<A = any, C = any, S = any, E = any> extends ExtrinsicV4<A, C, S, E> {}
99
export interface ExtrinsicSignature<A = any, S = any, E = any> extends ExtrinsicSignatureV4<A, S, E> {}
10+
export const DEFAULT_EXTRINSIC_VERSION = 4;
1011

1112
export const $Extrinsic = (registry: PortableRegistry) => {
1213
assert(registry, 'PortableRegistry is required to compose $Extrinsic codec');
1314

14-
const { callTypeId, addressTypeId, signatureTypeId, extraTypeId } = registry.metadata!.extrinsic;
15+
const { callTypeId, addressTypeId, signatureTypeId } = registry.metadata!.extrinsic;
1516

1617
const $Address = registry.findCodec(addressTypeId) as $.Shape<any>;
1718
const $Signature = registry.findCodec(signatureTypeId) as $.Shape<any>;
18-
const $Extra = registry.findCodec(extraTypeId) as $.Shape<any>;
19+
const $Extra = registry.createExtraCodec(DEFAULT_EXTRINSIC_VERSION) as $.Shape<any>;
1920
const $RuntimeCall = registry.findCodec(callTypeId) as $.Shape<any>;
2021

2122
const $ExtrinsicSignature: $.Shape<ExtrinsicSignature> = $.Struct({

packages/codecs/src/codecs/metadata/Metadata.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { $MetadataV15 } from './v15.js';
77
import {
88
$PalletDefV16,
99
$RuntimeApiMethodDefV16,
10-
$SignedExtensionDefV16,
1110
$StorageEntryV16,
11+
$TransactionExtensionDefV16,
1212
PalletDefV16,
13-
SignedExtensionDefV16,
1413
RuntimeApiMethodDefV16,
1514
StorageEntryV16,
15+
TransactionExtensionDefV16,
1616
} from './v16.js';
1717
import { $MetadataV16, MetadataV16 } from './v16.js';
1818

@@ -65,8 +65,8 @@ export type PalletDefLatest = PalletDefV16;
6565
export const $StorageEntryLatest = $StorageEntryV16;
6666
export type StorageEntryLatest = StorageEntryV16;
6767

68-
export const $SignedExtensionDefLatest = $SignedExtensionDefV16;
69-
export type SignedExtensionDefLatest = SignedExtensionDefV16;
68+
export const $SignedExtensionDefLatest = $TransactionExtensionDefV16;
69+
export type SignedExtensionDefLatest = TransactionExtensionDefV16;
7070

7171
export const $RuntimeApiMethodDefLatest = $RuntimeApiMethodDefV16;
7272
export type RuntimeApiMethodDefLatest = RuntimeApiMethodDefV16;

packages/codecs/src/codecs/metadata/v16.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ export const $PalletDefV16 = $.Struct({
112112

113113
export type PalletDefV16 = $.Input<typeof $PalletDefV16>;
114114

115-
export const $SignedExtensionDefV16 = $SignedExtensionDefV14;
116-
export type SignedExtensionDefV16 = $.Input<typeof $SignedExtensionDefV16>;
117-
118115
export const $TransactionExtensionDefV16 = $.Struct({
119116
identifier: $.str,
120117
typeId: $TypeId,

packages/codecs/src/registry/PortableRegistry.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EnumOptions } from '@dedot/shape';
1+
import { EnumOptions, Tuple } from '@dedot/shape';
22
import { blake2_256, HashFn, HexString, hexToU8a, isObject, isU8a, u8aToHex } from '@dedot/utils';
33
import {
44
$Extrinsic,
@@ -28,6 +28,27 @@ export class PortableRegistry extends TypeRegistry {
2828
return $Extrinsic(this);
2929
}
3030

31+
createExtraCodec(transactionVersion: number) {
32+
const { transactionExtensions, transactionExtensionsByVersion, version } = this.metadata.extrinsic;
33+
34+
const transactionVersionIndex = version.findIndex((v) => v === transactionVersion);
35+
36+
if (transactionVersionIndex < 0) {
37+
throw new Error(`Invalid transaction version: ${transactionVersion}`);
38+
}
39+
40+
const transactionExtensionIndexes = transactionExtensionsByVersion.get(transactionVersionIndex);
41+
42+
if (!transactionExtensionIndexes) {
43+
throw new Error(`No transaction extensions found for version ${transactionVersion}`);
44+
}
45+
46+
const transactionExtensionsVersioned = transactionExtensionIndexes.map((index) => transactionExtensions[index]);
47+
const extraCodecs = transactionExtensionsVersioned.map(({ typeId }) => this.findCodec(typeId));
48+
49+
return Tuple(...extraCodecs);
50+
}
51+
3152
get metadata(): MetadataLatest {
3253
return this.#metadata;
3354
}

packages/codegen/src/chaintypes/generator/ErrorsGen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class ErrorsGen extends ApiGen {
1616
continue;
1717
}
1818

19-
const errorDefs = this.#getErrorDefs(errorTypeId);
19+
const errorDefs = this.#getErrorDefs(errorTypeId.typeId);
2020

2121
defTypeOut += commentBlock(`Pallet \`${pallet.name}\`'s errors`);
2222
defTypeOut += `${stringCamelCase(pallet.name)}: {

0 commit comments

Comments
 (0)