fix: renaming
This commit is contained in:
committed by
Michael Vines
parent
daba1a7856
commit
97c07c7b0a
@ -41,9 +41,9 @@ export class SystemInstruction extends TransactionInstruction {
|
|||||||
const instructionTypeLayout = BufferLayout.u32('instruction');
|
const instructionTypeLayout = BufferLayout.u32('instruction');
|
||||||
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
||||||
let type;
|
let type;
|
||||||
for (const t in SystemInstructionEnum) {
|
for (const t in SystemInstructionLayout) {
|
||||||
if (SystemInstructionEnum[t].index == typeIndex) {
|
if (SystemInstructionLayout[t].index == typeIndex) {
|
||||||
type = SystemInstructionEnum[t];
|
type = SystemInstructionLayout[t];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!type) {
|
if (!type) {
|
||||||
@ -63,10 +63,10 @@ export class SystemInstruction extends TransactionInstruction {
|
|||||||
* The `from` public key of the instruction;
|
* The `from` public key of the instruction;
|
||||||
* returns null if SystemInstructionType does not support this field
|
* returns null if SystemInstructionType does not support this field
|
||||||
*/
|
*/
|
||||||
get From(): PublicKey | null {
|
get fromPublicKey(): PublicKey | null {
|
||||||
if (
|
if (
|
||||||
this.type == SystemInstructionEnum.CREATE ||
|
this.type == SystemInstructionLayout.Create ||
|
||||||
this.type == SystemInstructionEnum.TRANSFER
|
this.type == SystemInstructionLayout.Transfer
|
||||||
) {
|
) {
|
||||||
return this.keys[0].pubkey;
|
return this.keys[0].pubkey;
|
||||||
}
|
}
|
||||||
@ -77,10 +77,10 @@ export class SystemInstruction extends TransactionInstruction {
|
|||||||
* The `to` public key of the instruction;
|
* The `to` public key of the instruction;
|
||||||
* returns null if SystemInstructionType does not support this field
|
* returns null if SystemInstructionType does not support this field
|
||||||
*/
|
*/
|
||||||
get To(): PublicKey | null {
|
get toPublicKey(): PublicKey | null {
|
||||||
if (
|
if (
|
||||||
this.type == SystemInstructionEnum.CREATE ||
|
this.type == SystemInstructionLayout.Create ||
|
||||||
this.type == SystemInstructionEnum.TRANSFER
|
this.type == SystemInstructionLayout.Transfer
|
||||||
) {
|
) {
|
||||||
return this.keys[1].pubkey;
|
return this.keys[1].pubkey;
|
||||||
}
|
}
|
||||||
@ -91,11 +91,11 @@ export class SystemInstruction extends TransactionInstruction {
|
|||||||
* The `amount` or `lamports` of the instruction;
|
* The `amount` or `lamports` of the instruction;
|
||||||
* returns null if SystemInstructionType does not support this field
|
* returns null if SystemInstructionType does not support this field
|
||||||
*/
|
*/
|
||||||
get Amount(): number | null {
|
get amount(): number | null {
|
||||||
const data = this.type.layout.decode(this.data);
|
const data = this.type.layout.decode(this.data);
|
||||||
if (this.type == SystemInstructionEnum.TRANSFER) {
|
if (this.type == SystemInstructionLayout.Transfer) {
|
||||||
return data.amount;
|
return data.amount;
|
||||||
} else if (this.type == SystemInstructionEnum.CREATE) {
|
} else if (this.type == SystemInstructionLayout.Create) {
|
||||||
return data.lamports;
|
return data.lamports;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -115,8 +115,8 @@ type SystemInstructionType = {|
|
|||||||
/**
|
/**
|
||||||
* An enumeration of valid SystemInstructionTypes
|
* An enumeration of valid SystemInstructionTypes
|
||||||
*/
|
*/
|
||||||
const SystemInstructionEnum = Object.freeze({
|
const SystemInstructionLayout = Object.freeze({
|
||||||
CREATE: {
|
Create: {
|
||||||
index: 0,
|
index: 0,
|
||||||
layout: BufferLayout.struct([
|
layout: BufferLayout.struct([
|
||||||
BufferLayout.u32('instruction'),
|
BufferLayout.u32('instruction'),
|
||||||
@ -125,14 +125,14 @@ const SystemInstructionEnum = Object.freeze({
|
|||||||
Layout.publicKey('programId'),
|
Layout.publicKey('programId'),
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
ASSIGN: {
|
Assign: {
|
||||||
index: 1,
|
index: 1,
|
||||||
layout: BufferLayout.struct([
|
layout: BufferLayout.struct([
|
||||||
BufferLayout.u32('instruction'),
|
BufferLayout.u32('instruction'),
|
||||||
Layout.publicKey('programId'),
|
Layout.publicKey('programId'),
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
TRANSFER: {
|
Transfer: {
|
||||||
index: 2,
|
index: 2,
|
||||||
layout: BufferLayout.struct([
|
layout: BufferLayout.struct([
|
||||||
BufferLayout.u32('instruction'),
|
BufferLayout.u32('instruction'),
|
||||||
@ -174,7 +174,7 @@ export class SystemProgram {
|
|||||||
space: number,
|
space: number,
|
||||||
programId: PublicKey,
|
programId: PublicKey,
|
||||||
): Transaction {
|
): Transaction {
|
||||||
const type = SystemInstructionEnum.CREATE;
|
const type = SystemInstructionLayout.Create;
|
||||||
const data = encodeData(type, {
|
const data = encodeData(type, {
|
||||||
lamports,
|
lamports,
|
||||||
space,
|
space,
|
||||||
@ -195,7 +195,7 @@ export class SystemProgram {
|
|||||||
* Generate a Transaction that transfers lamports from one account to another
|
* Generate a Transaction that transfers lamports from one account to another
|
||||||
*/
|
*/
|
||||||
static transfer(from: PublicKey, to: PublicKey, amount: number): Transaction {
|
static transfer(from: PublicKey, to: PublicKey, amount: number): Transaction {
|
||||||
const type = SystemInstructionEnum.TRANSFER;
|
const type = SystemInstructionLayout.Transfer;
|
||||||
const data = encodeData(type, {amount});
|
const data = encodeData(type, {amount});
|
||||||
|
|
||||||
return new Transaction().add({
|
return new Transaction().add({
|
||||||
@ -212,7 +212,7 @@ export class SystemProgram {
|
|||||||
* Generate a Transaction that assigns an account to a program
|
* Generate a Transaction that assigns an account to a program
|
||||||
*/
|
*/
|
||||||
static assign(from: PublicKey, programId: PublicKey): Transaction {
|
static assign(from: PublicKey, programId: PublicKey): Transaction {
|
||||||
const type = SystemInstructionEnum.ASSIGN;
|
const type = SystemInstructionLayout.Assign;
|
||||||
const data = encodeData(type, {programId: programId.toBuffer()});
|
const data = encodeData(type, {programId: programId.toBuffer()});
|
||||||
|
|
||||||
return new Transaction().add({
|
return new Transaction().add({
|
||||||
|
@ -67,9 +67,9 @@ test('SystemInstruction create', () => {
|
|||||||
const transaction = new Transaction({recentBlockhash}).add(create);
|
const transaction = new Transaction({recentBlockhash}).add(create);
|
||||||
|
|
||||||
const systemInstruction = SystemInstruction.from(transaction.instructions[0]);
|
const systemInstruction = SystemInstruction.from(transaction.instructions[0]);
|
||||||
expect(systemInstruction.From).toEqual(from.publicKey);
|
expect(systemInstruction.fromPublicKey).toEqual(from.publicKey);
|
||||||
expect(systemInstruction.To).toEqual(to.publicKey);
|
expect(systemInstruction.toPublicKey).toEqual(to.publicKey);
|
||||||
expect(systemInstruction.Amount).toEqual(amount);
|
expect(systemInstruction.amount).toEqual(amount);
|
||||||
expect(systemInstruction.programId).toEqual(SystemProgram.programId);
|
expect(systemInstruction.programId).toEqual(SystemProgram.programId);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -83,9 +83,9 @@ test('SystemInstruction transfer', () => {
|
|||||||
transaction.sign(from);
|
transaction.sign(from);
|
||||||
|
|
||||||
const systemInstruction = SystemInstruction.from(transaction.instructions[0]);
|
const systemInstruction = SystemInstruction.from(transaction.instructions[0]);
|
||||||
expect(systemInstruction.From).toEqual(from.publicKey);
|
expect(systemInstruction.fromPublicKey).toEqual(from.publicKey);
|
||||||
expect(systemInstruction.To).toEqual(to.publicKey);
|
expect(systemInstruction.toPublicKey).toEqual(to.publicKey);
|
||||||
expect(systemInstruction.Amount).toEqual(amount);
|
expect(systemInstruction.amount).toEqual(amount);
|
||||||
expect(systemInstruction.programId).toEqual(SystemProgram.programId);
|
expect(systemInstruction.programId).toEqual(SystemProgram.programId);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -98,9 +98,9 @@ test('SystemInstruction assign', () => {
|
|||||||
transaction.sign(from);
|
transaction.sign(from);
|
||||||
|
|
||||||
const systemInstruction = SystemInstruction.from(transaction.instructions[0]);
|
const systemInstruction = SystemInstruction.from(transaction.instructions[0]);
|
||||||
expect(systemInstruction.From).toBeNull();
|
expect(systemInstruction.fromPublicKey).toBeNull();
|
||||||
expect(systemInstruction.To).toBeNull();
|
expect(systemInstruction.toPublicKey).toBeNull();
|
||||||
expect(systemInstruction.Amount).toBeNull();
|
expect(systemInstruction.amount).toBeNull();
|
||||||
expect(systemInstruction.programId).toEqual(SystemProgram.programId);
|
expect(systemInstruction.programId).toEqual(SystemProgram.programId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user