address-info.ts 958 B

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