Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Dec 22, 2022
1 parent b74c05f commit 097900f
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 498 deletions.
4 changes: 2 additions & 2 deletions codegen/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export abstract class CodegenServer {
))
}

filesMemo = new Map<C.M.Metadata, Files>()
filesMemo = new Map<C.frame.Metadata, Files>()
async files(chainUrl: string, version: string, chainVersion: string) {
const metadata = await this.metadata(chainUrl, chainVersion)
return U.getOrInit(this.filesMemo, metadata, () => {
Expand Down Expand Up @@ -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(
Expand Down
38 changes: 16 additions & 22 deletions effects/contracts/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ 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"

export interface CallProps {
sender: MultiAddress
contractAddress: Uint8Array
contractMetadata: ContractMetadata
message: ContractMetadata.Message
inkMetadata: InkMetadata
message: InkMessage
args: any[]
}

Expand All @@ -24,11 +26,11 @@ export function call<Client_ extends Z.Effect<Client>>(client: Client_) {
const {
sender,
contractAddress,
contractMetadata,
inkMetadata,
message,
args,
} = _props as Z.Rec$Access<Props>
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])
)
Expand All @@ -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_ extends Z.Effect<Client>>(client: Client_) {
return <Props extends Z.Rec$<CallTxProps>>(_props: Props) => {
const {
sender,
contractAddress,
value,
contractMetadata,
message,
args,
} = _props as Z.Rec$Access<Props>
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])
)
Expand Down Expand Up @@ -128,10 +125,7 @@ interface MessageCodecs {
$result: $.Codec<any>
}

function $message(
metadata: Z.$<ContractMetadata>,
message: Z.$<ContractMetadata.Message>,
): Z.$<MessageCodecs> {
function $message(metadata: Z.$<InkMetadata>, message: Z.$<InkMessage>): Z.$<MessageCodecs> {
return Z.ls(metadata, message).next(([metadata, message]) => {
const deriveCodec = DeriveCodec(metadata.V3.types)
return {
Expand Down
40 changes: 20 additions & 20 deletions effects/contracts/events.ts
Original file line number Diff line number Diff line change
@@ -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.$<ContractMetadata>,
events: Z.$<ExtrinsicEvent[]>,
) {
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.$<InkMetadata>, events: Z.$<ExtrinsicEvent[]>) {
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))
})
)
}
8 changes: 4 additions & 4 deletions effects/contracts/instantiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion examples/smart_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions fluent/Contract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as Z from "../deps/zones.ts"
import { contracts, events } from "../effects/mod.ts"
import { ContractMetadata, MultiAddress, Signer } from "../frame_metadata/mod.ts"
import { Signer } from "../frame_metadata/mod.ts"
import { Metadata as InkMetadata } from "../ink_metadata/mod.ts"
import { MultiAddress } from "../primitives/mod.ts"
import * as rpc from "../rpc/mod.ts"

export interface ContractCallProps<Args extends unknown[] = any[]> {
Expand All @@ -20,7 +22,7 @@ export interface ContractCallTxProps<Args extends unknown[] = any[]>
export class Contract<Client extends Z.Effect<rpc.Client>> {
constructor(
readonly client: Client,
readonly contractMetadata: ContractMetadata,
readonly inkMetadata: InkMetadata,
readonly contractAddress: Uint8Array,
) {}

Expand All @@ -36,7 +38,7 @@ export class Contract<Client extends Z.Effect<rpc.Client>> {
return {
sender,
contractAddress: this.contractAddress,
contractMetadata: this.contractMetadata,
inkMetadata: this.inkMetadata,
message: this.#getMessageByLabel(messageLabel)!,
args,
}
Expand All @@ -62,13 +64,13 @@ export class Contract<Client extends Z.Effect<rpc.Client>> {
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<Label extends Z.$<string>>(label: Label) {
return Z.lift(label).next((label) =>
this.contractMetadata.V3.spec.messages.find((c) => c.label === label)!
this.inkMetadata.V3.spec.messages.find((c) => c.label === label)!
)
}
}
4 changes: 2 additions & 2 deletions fluent/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export * from "./Contract.ts"
export class Storage<C extends C.Z.$<C.rpc.Client>, K extends unknown[], V> {
constructor(
readonly client: C,
readonly type: C.M.StorageEntry["type"],
readonly modifier: C.M.StorageEntry["modifier"],
readonly type: C.frame.StorageEntry["type"],
readonly modifier: C.frame.StorageEntry["modifier"],
readonly pallet: string,
readonly name: string,
readonly $key: C.$.Codec<K>,
Expand Down
Loading

0 comments on commit 097900f

Please sign in to comment.