Browse Source

ts: Add associated client code (#626)

Armani Ferrante 4 years ago
parent
commit
3be29425ac
1 changed files with 19 additions and 0 deletions
  1. 19 0
      ts/src/program/namespace/account.ts

+ 19 - 0
ts/src/program/namespace/account.ts

@@ -241,6 +241,25 @@ export class AccountClient {
       programId: this._programId,
     });
   }
+
+  /**
+   * Function returning the associated account. Args are keys to associate.
+   * Order matters.
+   */
+  async associated(...args: Array<PublicKey | Buffer>): Promise<any> {
+    const addr = await this.associatedAddress(...args);
+    return await this.fetch(addr);
+  }
+
+  /**
+   * Function returning the associated address. Args are keys to associate.
+   * Order matters.
+   */
+  async associatedAddress(
+    ...args: Array<PublicKey | Buffer>
+  ): Promise<PublicKey> {
+    return await pubkeyUtil.associated(this._programId, ...args);
+  }
 }
 
 /**