Skip to content

Commit

Permalink
chore: addec accountDataType to ChainDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Oct 13, 2023
1 parent b6a5a7f commit f4fdb6e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"tslib": "^2.1.0"
},
"peerDependencies": {
"@wharfkit/antelope": "^0.9.1"
"@wharfkit/antelope": "^0.10.1"
},
"devDependencies": {
"@babel/preset-env": "^7.20.2",
Expand Down
46 changes: 38 additions & 8 deletions src/common/chains.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Checksum256, Checksum256Type, Struct} from '@wharfkit/antelope'
import {API, Checksum256, Checksum256Type, Float64, Int64, Struct, TimePoint} from '@wharfkit/antelope'

import {ExplorerDefinition} from './explorer'
import {Logo} from './logo'
Expand All @@ -9,7 +9,7 @@ import type {ExplorerDefinitionType, LogoType} from './types'
* The information required to interact with a given chain.
*/
@Struct.type('chain_definition')
export class ChainDefinition extends Struct {
export class ChainDefinition<AccountDataType extends API.v1.AccountObject = API.v1.AccountObject> extends Struct {
/**
* The chain ID.
*/
Expand All @@ -30,12 +30,17 @@ export class ChainDefinition extends Struct {
*/
@Struct.field(ExplorerDefinition, {optional: true}) declare explorer?: ExplorerDefinitionType

static from(data) {
/**
* The account data type for the chain.
*/
@Struct.field(typeof API.v1.AccountObject) declare accountDataType: typeof API.v1.AccountObject

static from<AccountDataType extends API.v1.AccountObject = API.v1.AccountObject>(data) {
return super.from({
...data,
explorer: data.explorer ? ExplorerDefinition.from(data.explorer) : undefined,
logo: data.logo ? Logo.from(data.logo) : undefined,
}) as ChainDefinition
}) as ChainDefinition<AccountDataType>
}

get name() {
Expand Down Expand Up @@ -100,6 +105,31 @@ export const ChainNames: Record<ChainIndices, string> = {
UX: 'UX Network',
}


@Struct.type('telos_account_voter_info')
export class TelosAccountVoterInfo extends API.v1.AccountVoterInfo {
@Struct.field(Int64) last_stake!: Int64
}

@Struct.type('telos_account_object')
export class TelosAccountObject extends API.v1.AccountObject {
@Struct.field(TelosAccountVoterInfo, {optional: true})
declare voter_info?: TelosAccountVoterInfo
}

@Struct.type('wax_account_voter_info')
export class WAXAccountVoterInfo extends API.v1.AccountVoterInfo {
@Struct.field(Float64) declare unpaid_voteshare: Float64
@Struct.field(TimePoint) declare unpaid_voteshare_last_updated: TimePoint
@Struct.field(Float64) declare unpaid_voteshare_change_rate: Float64
@Struct.field(TimePoint) declare last_claim_time: TimePoint
}

@Struct.type('wax_account_object')
export class WAXAccountObject extends API.v1.AccountObject {
@Struct.field(WAXAccountVoterInfo, {optional: true}) declare voter_info?: WAXAccountVoterInfo
}

/**
* An exported list of ChainDefinition entries for select chains.
*/
Expand Down Expand Up @@ -160,27 +190,27 @@ export const Chains: Record<ChainIndices, ChainDefinition> = {
id: '71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd',
url: 'https://proton-testnet.greymass.com',
}),
Telos: ChainDefinition.from({
Telos: ChainDefinition.from<TelosAccountObject>({
id: '4667b205c6838ef70ff7988f6e8257e8be0e1284a2f59699054a018f743b1d11',
url: 'https://telos.greymass.com',
explorer: {
prefix: 'https://explorer.telos.net/transaction/',
suffix: '',
},
}),
TelosTestnet: ChainDefinition.from({
TelosTestnet: ChainDefinition.from<TelosAccountObject>({
id: '1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f',
url: 'https://telostestnet.greymass.com',
}),
WAX: ChainDefinition.from({
WAX: ChainDefinition.from<WAXAccountObject>({
id: '1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4',
url: 'https://wax.greymass.com',
explorer: {
prefix: 'https://waxblock.io/transaction/',
suffix: '',
},
}),
WAXTestnet: ChainDefinition.from({
WAXTestnet: ChainDefinition.from<WAXAccountObject>({
id: 'f16b1833c747c43682f4386fca9cbb327929334a762755ebec17f6f23c9b8a12',
url: 'https://waxtestnet.greymass.com',
}),
Expand Down

0 comments on commit f4fdb6e

Please sign in to comment.