-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Frequency schema names (#46)
* Deploy now uses `dsnp.*` schema names and new versions of add/propose schema extrinsics. * Adds `dsnp.getSchemaId()` and utility types/methods for registering non-standard mappings (see `README.md`). * New `find.ts` CLI script will do a forward lookup of DSNP schema names on chain. cf. frequency-chain/frequency#1784 Updated to use `@frequency-chain/[email protected]`. --------- Co-authored-by: Wes Biggs <[email protected]>
- Loading branch information
Showing
6 changed files
with
1,146 additions
and
1,272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { getFrequencyAPI } from "./services/connect.js"; | ||
import { schemas } from "../dsnp/index.js"; | ||
|
||
const find = async () => { | ||
const api = await getFrequencyAPI(); | ||
|
||
console.log("\n## DSNP Schema Information"); | ||
|
||
const allDsnp = (await api.rpc.schemas.getVersions("dsnp")).unwrap(); | ||
for (const schemaEntry of schemas.entries()) { | ||
const schemaString = JSON.stringify(schemaEntry[1].model); | ||
const schemaVersionResult = allDsnp.filter( | ||
(versioned) => versioned.schema_name.toString() === "dsnp." + schemaEntry[0], | ||
); | ||
for (const version of schemaVersionResult) { | ||
const schemaResult = (await api.rpc.schemas.getBySchemaId(version.schema_id.toString())).unwrap(); | ||
const jsonSchema = Buffer.from(schemaResult.model).toString("utf8"); | ||
const { schema_id, model_type, payload_location, settings } = schemaResult; | ||
|
||
// Ensure that full entry details match, otherwise it's a different version | ||
if ( | ||
schemaString === jsonSchema && | ||
model_type.toHuman() === schemaEntry[1].modelType && | ||
payload_location.toHuman() === schemaEntry[1].payloadLocation && | ||
JSON.stringify(settings.toHuman()) === JSON.stringify(schemaEntry[1].settings) | ||
) { | ||
console.log(`\n## Schema Id ${schema_id}`); | ||
console.table( | ||
Object.entries({ | ||
schemaName: schemaEntry[0], | ||
dsnpVersion: schemaEntry[1].dsnpVersion, | ||
schemaId: schema_id.toHuman(), | ||
}).map(([key, value]) => ({ key, value })), | ||
); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export const main = async () => { | ||
await find(); | ||
}; | ||
|
||
main().catch(console.error).finally(process.exit); |
Oops, something went wrong.