Skip to content

Commit 3cb2227

Browse files
committed
address comments
1 parent 4d3e187 commit 3cb2227

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

src/controllers/transaction/TransactionMetadataBlobController.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,6 @@ import { TransactionMetadataBlobService } from '../../services';
1818
import { IMetadataBlobBody, IPostRequestHandler } from '../../types/requests';
1919
import AbstractController from '../AbstractController';
2020

21-
/**
22-
* Parameters for generating metadata blob proof.
23-
*/
24-
export interface MetadataBlobParams {
25-
/**
26-
* Full encoded extrinsic. Use this OR the individual parts.
27-
*/
28-
tx?: string;
29-
/**
30-
* Optional tx additional signed data.
31-
*/
32-
txAdditionalSigned?: string;
33-
/**
34-
* Call data. Use with includedInExtrinsic and includedInSignedData.
35-
*/
36-
callData?: string;
37-
/**
38-
* Signed Extension data included in the extrinsic.
39-
*/
40-
includedInExtrinsic?: string;
41-
/**
42-
* Signed Extension data included in the signature.
43-
*/
44-
includedInSignedData?: string;
45-
}
46-
4721
/**
4822
* POST metadata blob for a transaction.
4923
*

src/services/transaction/TransactionMetadataBlobService.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ import { ApiDecoration } from '@polkadot/api/types';
1919
import type { BlockHash } from '@polkadot/types/interfaces';
2020
import { u8aToHex } from '@polkadot/util';
2121
import { BadRequest, InternalServerError } from 'http-errors';
22+
import { MetadataBlobParams } from 'src/types/requests';
2223
import { ITransactionMetadataBlob } from 'src/types/responses';
2324

24-
import { MetadataBlobParams } from '../../controllers/transaction/TransactionMetadataBlobController';
2525
import { AbstractService } from '../AbstractService';
2626

27+
const DEFAULT_DECIMALS = 10;
28+
const DEFAULT_SS58_PREFIX = 42;
29+
const DEFAULT_TOKEN_SYMBOL = 'DOT';
30+
2731
// Dynamic import helper that TypeScript won't transform to require()
2832
// This is necessary because @polkadot-api/merkleize-metadata is an ESM-only package
2933
// eslint-disable-next-line @typescript-eslint/no-implied-eval
@@ -89,27 +93,27 @@ export class TransactionMetadataBlobService extends AbstractService {
8993
const tokenSymbolRaw = properties.tokenSymbol.isSome ? properties.tokenSymbol.value : null;
9094
const ss58Format = properties.ss58Format.isSome ? properties.ss58Format.value : null;
9195

92-
let decimals = 10;
96+
let decimals = DEFAULT_DECIMALS;
9397
if (tokenDecimalsRaw) {
9498
const decimalsJson = tokenDecimalsRaw.toJSON();
9599
if (Array.isArray(decimalsJson)) {
96-
decimals = (decimalsJson[0] as number) ?? 10;
100+
decimals = (decimalsJson[0] as number) ?? DEFAULT_DECIMALS;
97101
} else if (typeof decimalsJson === 'number') {
98102
decimals = decimalsJson;
99103
}
100104
}
101105

102-
let tokenSymbol = 'DOT';
106+
let tokenSymbol = DEFAULT_TOKEN_SYMBOL;
103107
if (tokenSymbolRaw) {
104108
const symbolJson = tokenSymbolRaw.toJSON();
105109
if (Array.isArray(symbolJson)) {
106-
tokenSymbol = (symbolJson[0] as string) ?? 'DOT';
110+
tokenSymbol = (symbolJson[0] as string) ?? DEFAULT_TOKEN_SYMBOL;
107111
} else if (typeof symbolJson === 'string') {
108112
tokenSymbol = symbolJson;
109113
}
110114
}
111115

112-
const base58Prefix = ss58Format?.toNumber() ?? 42;
116+
const base58Prefix = ss58Format?.toNumber() ?? DEFAULT_SS58_PREFIX;
113117

114118
// Use dynamic import for ESM module compatibility
115119
const merkleizeMetadata = await this.getMerkleizeMetadata();

src/types/requests.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,32 @@ export interface IMetadataBlobBody {
6060
at?: string;
6161
}
6262

63+
/**
64+
* Parameters for generating metadata blob proof.
65+
*/
66+
export interface MetadataBlobParams {
67+
/**
68+
* Full encoded extrinsic. Use this OR the individual parts.
69+
*/
70+
tx?: string;
71+
/**
72+
* Optional tx additional signed data.
73+
*/
74+
txAdditionalSigned?: string;
75+
/**
76+
* Call data. Use with includedInExtrinsic and includedInSignedData.
77+
*/
78+
callData?: string;
79+
/**
80+
* Signed Extension data included in the extrinsic.
81+
*/
82+
includedInExtrinsic?: string;
83+
/**
84+
* Signed Extension data included in the signature.
85+
*/
86+
includedInSignedData?: string;
87+
}
88+
6389
/**
6490
* Body for the RequestHandlerContract. In other words, the body of the POST route that a message to a contract.
6591
*/

0 commit comments

Comments
 (0)