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

chore: update scale dependency to 0.10.0 #498

Merged
merged 7 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _tasks/dnt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ await Promise.all([
name: "wat-the-crypto",
version: "^0.0.1",
},
"https://deno.land/x/scale@v0.9.1/mod.ts": {
"https://deno.land/x/scale@v0.10.0/mod.ts": {
name: "scale-codec",
version: "^0.9.1",
version: "^0.10.0",
},
"https://deno.land/x/[email protected]/mod.ts": {
name: "zones",
Expand Down
25 changes: 10 additions & 15 deletions codegen/genCodecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ import type * as types from "./types/mod.ts"
return addCodecDecl(
ty,
`$.object(${
ty.fields.map((x) =>
S.array([
S.string(normalizeCase(x.name!)),
this.visit(x.ty),
])
).join(", ")
ty.fields.map((x) => `$.field(${S.string(normalizeCase(x.name!))}, ${this.visit(x.ty)})`)
.join(", ")
})`,
)
},
Expand All @@ -44,7 +40,9 @@ import type * as types from "./types/mod.ts"
ty,
`$.result(${
this.visit(ok)
}, $.instance(C.ChainError<$.Native<typeof $${err.id}>>, ["value", ${this.visit(err)}]))`,
}, $.instance(C.ChainError<$.Native<typeof $${err.id}>>, $.tuple(${
this.visit(err)
}), (x) => [x.value]))`,
)
},
never(ty) {
Expand Down Expand Up @@ -77,17 +75,14 @@ import type * as types from "./types/mod.ts"
const value = fields.length === 1
? this.visit(fields[0]!.ty)
: `$.tuple(${fields.map((f) => this.visit(f.ty)).join(", ")})`
props = [S.array([S.string("value"), value])]
props = [`$.field(${S.string("value")}, ${value})`]
} else {
// Object variant
props = fields.map((field) =>
S.array([
S.string(normalizeCase(field.name!)),
this.visit(field.ty),
])
)
props = fields.map((
field,
) => `$.field(${S.string(normalizeCase(field.name!))}, ${this.visit(field.ty)})`)
}
return [`${index}`, S.array([S.string(type), ...props])]
return [`${index}`, `$.variant(${S.string(type)}, ${props.join(",")})`]
}),
)
})`,
Expand Down
2 changes: 1 addition & 1 deletion deps/scale.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/x/scale@v0.9.1/mod.ts"
export * from "https://deno.land/x/scale@v0.10.0/mod.ts"
16 changes: 9 additions & 7 deletions effects/contracts/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export function events(inkMetadata: Z.$<InkMetadata>, events: Z.$<ExtrinsicEvent
$.taggedUnion(
"type",
inkMetadata.V3.spec.events
.map((e) => [
e.label,
[
"value",
$.tuple(...e.args.map((a) => DeriveCodec(inkMetadata.V3.types)(a.type.type))),
],
]),
.map((e) =>
$.variant(
e.label,
$.field(
"value",
$.tuple(...e.args.map((a) => DeriveCodec(inkMetadata.V3.types)(a.type.type))),
),
)
),
)
)
return Z.ls(events, $events).next(([events, $events]) =>
Expand Down
80 changes: 40 additions & 40 deletions frame_metadata/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export interface MapStorageEntryType {
export type StorageEntryType = PlainStorageEntryType | MapStorageEntryType

export const $storageEntryType: $.Codec<StorageEntryType> = $.taggedUnion("type", [
["Plain", ["value", $tyId]],
[
$.variant("Plain", $.field("value", $tyId)),
$.variant(
"Map",
["hashers", $.array($hasherKind)],
["key", $tyId],
["value", $tyId],
],
$.field("hashers", $.array($hasherKind)),
$.field("key", $tyId),
$.field("value", $tyId),
),
])

export type StorageEntry = {
Expand All @@ -50,17 +50,17 @@ export type StorageEntry = {
docs: string[]
} & StorageEntryType

export const $storageEntry: $.Codec<StorageEntry> = $.spread(
$.spread(
export const $storageEntry: $.Codec<StorageEntry> = $.object(
$.object(
$.object(
["name", $.str],
["modifier", $storageEntryModifier],
$.field("name", $.str),
$.field("modifier", $storageEntryModifier),
),
$storageEntryType,
),
$.object(
["default", $.uint8Array],
["docs", $.array($.str)],
$.field("default", $.uint8Array),
$.field("docs", $.array($.str)),
),
)

Expand All @@ -69,8 +69,8 @@ export interface Storage {
entries: StorageEntry[]
}
export const $storage: $.Codec<Storage> = $.object(
["prefix", $.str],
["entries", $.array($storageEntry)],
$.field("prefix", $.str),
$.field("entries", $.array($storageEntry)),
)

export interface Constant {
Expand All @@ -80,29 +80,29 @@ export interface Constant {
docs: string[]
}
export const $constant: $.Codec<Constant> = $.object(
["name", $.str],
["ty", $tyId],
["value", $.uint8Array],
["docs", $.array($.str)],
$.field("name", $.str),
$.field("ty", $tyId),
$.field("value", $.uint8Array),
$.field("docs", $.array($.str)),
)

export interface Pallet {
name: string
storage: Storage | undefined
calls: Ty | undefined
event: Ty | undefined
storage?: Storage
calls?: Ty
event?: Ty
constants: Constant[]
error: Ty | undefined
error?: Ty
i: number
}
export const $pallet: $.Codec<Pallet> = $.object(
["name", $.str],
["storage", $.option($storage)],
["calls", $.option($tyId)],
["event", $.option($tyId)],
["constants", $.array($constant)],
["error", $.option($tyId)],
["i", $.u8],
$.field("name", $.str),
$.optionalField("storage", $storage),
$.optionalField("calls", $tyId),
$.optionalField("event", $tyId),
$.field("constants", $.array($constant)),
$.optionalField("error", $tyId),
$.field("i", $.u8),
)

export interface SignedExtensionMetadata {
Expand All @@ -111,9 +111,9 @@ export interface SignedExtensionMetadata {
additionalSigned: Ty
}
export const $signedExtensionMetadata: $.Codec<SignedExtensionMetadata> = $.object(
["ident", $.str],
["ty", $tyId],
["additionalSigned", $tyId],
$.field("ident", $.str),
$.field("ty", $tyId),
$.field("additionalSigned", $tyId),
)

export interface ExtrinsicDef {
Expand All @@ -122,9 +122,9 @@ export interface ExtrinsicDef {
signedExtensions: SignedExtensionMetadata[]
}
export const $extrinsicDef: $.Codec<ExtrinsicDef> = $.object(
["ty", $tyId],
["version", $.u8],
["signedExtensions", $.array($signedExtensionMetadata)],
$.field("ty", $tyId),
$.field("version", $.u8),
$.field("signedExtensions", $.array($signedExtensionMetadata)),
)

// https://docs.substrate.io/build/application-development/#metadata-system
Expand All @@ -138,11 +138,11 @@ export interface Metadata {
extrinsic: ExtrinsicDef
}
export const $metadata: $.Codec<Metadata> = $.object(
["magicNumber", $.constant<typeof magicNumber>(magicNumber, $.u32)],
["version", $.constant<14>(14, $.u8)],
["tys", $tys],
["pallets", $.array($pallet)],
["extrinsic", $extrinsicDef],
$.field("magicNumber", $.constant<typeof magicNumber>(magicNumber, $.u32)),
$.field("version", $.constant<14>(14, $.u8)),
$.field("tys", $tys),
$.field("pallets", $.array($pallet)),
$.field("extrinsic", $extrinsicDef),
)

export function fromPrefixedHex(scaleEncoded: string): Metadata {
Expand Down
Loading