Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Rename RpcResponse to RpcResponseData
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed Aug 30, 2024
1 parent 1193f5f commit f16d5af
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .changeset/gorgeous-foxes-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@solana/rpc-subscriptions-spec': patch
'@solana/rpc-spec-types': patch
'@solana/rpc-spec': patch
'@solana/rpc-api': patch
---

Rename `RpcResponse` type to `RpcResponseData` to make room for a new `RpcResponse` type
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('getStakeMinimumDelegation', () => {
});
(['confirmed', 'finalized', 'processed'] as Commitment[]).forEach(commitment => {
describe(`when called with \`${commitment}\` commitment`, () => {
it('returns the result as a bigint wrapped in an RpcResponse', async () => {
it('returns the result as a bigint wrapped in an RpcResponseData', async () => {
expect.assertions(1);
const result = await rpc.getStakeMinimumDelegation({ commitment }).send();
expect(result.value).toEqual(expect.any(BigInt));
Expand Down
2 changes: 1 addition & 1 deletion packages/rpc-api/src/__tests__/is-blockhash-valid-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('isBlockhashValid', () => {
});
(['confirmed', 'finalized', 'processed'] as Commitment[]).forEach(commitment => {
describe(`when called with \`${commitment}\` commitment`, () => {
it('returns the result as a bool wrapped in an RpcResponse', async () => {
it('returns the result as a bool wrapped in an RpcResponseData', async () => {
expect.assertions(1);
const blockhash = '9PCVWkKP3bq1sT5eLFurUysMvVs4PxJsTfza5QSBB4d1' as Blockhash;
const result = await rpc.isBlockhashValid(blockhash, { commitment }).send();
Expand Down
5 changes: 3 additions & 2 deletions packages/rpc-spec-types/src/rpc-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ interface IHasIdentifier {
readonly id: number;
}

type RpcErrorResponse = Readonly<{
type RpcErrorResponsePayload = Readonly<{
code: number;
data?: unknown;
message: string;
}>;

export type RpcResponse<TResponse> = IHasIdentifier & Readonly<{ error: RpcErrorResponse } | { result: TResponse }>;
export type RpcResponseData<TResponse> = IHasIdentifier &
Readonly<{ error: RpcErrorResponsePayload } | { result: TResponse }>;
4 changes: 2 additions & 2 deletions packages/rpc-spec/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
createRpcMessage,
Flatten,
OverloadImplementations,
RpcResponse,
RpcResponseData,
UnionToIntersection,
} from '@solana/rpc-spec-types';

Expand Down Expand Up @@ -69,7 +69,7 @@ function createPendingRpcRequest<TRpcMethods, TRpcTransport extends RpcTransport
async send(options?: RpcSendOptions): Promise<TResponse> {
const { methodName, params, responseTransformer } = pendingRequest;
const payload = createRpcMessage(methodName, params);
const response = await rpcConfig.transport<RpcResponse<unknown>>({
const response = await rpcConfig.transport<RpcResponseData<unknown>>({
payload,
signal: options?.abortSignal,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/rpc-subscriptions-spec/src/rpc-subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
createRpcMessage,
Flatten,
OverloadImplementations,
RpcResponse,
RpcResponseData,
UnionToIntersection,
} from '@solana/rpc-spec-types';

Expand Down Expand Up @@ -155,7 +155,7 @@ function createPendingRpcSubscription<
* STEP 2: Wait for the acknowledgement from the server with the subscription id.
*/
for await (const message of connection as AsyncIterable<
RpcNotification<unknown> | RpcResponse<RpcSubscriptionId>
RpcNotification<unknown> | RpcResponseData<RpcSubscriptionId>
>) {
if ('id' in message && message.id === subscribeMessage.id) {
if ('error' in message) {
Expand All @@ -175,7 +175,7 @@ function createPendingRpcSubscription<
return {
async *[Symbol.asyncIterator]() {
for await (const message of connection as AsyncIterable<
RpcNotification<unknown> | RpcResponse<RpcSubscriptionId>
RpcNotification<unknown> | RpcResponseData<RpcSubscriptionId>
>) {
if (!('params' in message) || message.params.subscription !== subscriptionId) {
continue;
Expand Down

0 comments on commit f16d5af

Please sign in to comment.