This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(experimental): revise transactions schema (Part 1)
This PR introduces a revised transaction schema for GraphQL.⚠️ ‼️ Note: This is only a _light_ revision to the transaction schema. It will be _massively_ easier to review schema changes once the next PR in this stack is merged, and the types are written in pure GraphQL lang.
- Loading branch information
1 parent
e6fc977
commit e662875
Showing
8 changed files
with
173 additions
and
236 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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { SolanaRpcMethods } from '@solana/rpc-core'; | ||
import { Rpc } from '@solana/rpc-transport/dist/types/json-rpc-types'; | ||
|
||
import { GraphQLCache } from '../cache'; | ||
import { BlockQueryArgs } from '../schema/block'; | ||
|
||
export async function resolveBlock( | ||
{ slot, encoding = 'jsonParsed', ...config }: BlockQueryArgs, | ||
cache: GraphQLCache, | ||
rpc: Rpc<SolanaRpcMethods> | ||
) { | ||
const requestConfig = { encoding, ...config }; | ||
|
||
const cached = cache.get(slot, config); | ||
if (cached !== null) { | ||
return cached; | ||
} | ||
|
||
const block = await rpc | ||
.getBlock(slot, requestConfig as unknown as Parameters<SolanaRpcMethods['getBlock']>[1]) | ||
.send(); | ||
|
||
if (block === null) { | ||
return null; | ||
} | ||
|
||
cache.insert(slot, config, block); | ||
|
||
return block; | ||
} |
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,51 @@ | ||
import { SolanaRpcMethods } from '@solana/rpc-core'; | ||
import { Rpc } from '@solana/rpc-transport/dist/types/json-rpc-types'; | ||
|
||
import { GraphQLCache } from '../cache'; | ||
import { TransactionQueryArgs } from '../schema/transaction'; | ||
|
||
export async function resolveTransaction( | ||
{ signature, encoding = 'jsonParsed', ...config }: TransactionQueryArgs, | ||
cache: GraphQLCache, | ||
rpc: Rpc<SolanaRpcMethods> | ||
) { | ||
const requestConfig = { encoding, ...config }; | ||
|
||
const cached = cache.get(signature, requestConfig); | ||
if (cached !== null) { | ||
return cached; | ||
} | ||
|
||
const transaction = await rpc | ||
.getTransaction(signature, requestConfig as unknown as Parameters<SolanaRpcMethods['getTransaction']>[1]) | ||
.send(); | ||
|
||
if (transaction === null) { | ||
return null; | ||
} | ||
|
||
const [transactionData, responseEncoding, responseFormat] = Array.isArray(transaction.transaction) | ||
? encoding === 'jsonParsed' | ||
? [transaction.transaction[0], 'base64', 'unparsed'] | ||
: [transaction.transaction[0], encoding, 'unparsed'] | ||
: encoding === 'jsonParsed' | ||
? [transaction.transaction, encoding, 'parsed'] | ||
: [transaction.transaction, encoding, 'unparsed']; | ||
if (transaction.meta) { | ||
// Ugly, but tells TypeScript what's happening | ||
(transaction.meta as { format?: string } & { [key: string]: unknown })['format'] = responseFormat; | ||
} | ||
if (transactionData.message) { | ||
// Ugly, but tells TypeScript what's happening | ||
(transactionData.message as { format?: string } & { [key: string]: unknown })['format'] = responseFormat; | ||
} | ||
const queryResponse = { | ||
...transaction, | ||
encoding: responseEncoding, | ||
transaction: transactionData, | ||
}; | ||
|
||
cache.insert(signature, requestConfig, queryResponse); | ||
|
||
return queryResponse; | ||
} |
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
Oops, something went wrong.