Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blockchain specific account loading #15

Merged
merged 16 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
"prepare": "make"
},
"dependencies": {
"@wharfkit/antelope": "^0.7.3",
"@wharfkit/antelope": "^0.10.1",
"@wharfkit/common": "^1.2.0-rc4",
"@wharfkit/contract": "^0.4.3",
"@wharfkit/resources": "^1.0.0",
"tslib": "^2.1.0"
},
"resolutions": {
"@wharfkit/antelope": "^0.7.3"
"@wharfkit/antelope": "^0.10.1"
},
"devDependencies": {
"@rollup/plugin-alias": "^4.0.2",
Expand Down
10 changes: 5 additions & 5 deletions src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {Permission} from './permission'
import * as SystemContract from './contracts/eosio'
import {Resource, ResourceType} from './resource'

export interface AccountArgs {
export interface AccountArgs<Data extends API.v1.AccountObject = API.v1.AccountObject> {
client: APIClient
contract?: Contract
data: API.v1.AccountObject
data: Data
}

export interface BuyramOptions {
Expand All @@ -40,12 +40,12 @@ export interface UndelegateOptions {
net?: AssetType
}

export class Account {
readonly data: API.v1.AccountObject
export class Account<Data extends API.v1.AccountObject = API.v1.AccountObject> {
readonly data: Data
readonly systemContract: SystemContract.Contract
readonly client: APIClient

constructor(args: AccountArgs) {
constructor(args: AccountArgs<Data>) {
this.data = args.data
if (args.contract) {
this.systemContract = args.contract
Expand Down
31 changes: 15 additions & 16 deletions src/kit.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import {APIClient, Name, NameType} from '@wharfkit/antelope'
import {API, APIClient, NameType} from '@wharfkit/antelope'
import {Contract} from '@wharfkit/contract'
import {ChainDefinition} from '@wharfkit/common'

import {Account} from './account'

export interface AccountKitArgs {
client: APIClient
interface AccountKitOptions {
contract?: Contract
client?: APIClient
}

export class AccountKit {
export class AccountKit<DataType extends API.v1.AccountObject = API.v1.AccountObject> {
readonly chain: ChainDefinition<DataType>
readonly client: APIClient
readonly contract?: Contract

constructor(args: AccountKitArgs) {
if (args.contract) {
this.contract = args.contract
}
if (args.client) {
this.client = args.client
} else {
throw new Error('A `client` must be passed when initializing the AccountKit.')
}
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> {
return new Account({
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: await this.client.v1.chain.get_account(accountName),
data: data as DataType,
})
}
}
85 changes: 0 additions & 85 deletions test/data/1343515aa85d3148aedc98f52cbc3706fc33e53b.json

This file was deleted.

Loading
Loading