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

Commit

Permalink
chore: remove 3 hard-coded "primitive" factories (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay authored Jul 5, 2022
1 parent 8c68b84 commit 9f1c2a0
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 59 deletions.
2 changes: 0 additions & 2 deletions core/Address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { unimplemented } from "../_deps/asserts.ts";
import { Ss58 } from "../bindings/mod.ts";
import { MultiAddress } from "../primitives/MultiAddress.ts";
import * as U from "../util/mod.ts";
import { Addresses } from "./Addresses.ts";
import { NodeBase } from "./common.ts";
Expand Down Expand Up @@ -55,5 +54,4 @@ export class Address<
declare asPublicKeyText: () => string;
declare asSs58Bytes: () => Uint8Array;
declare asSs58Text: () => string;
declare asMulti: () => MultiAddress;
}
25 changes: 16 additions & 9 deletions examples/transfer_working.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { assert } from "../_deps/asserts.ts";
import { Hashers, Sr25519 } from "../bindings/mod.ts";
import * as M from "../frame_metadata/mod.ts";
import { westendBeacon } from "../known/mod.ts";
import * as C from "../mod.ts";
import * as rpc from "../rpc/mod.ts";
import * as U from "../util/mod.ts";

Expand All @@ -27,19 +26,21 @@ const $extrinsic = M.$extrinsic({
metadata,
deriveCodec,
hashers,
sign: (message) => new C.Sr25519Signature(alice.sign(message)),
sign: (message) => ({
type: "Sr25519",
value: alice.sign(message),
}),
});

const from = new C.MultiAddress("Id", alice.publicKey);
const DEST_PUBLIC_KEY = "8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48";
const dest = new C.MultiAddress("Id", U.hex.decode(DEST_PUBLIC_KEY));

const extrinsic: M.Extrinsic = {
protocolVersion: 4,
signature: {
address: from,
address: {
type: "Id",
value: alice.publicKey,
},
extra: [
/* era */ C.immortalEra,
/* era */ { type: "Immortal" },
/* nonce */ 1000,
/* tip */ 500,
],
Expand All @@ -52,7 +53,13 @@ const extrinsic: M.Extrinsic = {
},
palletName: "Balances",
methodName: "transfer",
args: { dest, value: 12345n },
args: {
dest: {
type: "Id",
value: U.hex.decode("8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"),
},
value: 12345n,
},
};

const encoded = $extrinsic.encode(extrinsic);
Expand Down
18 changes: 17 additions & 1 deletion frame_metadata/Extrinsic.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import * as $ from "../_deps/scale.ts";
import { MultiAddress, Signature } from "../primitives/mod.ts";
import { $null, DeriveCodec } from "./Codec.ts";
import { HasherLookup } from "./Key.ts";
import { Metadata } from "./Metadata.ts";

export type Era = {
type: "Mortal";
value: [period: bigint, phase: bigint];
} | {
type: "Immortal";
};

export interface MultiAddress {
type: "Id" | "Index" | "Raw" | "Address20" | "Address32";
value: Uint8Array;
}

interface Signature {
type: "Sr25519";
value: Uint8Array;
}

export interface Extrinsic {
protocolVersion: number;
signature?:
Expand Down
1 change: 0 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ export * as $ from "./_deps/scale.ts";
export * from "./Beacon.ts";
export * from "./core/mod.ts";
export * from "./known/mod.ts";
export * from "./primitives/mod.ts";
export * as test from "./test-util/mod.ts";
export { iter } from "./util/mod.ts";
18 changes: 0 additions & 18 deletions primitives/Era.ts

This file was deleted.

8 changes: 0 additions & 8 deletions primitives/MultiAddress.ts

This file was deleted.

17 changes: 0 additions & 17 deletions primitives/Signature.ts

This file was deleted.

3 changes: 0 additions & 3 deletions primitives/mod.ts

This file was deleted.

0 comments on commit 9f1c2a0

Please sign in to comment.