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

fixing validators balance conversion

  • Loading branch information
hrharder committed Aug 22, 2019
commit f040e2f903bdf0c08aa11a2557d1d8355454f842
@@ -8,10 +8,10 @@ export class NodeClient {
private readonly _heartbeatInterval: number;
private readonly _subscriptionIdMap: { [uuid: string]: string };

private static _convertValidatorData(rawValidators: any[]): Validator[] {
private static _convertValidatorData(...rawValidators: any[]): Validator[] {
const validators = [];
for (const validator of rawValidators) {
const balance = parseInt(validator.balance.split(": "));
const balance = parseInt(validator.balance.split(": ")[1]);
This conversation was marked as resolved by hrharder

This comment has been minimized.

Copy link
@Freydal

Freydal Aug 23, 2019

Contributor

Should this be stored as a BigNumber? I am under the impression this is tokens not power. The minimum right now 5e20.

This comment has been minimized.

Copy link
@hrharder

hrharder Aug 23, 2019

Author Member

Ahh good point... I'm curious how the Kosu RPC transmits the numbers over the wire for the balance, I will check that out.

But yes -- I think you're right, this should probably be a BigNumber

validators.push({ ...validator, balance });
}
return validators;
@@ -42,14 +42,13 @@ export class NodeClient {
}

public async queryValidator(nodeId: string): Promise<Validator> {
if (/^[a-fA-F0-9]{40}$/.test(nodeId)) {
if (!/^[a-fA-F0-9]{40}$/.test(nodeId)) {
throw new Error("invalid validator node ID string");
}

// hack: dealing with protobuf decoding issues
const raw = await this._call("kosu_queryValidator", nodeId);
const balance = parseInt(raw.balance.split(": "));
return { ...raw, balance };
return NodeClient._convertValidatorData(raw)[0];
}

public async remainingLimit(): Promise<number> {
@@ -72,7 +71,7 @@ export class NodeClient {

public async validators(): Promise<Validator[]> {
const rawValidators = await this._call("kosu_validators");
return NodeClient._convertValidatorData(rawValidators as unknown as any[]);
return NodeClient._convertValidatorData(...rawValidators);
}

public async subscribeToOrders(cb: (orders: any[]) => void): Promise<string> {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.