Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Add cyberlinks support for Cyber #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/gaia/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -50,6 +51,7 @@ export class GaiaApi extends Api<GaiaRest> {
Gov.registerCodec(codec);
Slashing.registerCodec(codec);
Staking.registerCodec(codec);
Link.registerCodec(codec);
}
},
...coreConfig
Expand Down
6 changes: 6 additions & 0 deletions src/x/link/codec.ts
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 2 additions & 0 deletions src/x/link/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./msgs";
export * from "./codec";
54 changes: 54 additions & 0 deletions src/x/link/msgs.ts
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
}