Skip to content

Instantly share code, notes, and snippets.

@brianosaurus
Last active May 7, 2019 16:58
Show Gist options
  • Save brianosaurus/6407318b3d7900fb992526866664dd69 to your computer and use it in GitHub Desktop.
Save brianosaurus/6407318b3d7900fb992526866664dd69 to your computer and use it in GitHub Desktop.
API ideas
Proposing this structure for getters and senders.
export interface Pong {
response: string;
}
export class Ping<TBigNumber> {
public static PingParams = t.type({});
public statuf PongParams = t.type({ respopnse: t.string });
@Getter()
public static async pingGetter<TBigNumber>(db: DB<TBigNumber>, params: t.TypeOf<typeof Ping.PingParams>): Promise<Pong> {
return {
response: "pong",
};
}
@Sender()
public static async pingSender<TBigNumber>(provider: AugurProvider, params: t.TypeOf<typeof Ping.PingParams>): Promise<Pong> {
return Ping.PongParams.decode(provider.send(params.encode());
}
}
The provider is responsible for the following operations:
{ subscribe, unsubscribe, send, connect, disconnect }
Event handlers can have a similar format
export PING_EVENT = "ping";
export class Ping<TBigNumber> {
public static PongParams = t.type({ response: t.string });
@HandleEvent()
public static async ping<TBigNumber>(params: any): Promise<Pong> {
return Ping.PongParams.decode(params);
}
}
@brianosaurus
Copy link
Author

I think the invocation will be more like

const response = API.send(Ping.PING_REQ, new Ping.PingParams({...});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment