fix: add TypeScript buffer type to layout.ts

This commit is contained in:
steveluscher 2022-03-23 21:59:41 -07:00 committed by Steven Luscher
parent b516a25132
commit d34fe3dba3
1 changed files with 23 additions and 10 deletions

View File

@ -4,16 +4,14 @@ import * as BufferLayout from '@solana/buffer-layout';
/** /**
* Layout for a public key * Layout for a public key
*/ */
export const publicKey = ( export const publicKey = (property: string = 'publicKey') => {
property: string = 'publicKey',
): BufferLayout.Layout => {
return BufferLayout.blob(32, property); return BufferLayout.blob(32, property);
}; };
/** /**
* Layout for a 64bit unsigned value * Layout for a 64bit unsigned value
*/ */
export const uint64 = (property: string = 'uint64'): BufferLayout.Layout => { export const uint64 = (property: string = 'uint64') => {
return BufferLayout.blob(8, property); return BufferLayout.blob(8, property);
}; };
@ -59,17 +57,25 @@ export const rustString = (property: string = 'string') => {
* Layout for an Authorized object * Layout for an Authorized object
*/ */
export const authorized = (property: string = 'authorized') => { export const authorized = (property: string = 'authorized') => {
return BufferLayout.struct( return BufferLayout.struct<
[publicKey('staker'), publicKey('withdrawer')], Readonly<{
property, staker: Uint8Array;
); withdrawer: Uint8Array;
}>
>([publicKey('staker'), publicKey('withdrawer')], property);
}; };
/** /**
* Layout for a Lockup object * Layout for a Lockup object
*/ */
export const lockup = (property: string = 'lockup') => { export const lockup = (property: string = 'lockup') => {
return BufferLayout.struct( return BufferLayout.struct<
Readonly<{
custodian: Uint8Array;
epoch: number;
unixTimestamp: number;
}>
>(
[ [
BufferLayout.ns64('unixTimestamp'), BufferLayout.ns64('unixTimestamp'),
BufferLayout.ns64('epoch'), BufferLayout.ns64('epoch'),
@ -83,7 +89,14 @@ export const lockup = (property: string = 'lockup') => {
* Layout for a VoteInit object * Layout for a VoteInit object
*/ */
export const voteInit = (property: string = 'voteInit') => { export const voteInit = (property: string = 'voteInit') => {
return BufferLayout.struct( return BufferLayout.struct<
Readonly<{
authorizedVoter: Uint8Array;
authorizedWithdrawer: Uint8Array;
commission: number;
nodePubkey: Uint8Array;
}>
>(
[ [
publicKey('nodePubkey'), publicKey('nodePubkey'),
publicKey('authorizedVoter'), publicKey('authorizedVoter'),