fix: update stake program api

This commit is contained in:
Justin Starry
2020-02-03 16:57:05 +08:00
committed by Michael Vines
parent 3482953757
commit 7181d3aeea
3 changed files with 7 additions and 58 deletions

View File

@ -247,10 +247,6 @@ declare module '@solana/web3.js' {
newAuthorized: PublicKey, newAuthorized: PublicKey,
stakeAuthorizationType: StakeAuthorizationType, stakeAuthorizationType: StakeAuthorizationType,
): Transaction; ): Transaction;
static redeemVoteCredits(
stakeAccount: PublicKey,
votePubkey: PublicKey,
): Transaction;
static split( static split(
stakeAccount: PublicKey, stakeAccount: PublicKey,
authorizedPubkey: PublicKey, authorizedPubkey: PublicKey,

View File

@ -123,26 +123,22 @@ export const StakeInstructionLayout = Object.freeze({
index: 2, index: 2,
layout: BufferLayout.struct([BufferLayout.u32('instruction')]), layout: BufferLayout.struct([BufferLayout.u32('instruction')]),
}, },
RedeemVoteCredits: {
index: 3,
layout: BufferLayout.struct([BufferLayout.u32('instruction')]),
},
Split: { Split: {
index: 4, index: 3,
layout: BufferLayout.struct([ layout: BufferLayout.struct([
BufferLayout.u32('instruction'), BufferLayout.u32('instruction'),
BufferLayout.ns64('lamports'), BufferLayout.ns64('lamports'),
]), ]),
}, },
Withdraw: { Withdraw: {
index: 5, index: 4,
layout: BufferLayout.struct([ layout: BufferLayout.struct([
BufferLayout.u32('instruction'), BufferLayout.u32('instruction'),
BufferLayout.ns64('lamports'), BufferLayout.ns64('lamports'),
]), ]),
}, },
Deactivate: { Deactivate: {
index: 6, index: 5,
layout: BufferLayout.struct([BufferLayout.u32('instruction')]), layout: BufferLayout.struct([BufferLayout.u32('instruction')]),
}, },
}); });
@ -202,7 +198,7 @@ export class StakeProgram {
* Max space of a Stake account * Max space of a Stake account
*/ */
static get space(): number { static get space(): number {
return 2008; return 4008;
} }
/** /**
@ -301,8 +297,9 @@ export class StakeProgram {
{pubkey: stakeAccount, isSigner: false, isWritable: true}, {pubkey: stakeAccount, isSigner: false, isWritable: true},
{pubkey: votePubkey, isSigner: false, isWritable: false}, {pubkey: votePubkey, isSigner: false, isWritable: false},
{pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false}, {pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false},
{pubkey: SYSVAR_STAKE_HISTORY_PUBKEY, isSigner: false, isWritable: false},
{pubkey: STAKE_CONFIG_ID, isSigner: false, isWritable: false}, {pubkey: STAKE_CONFIG_ID, isSigner: false, isWritable: false},
{pubkey: authorizedPubkey, isSigner: true, isWritable: false}, {pubkey: authorizedPubkey, isSigner: true, isWritable: false}
], ],
programId: this.programId, programId: this.programId,
data, data,
@ -336,38 +333,6 @@ export class StakeProgram {
}); });
} }
/**
* Generate a Transaction that authorizes a new PublicKey as Staker
* or Withdrawer on the Stake account.
*/
static redeemVoteCredits(
stakeAccount: PublicKey,
votePubkey: PublicKey,
): Transaction {
const type = StakeInstructionLayout.RedeemVoteCredits;
const data = encodeData(type);
return new Transaction().add({
keys: [
{pubkey: stakeAccount, isSigner: false, isWritable: true},
{pubkey: votePubkey, isSigner: false, isWritable: true},
{
pubkey: RewardsPoolPublicKey.randomId(),
isSigner: false,
isWritable: true,
},
{pubkey: SYSVAR_REWARDS_PUBKEY, isSigner: false, isWritable: false},
{
pubkey: SYSVAR_STAKE_HISTORY_PUBKEY,
isSigner: false,
isWritable: false,
},
],
programId: this.programId,
data,
});
}
/** /**
* Generate a Transaction that splits Stake tokens into another stake account * Generate a Transaction that splits Stake tokens into another stake account
*/ */

View File

@ -87,7 +87,7 @@ test('delegate', () => {
vote.publicKey, vote.publicKey,
); );
expect(transaction.keys).toHaveLength(5); expect(transaction.keys).toHaveLength(6);
expect(transaction.programId).toEqual(StakeProgram.programId); expect(transaction.programId).toEqual(StakeProgram.programId);
// TODO: Validate transaction contents more // TODO: Validate transaction contents more
}); });
@ -111,18 +111,6 @@ test('authorize', () => {
// TODO: Validate transaction contents more // TODO: Validate transaction contents more
}); });
test('redeemVoteCredits', () => {
const stake = new Account();
const vote = new Account();
let transaction;
transaction = StakeProgram.redeemVoteCredits(stake.publicKey, vote.publicKey);
expect(transaction.keys).toHaveLength(5);
expect(transaction.programId).toEqual(StakeProgram.programId);
// TODO: Validate transaction contents more
});
test('split', () => { test('split', () => {
const stake = new Account(); const stake = new Account();
const authorized = new Account(); const authorized = new Account();