enhanced-address-info.ts 1.3 KB

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