address-info.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import * as borsh from "borsh";
  2. import { Buffer } from "buffer";
  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. [ AddressInfo, {
  31. kind: 'struct',
  32. fields: [
  33. ['name', 'string'],
  34. ['house_number', 'u8'],
  35. ['street', 'string'],
  36. ['city', 'string'],
  37. ],
  38. }]
  39. ]);