Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upkosu.js: implement a go-kosu JSONRPC client (the NodeClient) #229
+1,389
−717
Conversation
|
The only issue I saw was storing the balance in an integer. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
hrharder commentedAug 22, 2019
•
edited
Use
.tsfile filter to hide lots of auto-generated markdown diffs.Overview
Adds the
NodeClientclass tokosu.js, a JSONRPC/WebSocket for the Kosu RPC-API.Supports all endpoints of the Kosu JSONRPC (as of #224).
Class: NodeClient
A simple JSONRPC/WebSocket client for the
go-kosuJSONRPC-API. Supports thefull Kosu JSONRPC, including subscriptions.
It is built on the web3
WebSocketProviderJSONRPC client, through a more desirable fork provided by 0x.
As such, it can be configured with the same options supported by the underlying
client.
It must be initialized with the URL of a
go-kosunode serving the JSONRPCover WebSocket.
View the Kosu RPC documentation here.
Hierarchy
Index
Constructors
Properties
Methods
Object literals
Constructors
constructor
+ new NodeClient(
url: string,options?:WebsocketProviderOptions): NodeClientDefined in NodeClient.ts:69
Create a new NodeClient (
node) via a connection to a Kosu node servingthe Kosu JSONRPC/WebSocket.
exampleParameters:
urloptions?WebsocketProviderOptionsWebSocketProvider.Returns: NodeClient
Properties
StaticNODE_ID_HASH_OFFSET▪ NODE_ID_HASH_OFFSET: number = 20
Defined in NodeClient.ts:37
Kosu validator node IDs are the first 20 bytes of the SHA-256 hash of the
public key.
StaticPUBLIC_KEY_LENGTH▪ PUBLIC_KEY_LENGTH: number = 32
Defined in NodeClient.ts:31
Kosu validator public key's are 32 bytes long.
Methods
addOrders
▸ addOrders(...
orders: any[]):Promise<OrderValidationResult[]>Defined in NodeClient.ts:101
See
kosu_addOrders.Submit poster-signed orders to the Kosu node to be subsequently proposed
to the network. In order for them to be accepted, they must have signatures
from valid posters who have bonded Kosu tokens.
See the
posterRegistry.registerTokens()method to bond KOSU.Parameters:
...ordersReturns:
Promise<OrderValidationResult[]>Validation results from the Kosu node, and/or the transaction
ID's of the accepted orders.
latestHeight
▸ latestHeight():
Promise<number>Defined in NodeClient.ts:112
See
kosu_latestHeight.Get the height of the most recently committed and finalized Kosu block.
Returns:
Promise<number>The most recent Kosu block number.
numberPosters
▸ numberPosters():
Promise<number>Defined in NodeClient.ts:123
See
kosu_numberPosters.Get the total number registered posters from the Kosu node.
Returns:
Promise<number>The total number of poster accounts the node is tracking.
queryPoster
▸ queryPoster(
address: string):Promise<Poster>Defined in NodeClient.ts:135
See
kosu_queryPoster.Get finalized (committed into current state) balance and order limit data
about a specified poster account.
Parameters:
addressReturns:
Promise<Poster>Balance and order limit data for the specified poster account.
queryValidator
▸ queryValidator(
nodeId: string):Promise<Validator>Defined in NodeClient.ts:152
See
kosu_queryValidator.Get finalized (committed into current state) information about a Kosu
validator node, identified by their node ID (also called Tendermint
address).
See
NodeClient.publicKeyToNodeId()to converting a validator's encodedpublic key to it's node ID.
Parameters:
nodeIdReturns:
Promise<Validator>Information about the requested validator (see
Validator).remainingLimit
▸ remainingLimit():
Promise<number>Defined in NodeClient.ts:169
See
kosu_remainingLimit.Get the total number of orders that may be posted this period. It is
equal to the sum of the unutilized bandwidth allocation for each poster
account for the current rebalance period.
Returns:
Promise<number>The unutilized order bandwidth for the current period.
roundInfo
▸ roundInfo():
Promise<RoundInfo>Defined in NodeClient.ts:181
See
kosu_roundInfo.Get the current rebalance period number, starting Ethereum block, ending
Ethereum block, and the maximum number of orders for the period.
Returns:
Promise<RoundInfo>Information about the current rebalance period.
subscribeToBlocks
▸ subscribeToBlocks(
cb: function):Promise<string>Defined in NodeClient.ts:237
Read about Kosu subscriptions here.
See
kosu_subscribefor topicnewBlocks.Subscribe to new block events, and be updated with the full Tendermint block
after each successful commit.
Parameters:
▪ cb: function
A callback function to handle new rebalance information.
▸ (
block: any): voidParameters:
blockReturns:
Promise<string>A UUID that can be used to cancel the new subscription (see
node.unsubscribe()).subscribeToOrders
▸ subscribeToOrders(
cb: function):Promise<string>Defined in NodeClient.ts:222
Read about Kosu subscriptions here.
See
kosu_subscribefor topicnewOrders.Subscribe to order transaction events, and be udpdated with an array of new
orders each time they are included in a Kosu block.
Parameters:
▪ cb: function
A callback function to handle each array of new orders.
▸ (
order: any): voidParameters:
orderReturns:
Promise<string>A UUID that can be used to cancel the new subscription (see
node.unsubscribe()).subscribeToRebalances
▸ subscribeToRebalances(
cb: function):Promise<string>Defined in NodeClient.ts:252
Read about Kosu subscriptions here.
See
kosu_subscribefor topicnewRebalances.Subscribe to rebalance events, and be updated with each new rebalance round
information (starting block, ending block, etc.).
Parameters:
▪ cb: function
A callback function to handle new rebalance information.
▸ (
roundInfo: RoundInfo): voidParameters:
roundInfoReturns:
Promise<string>A UUID that can be used to cancel the new subscription (see
node.unsubscribe()).totalOrders
▸ totalOrders():
Promise<number>Defined in NodeClient.ts:194
See
kosu_totalOrders.Get the total number of orders that have been processed by the network
since genesis.
Returns:
Promise<number>The total number of orders posted since network genesis.
unsubscribe
▸ unsubscribe(
subscriptionId: string):Promise<void>Defined in NodeClient.ts:261
Cancel an active subscription.
Parameters:
subscriptionIdReturns:
Promise<void>validators
▸ validators():
Promise<Validator[]>Defined in NodeClient.ts:206
See
kosu_validators.Get finalized (committed into current state) information about the current
full validator set. Returns the full set (not paginated).
Returns:
Promise<Validator[]>Information about all active Kosu validators (see
Validator).StaticpublicKeyToNodeId▸ publicKeyToNodeId(
publicKey: string): stringDefined in NodeClient.ts:50
Convert a Kosu/Tendermint public key to the corresponding node ID.
The node ID is the first 20 bytes of the SHA-256 hash of the public key.
Parameters:
publicKeyReturns: string
The node ID (tendermint "address") for that public key.
Object literals
StaticDEFAULT_OPTIONS▪ DEFAULT_OPTIONS: object
Defined in NodeClient.ts:26
The default options specify a connection timeout of 3s, all other defaults
are inherited from
WebsocketProviderOptions.timeout
• timeout: number = 3000
Defined in NodeClient.ts:26