reallocate.ts 3.2 KB

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