reallocate.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import * as borsh from "borsh";
  2. import { Buffer } from "buffer";
  3. import {
  4. PublicKey,
  5. SystemProgram,
  6. TransactionInstruction
  7. } from '@solana/web3.js';
  8. import { ReallocInstruction } from './instruction';
  9. export class ReallocateWithoutZeroInit {
  10. instruction: ReallocInstruction;
  11. state: string;
  12. zip: number;
  13. constructor(props: {
  14. instruction: ReallocInstruction,
  15. state: string,
  16. zip: number,
  17. }) {
  18. this.instruction = props.instruction;
  19. this.state = props.state;
  20. this.zip = props.zip;
  21. }
  22. toBuffer() {
  23. return Buffer.from(borsh.serialize(ReallocateWithoutZeroInitSchema, this))
  24. };
  25. static fromBuffer(buffer: Buffer) {
  26. return borsh.deserialize(ReallocateWithoutZeroInitSchema, ReallocateWithoutZeroInit, buffer);
  27. };
  28. };
  29. export const ReallocateWithoutZeroInitSchema = new Map([
  30. [ ReallocateWithoutZeroInit, {
  31. kind: 'struct',
  32. fields: [
  33. ['instruction', 'u8'],
  34. ['state', 'string'],
  35. ['zip', 'u32'],
  36. ],
  37. }]
  38. ]);
  39. export function createReallocateWithoutZeroInitInstruction(
  40. target: PublicKey,
  41. payer: PublicKey,
  42. programId: PublicKey,
  43. state: string,
  44. zip: number,
  45. ): TransactionInstruction {
  46. const instructionObject = new ReallocateWithoutZeroInit({
  47. instruction: ReallocInstruction.ReallocateWithoutZeroInit,
  48. state,
  49. zip,
  50. });
  51. const ix = new TransactionInstruction({
  52. keys: [
  53. {pubkey: target, isSigner: false, isWritable: true},
  54. {pubkey: payer, isSigner: true, isWritable: true},
  55. {pubkey: SystemProgram.programId, isSigner: false, isWritable: false}
  56. ],
  57. programId: programId,
  58. data: instructionObject.toBuffer(),
  59. });
  60. return ix;
  61. }
  62. export class ReallocateZeroInit {
  63. instruction: ReallocInstruction;
  64. name: string;
  65. position: string;
  66. company: string;
  67. years_employed: number;
  68. constructor(props: {
  69. instruction: ReallocInstruction,
  70. name: string,
  71. position: string,
  72. company: string,
  73. years_employed: number,
  74. }) {
  75. this.instruction = props.instruction;
  76. this.name = props.name;
  77. this.position = props.position;
  78. this.company = props.company;
  79. this.years_employed = props.years_employed;
  80. }
  81. toBuffer() {
  82. return Buffer.from(borsh.serialize(ReallocateZeroInitSchema, this))
  83. };
  84. static fromBuffer(buffer: Buffer) {
  85. return borsh.deserialize(ReallocateZeroInitSchema, ReallocateZeroInit, buffer);
  86. };
  87. };
  88. export const ReallocateZeroInitSchema = new Map([
  89. [ ReallocateZeroInit, {
  90. kind: 'struct',
  91. fields: [
  92. ['instruction', 'u8'],
  93. ['name', 'string'],
  94. ['position', 'string'],
  95. ['company', 'string'],
  96. ['years_employed', 'u8'],
  97. ],
  98. }]
  99. ]);
  100. export function createReallocateZeroInitInstruction(
  101. target: PublicKey,
  102. payer: PublicKey,
  103. programId: PublicKey,
  104. name: string,
  105. position: string,
  106. company: string,
  107. years_employed: number,
  108. ): TransactionInstruction {
  109. const instructionObject = new ReallocateZeroInit({
  110. instruction: ReallocInstruction.ReallocateZeroInit,
  111. name,
  112. position,
  113. company,
  114. years_employed,
  115. });
  116. const ix = new TransactionInstruction({
  117. keys: [
  118. {pubkey: target, isSigner: false, isWritable: true},
  119. ],
  120. programId: programId,
  121. data: instructionObject.toBuffer(),
  122. });
  123. return ix;
  124. }