All files / src kit.ts

100% Statements 10/10
70% Branches 7/10
100% Functions 3/3
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 3338x       1x             1x           9x 9x 9x       59x   58x           1x  
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,
        })
    }
}