Skip to content

Commit

Permalink
refactor(experimental): add info field to JSON parsed types (#2072)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcintyre94 authored Jan 29, 2024
1 parent 76ad167 commit 495a9b1
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { StringifiedBigInt } from '@solana/rpc-types';
import { JsonParsedAddressLookupTableAccount } from '../address-lookup-table-accounts';

const account = {
addresses: [
'F1Vc6AGoxXLwGB7QV8f4So3C5d8SXEk3KKGHxKGEJ8qn' as Address,
'FWscgV4VDSsMxkQg7jZ4HksqjLyadJS5RiCnAVZv2se9' as Address,
],
authority: '4msgK65vdz5ADUAB3eTQGpF388NuQUAoknLxutUQJd5B' as Address,
deactivationSlot: '204699277' as StringifiedBigInt,
lastExtendedSlot: '204699234' as StringifiedBigInt,
lastExtendedSlotStartIndex: 20,
info: {
addresses: [
'F1Vc6AGoxXLwGB7QV8f4So3C5d8SXEk3KKGHxKGEJ8qn' as Address,
'FWscgV4VDSsMxkQg7jZ4HksqjLyadJS5RiCnAVZv2se9' as Address,
],
authority: '4msgK65vdz5ADUAB3eTQGpF388NuQUAoknLxutUQJd5B' as Address,
deactivationSlot: '204699277' as StringifiedBigInt,
lastExtendedSlot: '204699234' as StringifiedBigInt,
lastExtendedSlotStartIndex: 20,
},
};

account satisfies JsonParsedAddressLookupTableAccount;
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { JsonParsedNonceAccount } from '../nonce-accounts';

{
const account = {
authority: '3xxDCjN8s6MgNHwdRExRLa6gHmmRTWPnUdzkbKfEgNAe' as Address,
blockhash: 'TcVy2wVcs7WqWVopv8LAJBHQfqVYZrm8UDqjDvBFQt8' as Blockhash,
feeCalculator: {
lamportsPerSignature: '5000' as StringifiedBigInt,
info: {
authority: '3xxDCjN8s6MgNHwdRExRLa6gHmmRTWPnUdzkbKfEgNAe' as Address,
blockhash: 'TcVy2wVcs7WqWVopv8LAJBHQfqVYZrm8UDqjDvBFQt8' as Blockhash,
feeCalculator: {
lamportsPerSignature: '5000' as StringifiedBigInt,
},
},
};
account satisfies JsonParsedNonceAccount;
Expand Down
72 changes: 37 additions & 35 deletions packages/rpc-parsed-types/src/__typetests__/vote-accounts-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,45 @@ import { Epoch, Slot, StringifiedBigInt, UnixTimestamp } from '@solana/rpc-types
import { JsonParsedVoteAccount } from '../vote-accounts';

const account = {
authorizedVoters: [
{
authorizedVoter: 'HMU77m6WSL9Xew9YvVCgz1hLuhzamz74eD9avi4XPdr' as Address,
epoch: 529n as Epoch,
info: {
authorizedVoters: [
{
authorizedVoter: 'HMU77m6WSL9Xew9YvVCgz1hLuhzamz74eD9avi4XPdr' as Address,
epoch: 529n as Epoch,
},
],
authorizedWithdrawer: 'HMU77m6WSL9Xew9YvVCgz1hLuhzamz74eD9avi4XPdr' as Address,
commission: 50,
epochCredits: [
{
credits: '68697256' as StringifiedBigInt,
epoch: 466n as Epoch,
previousCredits: '68325825' as StringifiedBigInt,
},
{
credits: '69068118' as StringifiedBigInt,
epoch: 467n as Epoch,
previousCredits: '68697256' as StringifiedBigInt,
},
],
lastTimestamp: {
slot: 228884530n as Slot,
timestamp: 1689090220 as UnixTimestamp,
},
],
authorizedWithdrawer: 'HMU77m6WSL9Xew9YvVCgz1hLuhzamz74eD9avi4XPdr' as Address,
commission: 50,
epochCredits: [
{
credits: '68697256' as StringifiedBigInt,
epoch: 466n as Epoch,
previousCredits: '68325825' as StringifiedBigInt,
},
{
credits: '69068118' as StringifiedBigInt,
epoch: 467n as Epoch,
previousCredits: '68697256' as StringifiedBigInt,
},
],
lastTimestamp: {
slot: 228884530n as Slot,
timestamp: 1689090220 as UnixTimestamp,
nodePubkey: 'HMU77m6WSL9Xew9YvVCgz1hLuhzamz74eD9avi4XPdr' as Address,
priorVoters: [],
rootSlot: 228884499n as Slot,
votes: [
{
confirmationCount: 31,
slot: 228884500n as Slot,
},
{
confirmationCount: 30,
slot: 228884501n as Slot,
},
],
},
nodePubkey: 'HMU77m6WSL9Xew9YvVCgz1hLuhzamz74eD9avi4XPdr' as Address,
priorVoters: [],
rootSlot: 228884499n as Slot,
votes: [
{
confirmationCount: 31,
slot: 228884500n as Slot,
},
{
confirmationCount: 30,
slot: 228884501n as Slot,
},
],
};

account satisfies JsonParsedVoteAccount;
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { Address } from '@solana/addresses';
import type { StringifiedBigInt } from '@solana/rpc-types';

export type JsonParsedAddressLookupTableAccount = Readonly<{
import { RpcParsedInfo } from './rpc-parsed-type';

export type JsonParsedAddressLookupTableAccount = RpcParsedInfo<{
addresses: readonly Address[];
authority?: Address;
deactivationSlot: StringifiedBigInt;
Expand Down
4 changes: 3 additions & 1 deletion packages/rpc-parsed-types/src/nonce-accounts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Address } from '@solana/addresses';
import type { Blockhash, StringifiedBigInt } from '@solana/rpc-types';

export type JsonParsedNonceAccount = Readonly<{
import { RpcParsedInfo } from './rpc-parsed-type';

export type JsonParsedNonceAccount = RpcParsedInfo<{
authority: Address;
blockhash: Blockhash;
feeCalculator: Readonly<{
Expand Down
4 changes: 4 additions & 0 deletions packages/rpc-parsed-types/src/rpc-parsed-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ export type RpcParsedType<TType extends string, TInfo> = Readonly<{
info: TInfo;
type: TType;
}>;

export type RpcParsedInfo<TInfo> = Readonly<{
info: TInfo;
}>;
4 changes: 3 additions & 1 deletion packages/rpc-parsed-types/src/vote-accounts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Address } from '@solana/addresses';
import { Epoch, Slot, StringifiedBigInt, UnixTimestamp } from '@solana/rpc-types';

export type JsonParsedVoteAccount = Readonly<{
import { RpcParsedInfo } from './rpc-parsed-type';

export type JsonParsedVoteAccount = RpcParsedInfo<{
authorizedVoters: Readonly<{
authorizedVoter: Address;
epoch: Epoch;
Expand Down

0 comments on commit 495a9b1

Please sign in to comment.