-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Use RpcRequest in createRpcMessage helper (#3394)
This PR changes the arguments of the `createRpcMessage` helper function so that it accepts an `RpcRequest` directly instead of accepting all the components inside a request (i.e. `methodName` and `params`). We discussed this a little while ago with @mcintyre94 as, without this change, you sometimes need to express a request as an object and sometimes as its deconstructed version. This PR stack aims to embrace the `RpcRequest` object wherever applicable.
1 parent
3c02c35
commit db144da
Showing
6 changed files
with
32 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@solana/rpc-subscriptions-spec': patch | ||
'@solana/rpc-spec-types': patch | ||
'@solana/rpc-spec': patch | ||
--- | ||
|
||
Use RpcRequest in createRpcMessage helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import { RpcRequest } from './rpc-request'; | ||
|
||
let _nextMessageId = 0; | ||
function getNextMessageId() { | ||
const id = _nextMessageId; | ||
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER; | ||
return id; | ||
} | ||
|
||
export function createRpcMessage<TParams>(method: string, params: TParams) { | ||
export function createRpcMessage<TParams>(request: RpcRequest<TParams>) { | ||
return { | ||
id: getNextMessageId(), | ||
jsonrpc: '2.0', | ||
method, | ||
params, | ||
method: request.methodName, | ||
params: request.params, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters