From dcd23053317af26daf4740bfce2e8b757a6118b6 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Thu, 22 Dec 2022 13:38:31 -0800 Subject: [PATCH] chore: reorganize frame metadata (#480) --- _tasks/download_frame_metadata.ts | 32 +- codegen/codecs.test.ts | 4 +- codegen/genCodecs.ts | 8 +- codegen/genMetadata.ts | 13 +- codegen/server/server.ts | 4 +- codegen/typeVisitor.ts | 22 +- codegen/utils.ts | 4 +- effects/contracts/call.ts | 38 +- effects/contracts/events.ts | 40 +- effects/contracts/instantiate.ts | 8 +- effects/extrinsic.ts | 17 +- effects/scale.ts | 14 +- examples/smart_contract.ts | 2 +- fluent/Contract.ts | 11 +- fluent/mod.ts | 4 +- frame_metadata/Codec.test.ts | 106 - frame_metadata/Contract.ts | 346 - frame_metadata/Extrinsic.ts | 21 +- frame_metadata/Key.test.ts | 33 +- frame_metadata/Key.ts | 12 +- frame_metadata/Metadata.test.ts | 26 +- frame_metadata/Metadata.ts | 2 +- .../__snapshots__/Metadata.test.ts.snap | 264445 ++++++++------- frame_metadata/_downloaded/mod.ts | 29 + frame_metadata/mod.ts | 6 - frame_metadata/test-common.ts | 26 - ink_metadata/Metadata.ts | 92 + .../_downloaded/erc20.json | 2 +- ink_metadata/known.ts | 162 + ink_metadata/mod.ts | 3 + ink_metadata/normalizeTys.ts | 83 + mod.ts | 24 +- .../MultiAddress.ts | 42 +- primitives/MultiSignature.ts | 41 + primitives/Signer.ts | 9 + primitives/mod.ts | 3 + scale_info/Codec.test.ts | 99 + {frame_metadata => scale_info}/Codec.ts | 8 +- .../scale_info.ts => scale_info/Ty.ts | 0 {frame_metadata => scale_info}/TyVisitor.ts | 2 +- scale_info/mod.ts | 4 + .../overrides}/Era.ts | 10 +- scale_info/overrides/mod.ts | 1 + test_util/extrinsic.ts | 4 +- util/{sr25519.ts => Sr25519.ts} | 2 +- util/mod.ts | 2 +- words.txt | 1 + 47 files changed, 146117 insertions(+), 119750 deletions(-) delete mode 100644 frame_metadata/Codec.test.ts delete mode 100644 frame_metadata/Contract.ts create mode 100644 frame_metadata/_downloaded/mod.ts delete mode 100644 frame_metadata/test-common.ts create mode 100644 ink_metadata/Metadata.ts rename frame_metadata/raw_erc20_metadata.json => ink_metadata/_downloaded/erc20.json (99%) create mode 100644 ink_metadata/known.ts create mode 100644 ink_metadata/mod.ts create mode 100644 ink_metadata/normalizeTys.ts rename frame_metadata/primitives.ts => primitives/MultiAddress.ts (59%) create mode 100644 primitives/MultiSignature.ts create mode 100644 primitives/Signer.ts create mode 100644 primitives/mod.ts create mode 100644 scale_info/Codec.test.ts rename {frame_metadata => scale_info}/Codec.ts (94%) rename frame_metadata/scale_info.ts => scale_info/Ty.ts (100%) rename {frame_metadata => scale_info}/TyVisitor.ts (99%) create mode 100644 scale_info/mod.ts rename {frame_metadata => scale_info/overrides}/Era.ts (92%) create mode 100644 scale_info/overrides/mod.ts rename util/{sr25519.ts => Sr25519.ts} (92%) diff --git a/_tasks/download_frame_metadata.ts b/_tasks/download_frame_metadata.ts index 327951249..1ba92c935 100755 --- a/_tasks/download_frame_metadata.ts +++ b/_tasks/download_frame_metadata.ts @@ -1,11 +1,33 @@ -import * as fs from "../deps/std/fs.ts" -import * as path from "../deps/std/path.ts" import * as Z from "../deps/zones.ts" import * as C from "../mod.ts" import * as U from "../util/mod.ts" -const outDir = path.join(Deno.cwd(), "frame_metadata", "_downloaded") -await fs.emptyDir(outDir) +const names = Object.keys(C.knownClients) +const outDir = new URL("../frame_metadata/_downloaded", import.meta.url) +try { + Deno.removeSync(outDir, { recursive: true }) +} catch (_e) {} +Deno.mkdirSync(outDir) + +const modFilePath = new URL("_downloaded/mod.ts", outDir) +const modFileContents = `// This file was generated by \`_tasks/download_frame_metadata.ts\` +import * as U from "../../util/mod.ts" +import { $metadata } from "../mod.ts" + +export const [ + ${names.join(",\n ")}, +] = await Promise.all([ + ${names.map((name) => `download("${name}")`).join(",\n ")}, +]) + +async function download(name: string) { + return $metadata.decode( + U.hex.decodeBuf((await Deno.readFile(new URL(\`./$\{name}.scale\`, import.meta.url))).slice(2)), + ) +} +` +Deno.writeTextFileSync(modFilePath, modFileContents, { create: true }) + U.throwIfError(await Z.ls(...Object.entries(C.knownClients).map(download)).run()) function download, Client extends Z.$>( @@ -14,7 +36,7 @@ function download, Client extends Z.$>( return Z.ls(...entry).next(async ([name, client]) => { try { const metadataHex = U.throwIfError(await C.state.getMetadata(client)().run()) - const outPath = path.join(outDir, `${name}.scale`) + const outPath = new URL(`_downloaded/${name}.scale`, outDir) console.log(`Downloading ${name} metadata to "${outPath}".`) await Deno.writeTextFile(outPath, metadataHex) return diff --git a/codegen/codecs.test.ts b/codegen/codecs.test.ts index 20f99048a..1436a32af 100644 --- a/codegen/codecs.test.ts +++ b/codegen/codecs.test.ts @@ -1,6 +1,6 @@ import { Codec } from "../deps/scale.ts" import { assertEquals } from "../deps/std/testing/asserts.ts" -import * as M from "../frame_metadata/mod.ts" +import { DeriveCodec } from "../scale_info/mod.ts" import * as testClients from "../test_util/clients/mod.ts" import { InMemoryCache } from "./server/cache.ts" import { LocalCapiCodegenServer } from "./server/local.ts" @@ -21,7 +21,7 @@ for (const runtime of Object.keys(testClients)) { `http://localhost:${port!}/@local/proxy/${chainUrl}/@${version}/codecs.ts` ) server.abortController.abort() - const deriveCodec = M.DeriveCodec(metadata.tys) + const deriveCodec = DeriveCodec(metadata.tys) const derivedCodecs = metadata.tys.map(deriveCodec) const codegenCodecs = codegened._all const origInspect = Codec.prototype["_inspect"]! diff --git a/codegen/genCodecs.ts b/codegen/genCodecs.ts index f1f3dafe1..83f806ac3 100644 --- a/codegen/genCodecs.ts +++ b/codegen/genCodecs.ts @@ -1,9 +1,9 @@ -import * as M from "../frame_metadata/mod.ts" +import { Ty, TyVisitor } from "../scale_info/mod.ts" import { normalizeCase } from "../util/case.ts" import { CodegenProps } from "./mod.ts" import { S } from "./utils.ts" -export function genCodecs(props: CodegenProps, typeVisitor: M.TyVisitor) { +export function genCodecs(props: CodegenProps, typeVisitor: TyVisitor) { const { tys } = props.metadata const namespaceImports = new Set() @@ -13,7 +13,7 @@ import type * as types from "./types/mod.ts" ` - const visitor = new M.TyVisitor(tys, { + const visitor = new TyVisitor(tys, { unitStruct(ty) { return addCodecDecl(ty, "C.$null") }, @@ -141,7 +141,7 @@ import type * as types from "./types/mod.ts" return file - function addCodecDecl(ty: M.Ty, value: string) { + function addCodecDecl(ty: Ty, value: string) { if (ty.path.length > 1) { namespaceImports.add(ty.path[0]!) } diff --git a/codegen/genMetadata.ts b/codegen/genMetadata.ts index 1b232e734..294cf2cf1 100644 --- a/codegen/genMetadata.ts +++ b/codegen/genMetadata.ts @@ -1,17 +1,18 @@ -import * as M from "../frame_metadata/mod.ts" +import { Metadata } from "../frame_metadata/mod.ts" import { hex } from "../mod.ts" +import { Ty, TyVisitor, UnionTyDef } from "../scale_info/mod.ts" import { normalizeCase } from "../util/case.ts" import { Files } from "./Files.ts" import { getRawCodecPath, makeDocComment, S } from "./utils.ts" export function genMetadata( - metadata: M.Metadata, - typeVisitor: M.TyVisitor, + metadata: Metadata, + typeVisitor: TyVisitor, files: Files, ) { const { tys, extrinsic, pallets } = metadata - const isUnitVisitor = new M.TyVisitor(tys, { + const isUnitVisitor = new TyVisitor(tys, { unitStruct: () => true, wrapperStruct(_, inner) { return this.visit(inner) @@ -68,7 +69,7 @@ import { $, C, client } from "../capi.ts" ) } if (pallet.calls) { - const ty = pallet.calls as M.Ty & M.UnionTyDef + const ty = pallet.calls as Ty & UnionTyDef const isStringUnion = ty.members.every((x) => !x.fields.length) for (const call of ty.members) { const type = normalizeCase(call.name) @@ -130,7 +131,7 @@ const _extrinsic = ${ export const extrinsic = C.extrinsic(client); `) - function getExtrasCodec(xs: [string, M.Ty][]) { + function getExtrasCodec(xs: [string, Ty][]) { return S.array( xs.filter((x) => !isUnitVisitor.visit(x[1])).map((x) => getRawCodecPath(x[1])), ) diff --git a/codegen/server/server.ts b/codegen/server/server.ts index 83c070b68..eb30dbdbe 100644 --- a/codegen/server/server.ts +++ b/codegen/server/server.ts @@ -139,7 +139,7 @@ export abstract class CodegenServer { )) } - filesMemo = new Map() + filesMemo = new Map() async files(chainUrl: string, version: string, chainVersion: string) { const metadata = await this.metadata(chainUrl, chainVersion) return U.getOrInit(this.filesMemo, metadata, () => { @@ -415,7 +415,7 @@ export const client = C.rpcClient(C.rpc.proxyProvider, ${JSON.stringify(chainUrl } metadata(chainUrl: string, version: string) { - return this.cache.get(`metadata/${chainUrl}/${version}`, C.M.$metadata, async () => { + return this.cache.get(`metadata/${chainUrl}/${version}`, C.frame.$metadata, async () => { const client = this.client(chainUrl) const [chainVersion, metadata] = U.throwIfError( await C.Z.ls( diff --git a/codegen/typeVisitor.ts b/codegen/typeVisitor.ts index b7d260a42..24ff77560 100644 --- a/codegen/typeVisitor.ts +++ b/codegen/typeVisitor.ts @@ -1,5 +1,5 @@ import { posix as pathPosix } from "../deps/std/path.ts" -import * as M from "../frame_metadata/mod.ts" +import { Ty, TyVisitor, TyVisitorMethods } from "../scale_info/mod.ts" import { normalizeCase } from "../util/case.ts" import { getOrInit } from "../util/mod.ts" import { Files } from "./Files.ts" @@ -8,7 +8,7 @@ import { makeDocComment, S } from "./utils.ts" class TypeFile { reexports = new Set() - types = new Map() + types = new Map() get ext() { return this.reexports.size ? "/mod.ts" : ".ts" } @@ -16,11 +16,11 @@ class TypeFile { export function createTypeVisitor(props: CodegenProps, files: Files) { const { tys } = props.metadata - const paths = new Map() + const paths = new Map() const typeFiles = new Map() - addPath("types.Compact", { type: "Compact" } as M.Ty) + addPath("types.Compact", { type: "Compact" } as Ty) - const visitor = new M.TyVisitor(tys, { + const visitor = new TyVisitor(tys, { unitStruct(_ty) { return "null" }, @@ -127,7 +127,7 @@ export function createTypeVisitor(props: CodegenProps, files: Files) { return visitor - function getPath(ty: M.Ty): string | null { + function getPath(ty: Ty): string | null { return getOrInit(paths, ty, () => { if ( ty.type === "Struct" && ty.fields.length === 1 && ty.params.some((x) => x.ty !== undefined) @@ -142,7 +142,7 @@ export function createTypeVisitor(props: CodegenProps, files: Files) { return path }) - function _getPath(ty: M.Ty): string | null { + function _getPath(ty: Ty): string | null { if (ty.type === "Primitive") { return (ty.kind === "bool" || ty.kind === "str" ? null : ty.kind) } @@ -182,7 +182,7 @@ export function createTypeVisitor(props: CodegenProps, files: Files) { } } - function addPath(path: string, ty: M.Ty) { + function addPath(path: string, ty: Ty) { let pair = split(path.replace(/\./g, "/")) if (!pair) throw new Error("addPath called with orphan") getOrInit(typeFiles, pair[0], () => new TypeFile()).types.set(path, ty) @@ -197,11 +197,11 @@ export function createTypeVisitor(props: CodegenProps, files: Files) { } } - function createTypeDecl(path: string, ty: M.Ty) { + function createTypeDecl(path: string, ty: Ty) { const name = path.slice(path.lastIndexOf(".") + 1) const docs = makeDocComment(ty.docs) - const fallback = (key: keyof M.TyVisitorMethods) => (...args: any) => { + const fallback = (key: keyof TyVisitorMethods) => (...args: any) => { return `\ ${docs} export type ${name} = ${(visitor[key] as any)!(...args)} @@ -214,7 +214,7 @@ export const $${name[0]!.toLowerCase()}${name.slice(1)}: $.Codec<${ }> = codecs.$${ty.id} ` - return codec + new M.TyVisitor(tys, { + return codec + new TyVisitor(tys, { unitStruct() { return `\ ${docs} diff --git a/codegen/utils.ts b/codegen/utils.ts index 86e80c49c..6ea15622b 100644 --- a/codegen/utils.ts +++ b/codegen/utils.ts @@ -1,4 +1,4 @@ -import * as M from "../frame_metadata/mod.ts" +import { Ty } from "../scale_info/mod.ts" export namespace S { export function array(items: string[]): string { @@ -22,6 +22,6 @@ export function makeDocComment(docs: string[] = []) { return `/**\n * ${docs.join("\n * ")}\n */\n` } -export function getRawCodecPath(ty: M.Ty) { +export function getRawCodecPath(ty: Ty) { return `codecs.$${ty.id}` } diff --git a/effects/contracts/call.ts b/effects/contracts/call.ts index 05180ed1b..e80fe8774 100644 --- a/effects/contracts/call.ts +++ b/effects/contracts/call.ts @@ -3,10 +3,12 @@ import * as Z from "../../deps/zones.ts" import { $contractsApiCallArgs, $contractsApiCallResult, - ContractMetadata, -} from "../../frame_metadata/Contract.ts" -import { DeriveCodec, MultiAddress } from "../../frame_metadata/mod.ts" + Message as InkMessage, + Metadata as InkMetadata, +} from "../../ink_metadata/mod.ts" +import { MultiAddress } from "../../primitives/mod.ts" import { Client } from "../../rpc/mod.ts" +import { DeriveCodec } from "../../scale_info/mod.ts" import * as U from "../../util/mod.ts" import { extrinsic } from "../extrinsic.ts" import { state } from "../rpc_known_methods.ts" @@ -14,8 +16,8 @@ import { state } from "../rpc_known_methods.ts" export interface CallProps { sender: MultiAddress contractAddress: Uint8Array - contractMetadata: ContractMetadata - message: ContractMetadata.Message + inkMetadata: InkMetadata + message: InkMessage args: any[] } @@ -24,11 +26,11 @@ export function call>(client: Client_) { const { sender, contractAddress, - contractMetadata, + inkMetadata, message, args, } = _props as Z.Rec$Access - const $message_ = $message(contractMetadata, message) + const $message_ = $message(inkMetadata, message) const data = Z.ls($message_, message, args).next(([{ $args }, { selector }, args]) => $args.encode([U.hex.decode(selector), ...args]) ) @@ -48,22 +50,17 @@ export interface CallTxProps { sender: MultiAddress contractAddress: Uint8Array value?: bigint - contractMetadata: ContractMetadata - message: ContractMetadata.Message + inkMetadata: InkMetadata + message: InkMessage args: any[] } export function callTx>(client: Client_) { return >(_props: Props) => { - const { - sender, - contractAddress, - value, - contractMetadata, - message, - args, - } = _props as Z.Rec$Access - const $message_ = $message(contractMetadata, message) + const { sender, contractAddress, value, inkMetadata, message, args } = _props as Z.Rec$Access< + Props + > + const $message_ = $message(inkMetadata, message) const data = Z.ls($message_, message, args).next(([{ $args }, { selector }, args]) => $args.encode([U.hex.decode(selector), ...args]) ) @@ -128,10 +125,7 @@ interface MessageCodecs { $result: $.Codec } -function $message( - metadata: Z.$, - message: Z.$, -): Z.$ { +function $message(metadata: Z.$, message: Z.$): Z.$ { return Z.ls(metadata, message).next(([metadata, message]) => { const deriveCodec = DeriveCodec(metadata.V3.types) return { diff --git a/effects/contracts/events.ts b/effects/contracts/events.ts index 8b39a5833..d15e25b91 100644 --- a/effects/contracts/events.ts +++ b/effects/contracts/events.ts @@ -1,28 +1,28 @@ import * as $ from "../../deps/scale.ts" import * as Z from "../../deps/zones.ts" -import { ContractMetadata, DeriveCodec } from "../../frame_metadata/mod.ts" +import { Metadata as InkMetadata } from "../../ink_metadata/mod.ts" +import { DeriveCodec } from "../../scale_info/mod.ts" import { ExtrinsicEvent } from "../events.ts" -export function events( - contractMetadata: Z.$, - events: Z.$, -) { - const $events = Z.ls(contractMetadata).next(([contractMetadata]) => { - return $.taggedUnion( - "type", - contractMetadata.V3.spec.events - .map((e) => [ - e.label, - [ - "value", - $.tuple(...e.args.map((a) => DeriveCodec(contractMetadata.V3.types)(a.type.type))), - ], - ]), +export function events(inkMetadata: Z.$, events: Z.$) { + const $events = Z + .ls(inkMetadata) + .next(([inkMetadata]) => + $.taggedUnion( + "type", + inkMetadata.V3.spec.events + .map((e) => [ + e.label, + [ + "value", + $.tuple(...e.args.map((a) => DeriveCodec(inkMetadata.V3.types)(a.type.type))), + ], + ]), + ) ) - }) - return Z.ls(events, $events).next(([events, $events]) => { - return events + return Z.ls(events, $events).next(([events, $events]) => + events .filter((e) => e.event?.type === "Contracts" && e.event?.value?.type === "ContractEmitted") .map((e) => $events.decode(e.event?.value.data)) - }) + ) } diff --git a/effects/contracts/instantiate.ts b/effects/contracts/instantiate.ts index 90ff31a33..321ee9ddf 100644 --- a/effects/contracts/instantiate.ts +++ b/effects/contracts/instantiate.ts @@ -2,9 +2,9 @@ import * as Z from "../../deps/zones.ts" import { $contractsApiInstantiateArgs, $contractsApiInstantiateResult, - ContractMetadata, -} from "../../frame_metadata/Contract.ts" -import { MultiAddress } from "../../frame_metadata/mod.ts" + Constructor as InkConstructor, +} from "../../ink_metadata/mod.ts" +import { MultiAddress } from "../../primitives/mod.ts" import { Client } from "../../rpc/mod.ts" import * as U from "../../util/mod.ts" import { extrinsic } from "../extrinsic.ts" @@ -13,7 +13,7 @@ import { state } from "../rpc_known_methods.ts" export interface InstantiateProps { sender: MultiAddress code: Uint8Array - constructorMetadata: ContractMetadata.Constructor + constructorMetadata: InkConstructor salt: Uint8Array } diff --git a/effects/extrinsic.ts b/effects/extrinsic.ts index f4471d915..580f9bb7c 100644 --- a/effects/extrinsic.ts +++ b/effects/extrinsic.ts @@ -1,7 +1,8 @@ import { unimplemented } from "../deps/std/testing/asserts.ts" import * as Z from "../deps/zones.ts" -import * as M from "../frame_metadata/mod.ts" +import { MultiAddress, Signer } from "../primitives/mod.ts" import * as rpc from "../rpc/mod.ts" +import { era } from "../scale_info/mod.ts" import * as U from "../util/mod.ts" import { const as const_ } from "./const.ts" import { metadata } from "./metadata.ts" @@ -11,7 +12,7 @@ import * as scale from "./scale.ts" const k0_ = Symbol() export interface ExtrinsicProps { - sender: M.MultiAddress + sender: MultiAddress checkpoint?: U.HexHash mortality?: [period: bigint, phase: bigint] nonce?: string @@ -19,7 +20,7 @@ export interface ExtrinsicProps { call: Call } -export function extrinsic, Call = unknown>(client: Client) { +export function extrinsic>(client: Client) { return >(props: Props): Extrinsic => { return new Extrinsic(client, props) } @@ -34,7 +35,7 @@ export class Extrinsic< readonly props: Props, ) {} - signed>(sign: Sign): SignedExtrinsic { + signed>(sign: Sign): SignedExtrinsic { return new SignedExtrinsic(this.client, this.props, sign) } @@ -60,7 +61,7 @@ export class Extrinsic< export class SignedExtrinsic< Client extends Z.$ = Z.$, Props extends Z.Rec$ = Z.Rec$, - Sign extends Z.$ = Z.$, + Sign extends Z.$ = Z.$, > { client props @@ -110,8 +111,8 @@ export class SignedExtrinsic< .lift(this.props.mortality) .next((mortality) => { return mortality - ? M.era.mortal(mortality[0], mortality[1]) - : M.era.immortal + ? era.mortal(mortality[0], mortality[1]) + : era.immortal }) const extra = Z.ls(mortality, nonce, this.props.tip || 0n) const additional = Z.ls(specVersion, transactionVersion, checkpointHash, genesisHash) @@ -151,7 +152,7 @@ export function extrinsicsDecoded>(client: Client function $extrinsic< Client extends Z.$ = Z.$, - Rest extends [sign?: Z.$] = [sign?: Z.$], + Rest extends [sign?: Z.$] = [sign?: Z.$], >(client: Client, ...[sign]: Rest) { const metadata_ = metadata(client)() const deriveCodec_ = scale.deriveCodec(metadata_) diff --git a/effects/scale.ts b/effects/scale.ts index e6ee633ee..d8c359a6e 100644 --- a/effects/scale.ts +++ b/effects/scale.ts @@ -1,6 +1,8 @@ import * as $ from "../deps/scale.ts" import * as Z from "../deps/zones.ts" import * as M from "../frame_metadata/mod.ts" +import { Signer } from "../primitives/mod.ts" +import { DeriveCodec, Ty } from "../scale_info/mod.ts" const k0_ = Symbol() const k1_ = Symbol() @@ -10,12 +12,12 @@ const k4_ = Symbol() const k5_ = Symbol() export const deriveCodec = Z.call.fac((metadata: M.Metadata) => { - return M.DeriveCodec(metadata.tys) + return DeriveCodec(metadata.tys) }, k0_) export const codec = Z.call.fac(( - deriveCodec: M.DeriveCodec, - ty: number | M.Ty, + deriveCodec: DeriveCodec, + ty: number | Ty, ) => { return deriveCodec(ty) }, k1_) @@ -55,9 +57,9 @@ export function scaleEncoded>, Decoded>( } export const $extrinsic = Z.call.fac(( - deriveCodec: M.DeriveCodec, + deriveCodec: DeriveCodec, metadata: M.Metadata, - sign: M.Signer, + sign: Signer, prefix?: number, ) => { return M.$extrinsic({ @@ -69,7 +71,7 @@ export const $extrinsic = Z.call.fac(( }, k4_) export const $storageKey = Z.call.fac(( - deriveCodec: M.DeriveCodec, + deriveCodec: DeriveCodec, pallet: M.Pallet, storageEntry: M.StorageEntry, ) => { diff --git a/examples/smart_contract.ts b/examples/smart_contract.ts index 5c3d64ef9..e8b8fd149 100644 --- a/examples/smart_contract.ts +++ b/examples/smart_contract.ts @@ -18,7 +18,7 @@ const [code, metadataRaw] = await Promise.all([ await Deno.readFile("examples/smart_contract/flipper.wasm"), await Deno.readTextFile("examples/smart_contract/metadata.json"), ]) -const metadata = C.M.ContractMetadata.normalize(JSON.parse(metadataRaw)) +const metadata = C.ink.normalizeTys(JSON.parse(metadataRaw)) const constructorMetadata = metadata.V3.spec.constructors.find((c) => c.label === "default")! class ExtrinsicFailed extends Error { diff --git a/fluent/Contract.ts b/fluent/Contract.ts index a581a32cd..149419f0a 100644 --- a/fluent/Contract.ts +++ b/fluent/Contract.ts @@ -1,6 +1,7 @@ import * as Z from "../deps/zones.ts" import { contracts, events } from "../effects/mod.ts" -import { ContractMetadata, MultiAddress, Signer } from "../frame_metadata/mod.ts" +import { Metadata as InkMetadata } from "../ink_metadata/mod.ts" +import { MultiAddress, Signer } from "../primitives/mod.ts" import * as rpc from "../rpc/mod.ts" export interface ContractCallProps { @@ -20,7 +21,7 @@ export interface ContractCallTxProps export class Contract> { constructor( readonly client: Client, - readonly contractMetadata: ContractMetadata, + readonly inkMetadata: InkMetadata, readonly contractAddress: Uint8Array, ) {} @@ -36,7 +37,7 @@ export class Contract> { return { sender, contractAddress: this.contractAddress, - contractMetadata: this.contractMetadata, + inkMetadata: this.inkMetadata, message: this.#getMessageByLabel(messageLabel)!, args, } @@ -62,13 +63,13 @@ export class Contract> { return }) const events_ = events(tx, finalizedIn) - const contractEvents = contracts.events(this.contractMetadata, events_) + const contractEvents = contracts.events(this.inkMetadata, events_) return Z.ls(finalizedIn, events_, contractEvents) } #getMessageByLabel