diff --git a/src/gaia/api.ts b/src/gaia/api.ts index f1e6f8b..052667d 100644 --- a/src/gaia/api.ts +++ b/src/gaia/api.ts @@ -6,6 +6,7 @@ import * as Distribution from "../x/distribution"; import * as Gov from "../x/gov"; import * as Slashing from "../x/slashing"; import * as Staking from "../x/staking"; +import * as Link from "../x/link"; import { defaultTxEncoder } from "../common/stdTx"; import { stdTxBuilder } from "../common/stdTxBuilder"; import { Context } from "../core/context"; @@ -50,6 +51,7 @@ export class GaiaApi extends Api { Gov.registerCodec(codec); Slashing.registerCodec(codec); Staking.registerCodec(codec); + Link.registerCodec(codec); } }, ...coreConfig diff --git a/src/x/link/codec.ts b/src/x/link/codec.ts new file mode 100644 index 0000000..1e7fc25 --- /dev/null +++ b/src/x/link/codec.ts @@ -0,0 +1,6 @@ +import { Codec } from "@node-a-team/ts-amino"; +import { MsgLink } from "./msgs"; + +export function registerCodec(codec: Codec) { + codec.registerConcrete("cyber/Link", MsgLink.prototype); +} diff --git a/src/x/link/index.ts b/src/x/link/index.ts new file mode 100644 index 0000000..3173262 --- /dev/null +++ b/src/x/link/index.ts @@ -0,0 +1,2 @@ +export * from "./msgs"; +export * from "./codec"; diff --git a/src/x/link/msgs.ts b/src/x/link/msgs.ts new file mode 100644 index 0000000..89fb18e --- /dev/null +++ b/src/x/link/msgs.ts @@ -0,0 +1,54 @@ +import { Amino, Type } from "@node-a-team/ts-amino"; +const { Field, DefineStruct } = Amino; +import { Msg } from "../../core/tx"; +import { AccAddress } from "../../common/address"; + +@DefineStruct() +export class Link { + @Field.String(0) + public from: string; + + @Field.String(1) + public to: string; + + constructor(from: string, to: string) { + this.from = from; + this.to = to; + } +} + +@DefineStruct() +export class MsgLink extends Msg { + @Field.Defined(0, { + jsonName: "address" + }) + public address: AccAddress; + + @Field.Slice( + 1, + { type: Type.Defined }, + { + jsonName: "links" + } + ) + public links: Link[]; + + constructor(address: AccAddress, links: Link[]) { + super(); + this.address = address; + this.links = links; + } + + public getSigners(): AccAddress[] { + return [this.address]; + } + + public validateBasic(): void { + for (const link of this.links) { + // TODO improve validation + if (link.from.length == 0 || link.to.length == 0) { + throw new Error("CID is empty"); + } + } + } +}