Skip to content

Commit a28ca1a

Browse files
authored
Remove dependencies (#59)
Reduced the non-dev dependencies by changing `getSchemaId` to take the genesis hash instead of an `ApiPromise` Problem ======= Keeping the Polkadot/api libraries in version sync is difficult and issues arise with dependencies in typescript with the additional requirement that `@frequency-chain/api-augment` versions align. Solution ======== Removed the dependency need.
1 parent bfc36da commit a28ca1a

File tree

4 files changed

+185
-124
lines changed

4 files changed

+185
-124
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { dsnp } from "@dsnp/frequency-schemas";
2424
import { ApiPromise } from "@polkadot/api";
2525

2626
const api = ApiPromise.create(/* ... */);
27-
console.log(await dsnp.getSchemaId(api, "broadcast"));
27+
console.log(dsnp.getSchemaId("broadcast", "1.3", api.genesisHash.toString()));
2828
```
2929

3030
The API connection is used only to identify the chain by its genesis hash.
@@ -40,7 +40,7 @@ dsnp.setSchemaMapping(api.genesisHash.toString(), {
4040
// ...
4141
});
4242
43-
console.log(await dsnp.getSchemaId(api, "broadcast")); // yields 67
43+
console.log(dsnp.getSchemaId("broadcast", "1.2", api.genesisHash.toString())); // yields 67
4444
```
4545

4646
### With Parquet Writer

dsnp/index.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { ApiPromise } from "@polkadot/api";
2-
31
import type { Schema } from "avsc";
42
import { DSNPParquetSchema } from "@dsnp/schemas/types/dsnp-parquet.js";
53
import {
@@ -283,19 +281,14 @@ chainMapping["default"] = {
283281
};
284282

285283
/**
286-
* Gets the schemaId from the Frequency instance configured for
287-
* apiPromise for the given DSNP type and version. If version is
288-
* unspecified, the latest version is returned. (You probably only
289-
* need version if you're migrating.)
284+
* Gets the schemaId for for given DSNP type and version and genesis hash.
285+
* If version is unspecified, the latest version is returned. (You probably
286+
* only need version if you're migrating.)
287+
* If genesis hash is unspecified, the mainnet genesis hash and schema
288+
* numbers will be used.
290289
*/
291-
export const getSchemaId = async (
292-
apiPromise: Promise<ApiPromise>,
293-
schemaName: SchemaName,
294-
dsnpVersion?: DSNPVersion,
295-
): Promise<number> => {
296-
const api = await apiPromise;
297-
const genesisHash = api.genesisHash.toString();
298-
let mapping = chainMapping[genesisHash];
290+
export const getSchemaId = (schemaName: SchemaName, dsnpVersion?: DSNPVersion, genesisHash?: string): number => {
291+
let mapping = chainMapping[genesisHash || GENESIS_HASH_MAINNET];
299292
// If we don't recognize this chain, use default mapping
300293
if (!mapping) mapping = chainMapping["default"];
301294
const versions = mapping[schemaName];

0 commit comments

Comments
 (0)