Extending and composing data schemas
The best blockchain primitives are composable and schemas are no exception. Promoting re-use is a priority
Extension in practice (Example 1)
import { SDK } from "@somnia-chain/streams"
const sdk = new SDK({
public: getPublicClient(),
wallet: getWalletClient(),
})
// The parent schema here will be the GPS schema from the quick start guide
const gpsSchema = `uint64 timestamp, int32 latitude, int32 longitude, int32 altitude, uint32 accuracy, bytes32 entityId, uint256 nonce`
const parentSchemaId = await sdk.streams.computeSchemaId(gpsSchema)
// Lets extend the gps schema and add F1 data since every car will have a gps position
const formulaOneSchema = `uint256 driverNumber`
// We can also extend the gps schema for FR data i.e. aircraft identifier
const flightRadarSchema = `bytes32 ICAO24`
await sdk.streams.registerDataSchemas([
{ schemaName: "gps", schema: gpsSchema },
{ schemaName: "f1", schema: formulaOneSchema, parentSchemaId }, // F1 extends GPS
{ schemaName: "FR", schema: flightRadarSchema, parentSchemaId },// FR extends GPS
])Extension in practice (Example 2)
Last updated