Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kosu.js: implement a go-kosu JSONRPC client (the NodeClient) #229

Merged
merged 18 commits into from Aug 23, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

use BigNumber for validator balance

  • Loading branch information
hrharder committed Aug 23, 2019
commit 1965401c4015cab548f21a406f6bea3de9a3a39e
@@ -1,4 +1,5 @@
import { WebsocketProvider, WebsocketProviderOptions } from "@0x/web3-providers-fork";
import { BigNumber } from "@0x/utils";
import assert from "assert";
import { createHash } from "crypto";
import { isFunction, isString } from "lodash";
@@ -61,8 +62,7 @@ export class NodeClient {
const validators = [];
for (const validator of rawValidators) {
// HACK: protobuf nests the balance as `balance: "value: N"`
const balance = parseInt(validator.balance.split(": ")[1]);

const balance = new BigNumber(validator.balance.split(": ")[1]);
validators.push({ ...validator, balance });
}
return validators;
@@ -220,7 +220,7 @@ export class NodeClient {
* @returns A UUID that can be used to cancel the new subscription (see `node.unsubscribe()`).
*/
public async subscribeToOrders(cb: (order: any) => void): Promise<string> {
return this._subscribe("newOrders", cb);
return this._subscribe("newOrders", (res: any) => cb(res.result.transaction_order));
}

/**
@@ -235,7 +235,7 @@ export class NodeClient {
* @returns A UUID that can be used to cancel the new subscription (see `node.unsubscribe()`).
*/
public async subscribeToBlocks(cb: (block: any) => void): Promise<string> {
return this._subscribe("newBlocks", cb);
return this._subscribe("newBlocks", (res: any) => cb(res.result.block));
}

/**
@@ -250,7 +250,7 @@ export class NodeClient {
* @returns A UUID that can be used to cancel the new subscription (see `node.unsubscribe()`).
*/
public async subscribeToRebalances(cb: (roundInfo: RoundInfo) => void): Promise<string> {
return this._subscribe("newRebalances", cb);
return this._subscribe("newRebalances", (res: any) => cb(res.result.round_info));
}

/**
@@ -260,8 +260,7 @@ export class NodeClient {
*/
public async unsubscribe(subscriptionId: string): Promise<void> {
assert(isString(subscriptionId), "subscriptionId must be a string");
const kosuSubscriptionId = this._subscriptionIdMap[subscriptionId];
await this._call("kosu_unsubscribe", kosuSubscriptionId);
await this._call("kosu_unsubscribe", this._subscriptionIdMap[subscriptionId]);
}

private async _call(method: string, ...params: any[]): Promise<any> {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.