This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more request transformers (#3161)
This PR finishes the refactoring of the `getDefaultRequestTransformerForSolanaRpc` function by creating three new request transformers and delegating to them: - `getIntegerOverflowRequestTransformer`: Wraps the integer overflow visitor in a request transformer. - `getBigIntDowncastRequestTransformer`: Wraps the bigint downcast visitor in a request transformer. - `getTreeWalkerRequestTransformer`: Helper that creates request transformers from visitors. Additionally, this PR changes the definition of the `onIntegerOverflow` slightly by using `request: RpcRequest` as its first argument instead of `methodName: string` to be more consistent with the rest of the RPC API.
- Loading branch information
1 parent
fcfaec9
commit 9dfca45
Showing
15 changed files
with
155 additions
and
57 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': patch | ||
'@solana/rpc-subscriptions': patch | ||
'@solana/rpc-transformers': patch | ||
--- | ||
|
||
Change first argument of `onIntegerOverflow` handler from `methodName: string` to `request: RpcRequest` |
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,6 @@ | ||
--- | ||
'@solana/rpc-transformers': patch | ||
'@solana/rpc-api': patch | ||
--- | ||
|
||
Add `getIntegerOverflowRequestTransformer`, `getBigIntDowncastRequestTransformer` and `getTreeWalkerRequestTransformer` helpers |
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
2 changes: 1 addition & 1 deletion
2
...arams-transformer-bigint-downcast-test.ts → ...quest-transformer-bigint-downcast-test.ts
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
2 changes: 1 addition & 1 deletion
2
...rams-transformer-integer-overflow-test.ts → ...uest-transformer-integer-overflow-test.ts
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
14 changes: 0 additions & 14 deletions
14
packages/rpc-transformers/src/params-transformer-integer-overflow.ts
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
...src/params-transformer-bigint-downcast.ts → ...rc/request-transformer-bigint-downcast.ts
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
26 changes: 26 additions & 0 deletions
26
packages/rpc-transformers/src/request-transformer-integer-overflow.ts
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,26 @@ | ||
import { RpcRequest } from '@solana/rpc-spec'; | ||
|
||
import { getTreeWalkerRequestTransformer, KeyPath, TraversalState } from './tree-traversal'; | ||
|
||
export type IntegerOverflowHandler = (request: RpcRequest, keyPath: KeyPath, value: bigint) => void; | ||
|
||
export function getIntegerOverflowRequestTransformer(onIntegerOverflow: IntegerOverflowHandler) { | ||
return <TParams>(request: RpcRequest<TParams>): RpcRequest => { | ||
const transformer = getTreeWalkerRequestTransformer( | ||
[getIntegerOverflowNodeVisitor((...args) => onIntegerOverflow(request, ...args))], | ||
{ keyPath: [] }, | ||
); | ||
return transformer(request); | ||
}; | ||
} | ||
|
||
export function getIntegerOverflowNodeVisitor(onIntegerOverflow: (keyPath: KeyPath, value: bigint) => void) { | ||
return <T>(value: T, { keyPath }: TraversalState): T => { | ||
if (typeof value === 'bigint') { | ||
if (onIntegerOverflow && (value > Number.MAX_SAFE_INTEGER || value < -Number.MAX_SAFE_INTEGER)) { | ||
onIntegerOverflow(keyPath as (number | string)[], value); | ||
} | ||
} | ||
return value; | ||
}; | ||
} |
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