-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkit.ts
32 lines (26 loc) · 1.01 KB
/
kit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {API, APIClient, NameType} from '@wharfkit/antelope'
import {Contract} from '@wharfkit/contract'
import {ChainDefinition} from '@wharfkit/common'
import {Account} from './account'
interface AccountKitOptions {
contract?: Contract
client?: APIClient
}
export class AccountKit<DataType extends API.v1.AccountObject = API.v1.AccountObject> {
readonly chain: ChainDefinition<DataType>
readonly client: APIClient
readonly contract?: Contract
constructor(chain: ChainDefinition<DataType>, options?: AccountKitOptions) {
this.chain = chain
this.contract = options?.contract
this.client = options?.client || new APIClient({url: this.chain.url})
}
async load(accountName: NameType): Promise<Account<DataType>> {
const data = await this.client.v1.chain.get_account(accountName, this.chain.accountDataType)
return new Account<DataType>({
client: this.client,
contract: this.contract,
data: data as DataType,
})
}
}