fix: optional stake lockup field parameters (#16943)

* fix: optional stake lockup field parameters

* chore: update web3.js/src/stake-program.ts

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>

* chore: prettier

Co-authored-by: Justin Starry <justin.m.starry@gmail.com>
Co-authored-by: Justin Starry <justin@solana.com>
This commit is contained in:
Trent Nelson 2021-04-29 08:04:33 -06:00 committed by GitHub
parent 90641ad28b
commit a2fbb9cfef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View File

@ -39,6 +39,11 @@ export class PublicKey {
} }
} }
/**
* Default public key value. (All zeros)
*/
static default: PublicKey = new PublicKey('11111111111111111111111111111111');
/** /**
* Checks if two publicKeys are equal * Checks if two publicKeys are equal
*/ */

View File

@ -59,6 +59,11 @@ export class Lockup {
this.epoch = epoch; this.epoch = epoch;
this.custodian = custodian; this.custodian = custodian;
} }
/**
* Default, inactive Lockup value
*/
static default: Lockup = new Lockup(0, 0, PublicKey.default);
} }
/** /**
@ -72,7 +77,7 @@ export type CreateStakeAccountParams = {
/** Authorities of the new stake account */ /** Authorities of the new stake account */
authorized: Authorized; authorized: Authorized;
/** Lockup of the new stake account */ /** Lockup of the new stake account */
lockup: Lockup; lockup?: Lockup;
/** Funding amount */ /** Funding amount */
lamports: number; lamports: number;
}; };
@ -86,7 +91,7 @@ export type CreateStakeAccountWithSeedParams = {
basePubkey: PublicKey; basePubkey: PublicKey;
seed: string; seed: string;
authorized: Authorized; authorized: Authorized;
lockup: Lockup; lockup?: Lockup;
lamports: number; lamports: number;
}; };
@ -96,7 +101,7 @@ export type CreateStakeAccountWithSeedParams = {
export type InitializeStakeParams = { export type InitializeStakeParams = {
stakePubkey: PublicKey; stakePubkey: PublicKey;
authorized: Authorized; authorized: Authorized;
lockup: Lockup; lockup?: Lockup;
}; };
/** /**
@ -502,7 +507,8 @@ export class StakeProgram {
* Generate an Initialize instruction to add to a Stake Create transaction * Generate an Initialize instruction to add to a Stake Create transaction
*/ */
static initialize(params: InitializeStakeParams): TransactionInstruction { static initialize(params: InitializeStakeParams): TransactionInstruction {
const {stakePubkey, authorized, lockup} = params; const {stakePubkey, authorized, lockup: maybeLockup} = params;
const lockup: Lockup = maybeLockup || Lockup.default;
const type = STAKE_INSTRUCTION_LAYOUTS.Initialize; const type = STAKE_INSTRUCTION_LAYOUTS.Initialize;
const data = encodeData(type, { const data = encodeData(type, {
authorized: { authorized: {

View File

@ -367,7 +367,6 @@ describe('StakeProgram', () => {
authorized.publicKey, authorized.publicKey,
authorized.publicKey, authorized.publicKey,
), ),
lockup: new Lockup(0, 0, new PublicKey(0)),
lamports: minimumAmount + 42, lamports: minimumAmount + 42,
}); });