Skip to content

Commit

Permalink
refactor: explorer rest typing
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRalee committed Sep 4, 2024
1 parent 737684f commit b49ea43
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 127 deletions.
34 changes: 17 additions & 17 deletions packages/sdk-ts/src/client/indexer/rest/IndexerRestExplorerApi.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { MsgStatus, MsgType } from '@injectivelabs/ts-types'
import BaseRestConsumer from '../../base/BaseRestConsumer'
import {
HttpRequestException,
UnspecifiedErrorCode,
} from '@injectivelabs/exceptions'
import {
Paging,
Contract,
WasmCode,
BankTransfer,
ExplorerTransaction,
ExplorerApiResponse,
ContractTransaction,
ExplorerBlockWithTxs,
ExplorerValidatorUptime,
ExplorerCW20BalanceWithToken,
ContractTransactionWithMessages,
} from '../types/explorer'
import {
ExplorerApiResponse,
ContractExplorerApiResponse,
WasmCodeExplorerApiResponse,
BlockFromExplorerApiResponse,
CW20BalanceExplorerApiResponse,
ExplorerApiResponseWithPagination,
TransactionFromExplorerApiResponse,
BankTransferFromExplorerApiResponse,
ValidatorUptimeFromExplorerApiResponse,
ContractTransactionExplorerApiResponse,
WasmCodeExplorerApiResponse,
} from '../types/explorer-rest'
import {
Contract,
WasmCode,
BankTransfer,
ContractTransaction,
ExplorerCW20BalanceWithToken,
BankTransferFromExplorerApiResponse,
ContractTransactionWithMessages,
} from '../types/explorer'
import {
HttpRequestException,
UnspecifiedErrorCode,
} from '@injectivelabs/exceptions'
import { IndexerRestExplorerTransformer } from '../transformers'
import BaseRestConsumer from '../../base/BaseRestConsumer'
import { Block, ExplorerValidator } from '../types/explorer'
import { IndexerRestExplorerTransformer } from '../transformers'
import { IndexerModule } from '../types'

const explorerEndpointSuffix = 'api/explorer/v1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { BigNumberInBase, BigNumberInWei } from '@injectivelabs/utils'
import {
Contract,
WasmCode,
Transaction,
CW20Message,
BankTransfer,
ExplorerTransaction,
ContractTransaction,
ExplorerBlockWithTxs,
ExplorerValidatorUptime,
ExplorerCW20BalanceWithToken,
} from '../types/explorer'
import {
Block,
ContractTransactionWithMessages,
ExplorerValidator,
ContractTransactionWithMessages,
} from '../types/explorer'
import { TokenType, TokenVerification } from '../../../types/token'
import {
BaseTransaction,
BlockFromExplorerApiResponse,
ContractExplorerApiResponse,
ContractTransactionExplorerApiResponse,
WasmCodeExplorerApiResponse,
BlockFromExplorerApiResponse,
CW20BalanceExplorerApiResponse,
ExplorerBlockWithTxs,
ExplorerTransaction,
ExplorerValidatorUptime,
TransactionFromExplorerApiResponse,
BankTransferFromExplorerApiResponse,
ContractTransactionExplorerApiResponse,
ValidatorUptimeFromExplorerApiResponse,
WasmCodeExplorerApiResponse,
} from '../types/explorer-rest'
import {
Contract,
WasmCode,
CW20Message,
BankTransfer,
ContractTransaction,
ExplorerCW20BalanceWithToken,
BankTransferFromExplorerApiResponse,
} from '../types/explorer'
import { TokenType, TokenVerification } from '../../../types/token'

const ZERO_IN_BASE = new BigNumberInBase(0)

Expand Down Expand Up @@ -149,7 +149,7 @@ export class IndexerRestExplorerTransformer {
}

static baseTransactionToTransaction(
transaction: BaseTransaction,
transaction: Transaction,
): ExplorerTransaction {
return {
...transaction,
Expand Down Expand Up @@ -227,6 +227,12 @@ export class IndexerRestExplorerTransformer {
type: transaction.messages[0].type,
logs: transaction.logs,
signatures: transaction.signatures,
messages: (transaction.messages || [])
.filter((m) => m)
.map((message) => ({
type: message.type,
message: message.value,
})),
fee: transaction.gas_fee.amount
? new BigNumberInWei(transaction.gas_fee.amount[0].amount).toBase()
: ZERO_IN_BASE,
Expand Down
76 changes: 12 additions & 64 deletions packages/sdk-ts/src/client/indexer/types/explorer-rest.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
/* eslint-disable camelcase */
import { Coin } from '@injectivelabs/ts-types'
import {
Paging,
EventLog,
Signature,
ValidatorUptime,
BlockWithTxs as BaseBlockWithTxs,
Transaction as BaseTransaction,
CosmWasmChecksum,
CosmWasmPermission,
ValidatorUptimeStatus,
} from './explorer'

export enum AccessTypeCode {
AccessTypeUnspecified = 0,
AccessTypeNobody = 1,
AccessTypeOnlyAddress = 2,
AccessTypeEverybody = 3,
AccessTypeAnyOfAddresses = 4,
}

export enum AccessType {
AccessTypeUnspecified = 'Unspecified',
AccessTypeNobody = 'Nobody',
AccessTypeOnlyAddress = 'Only Address',
AccessTypeEverybody = 'Everybody',
AccessTypeAnyOfAddresses = 'Any of Addresses',
}

export interface Paging {
from: number
to: number
total: number
}
export interface ExplorerApiResponse<T> {
data: T
}
Expand Down Expand Up @@ -92,50 +73,11 @@ export interface ExplorerBlockApiResponse {
data: BlockFromExplorerApiResponse[]
}

export interface Message {
type: string
message: any
}

export interface ExplorerTransaction extends Omit<BaseTransaction, 'messages'> {
memo: string
messages: Message[]
parsedMessages?: Message[]
errorLog?: string
logs?: EventLog[]
claimIds?: number[]
}

export interface ExplorerBlockWithTxs extends Omit<BaseBlockWithTxs, 'txs'> {
txs: ExplorerTransaction[]
}

export enum ValidatorUptimeStatus {
Proposed = 'proposed',
Signed = 'signed',
Missed = 'missed',
}

export interface ValidatorUptimeFromExplorerApiResponse {
block_number: number
status: ValidatorUptimeStatus
}

export interface ExplorerValidatorUptime
extends Omit<ValidatorUptime, 'status'> {
status: ValidatorUptimeStatus
}

export interface CosmWasmPermission {
access_type: AccessTypeCode
address: string
}

export interface CosmWasmChecksum {
algorithm: string
hash: string
}

export interface WasmCodeExplorerApiResponse {
checksum: CosmWasmChecksum
code_id: number
Expand Down Expand Up @@ -226,4 +168,10 @@ export interface CW20BalanceExplorerApiResponse {
}
}

export { BaseTransaction }
export interface BankTransferFromExplorerApiResponse {
sender: string
recipient: string
amounts: Coin[]
block_number: number
block_timestamp: string
}
107 changes: 80 additions & 27 deletions packages/sdk-ts/src/client/indexer/types/explorer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
import { Coin } from '@injectivelabs/ts-types'
import { BigNumberInBase } from '@injectivelabs/utils'
import type { CosmWasmChecksum, CosmWasmPermission } from './explorer-rest'
import { InjectiveExplorerRpc } from '@injectivelabs/indexer-proto-ts'
import { Coin } from '@injectivelabs/ts-types'
import { TokenStatic } from '../../../types/token'

export enum AccessTypeCode {
AccessTypeUnspecified = 0,
AccessTypeNobody = 1,
AccessTypeOnlyAddress = 2,
AccessTypeEverybody = 3,
AccessTypeAnyOfAddresses = 4,
}

export enum AccessType {
AccessTypeUnspecified = 'Unspecified',
AccessTypeNobody = 'Nobody',
AccessTypeOnlyAddress = 'Only Address',
AccessTypeEverybody = 'Everybody',
AccessTypeAnyOfAddresses = 'Any of Addresses',
}

export enum ValidatorUptimeStatus {
Proposed = 'proposed',
Signed = 'signed',
Missed = 'missed',
}

export interface Paging {
from: number
to: number
total: number
}

export interface EventLogEvent {
type: string
attributes: Array<{
Expand All @@ -23,6 +50,11 @@ export interface Signature {
sequence: number
}

export interface Message {
type: string
message: any
}

export interface IBCTransferTx {
sender: string
receiver: string
Expand Down Expand Up @@ -269,23 +301,8 @@ export interface Contract {
}
}

export interface ContractTransaction {
txHash: string
type: string
code: number
amount: BigNumberInBase
fee: BigNumberInBase
height: number
time: number
data: string
memo: string
tx_number: number
error_log: string
logs: EventLog[]
signatures: Signature[]
}

export interface ContractTransactionWithMessages extends ContractTransaction {
export interface ContractTransactionWithMessages
extends Omit<ContractTransaction, 'messages'> {
messages: Array<{
type: string
value: {
Expand All @@ -310,14 +327,6 @@ export interface WasmCode {
proposalId?: number
}

export interface BankTransferFromExplorerApiResponse {
sender: string
recipient: string
amounts: Coin[]
block_number: number
block_timestamp: string
}

export interface BankTransfer {
sender: string
recipient: string
Expand All @@ -326,6 +335,50 @@ export interface BankTransfer {
blockTimestamp: number
}

export interface ContractTransaction {
txHash: string
type: string
code: number
messages: Message[]
amount: BigNumberInBase
fee: BigNumberInBase
height: number
time: number
data: string
memo: string
tx_number: number
error_log: string
logs: EventLog[]
signatures: Signature[]
}

export interface ExplorerTransaction extends Omit<Transaction, 'messages'> {
memo: string
messages: Message[]
errorLog?: string
logs?: EventLog[]
claimIds?: number[]
}

export interface ExplorerBlockWithTxs extends Omit<BlockWithTxs, 'txs'> {
txs: ExplorerTransaction[]
}

export interface ExplorerValidatorUptime
extends Omit<ValidatorUptime, 'status'> {
status: ValidatorUptimeStatus
}

export interface CosmWasmPermission {
access_type: AccessTypeCode
address: string
}

export interface CosmWasmChecksum {
algorithm: string
hash: string
}

export type GrpcIBCTransferTx = InjectiveExplorerRpc.IBCTransferTx
export type GrpcPeggyDepositTx = InjectiveExplorerRpc.PeggyDepositTx
export type GrpcPeggyWithdrawalTx = InjectiveExplorerRpc.PeggyWithdrawalTx
Expand Down

0 comments on commit b49ea43

Please sign in to comment.