work-info.ts 972 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { Buffer } from 'node:buffer';
  2. import * as borsh from 'borsh';
  3. export class WorkInfo {
  4. name: string;
  5. position: string;
  6. company: string;
  7. years_employed: number;
  8. constructor(props: {
  9. name: string;
  10. position: string;
  11. company: string;
  12. years_employed: number;
  13. }) {
  14. this.name = props.name;
  15. this.position = props.position;
  16. this.company = props.company;
  17. this.years_employed = props.years_employed;
  18. }
  19. toBase58() {
  20. return borsh.serialize(WorkInfoSchema, this).toString();
  21. }
  22. toBuffer() {
  23. return Buffer.from(borsh.serialize(WorkInfoSchema, this));
  24. }
  25. static fromBuffer(buffer: Buffer) {
  26. return borsh.deserialize(WorkInfoSchema, WorkInfo, buffer);
  27. }
  28. }
  29. export const WorkInfoSchema = new Map([
  30. [
  31. WorkInfo,
  32. {
  33. kind: 'struct',
  34. fields: [
  35. ['name', 'string'],
  36. ['position', 'string'],
  37. ['company', 'string'],
  38. ['years_employed', 'u8'],
  39. ],
  40. },
  41. ],
  42. ]);