mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-02-20 00:33:07 +01:00
refactor(blockchain-link): use blockbook api types
This commit is contained in:
@@ -1,20 +1,24 @@
|
||||
import type { RequiredKey } from '@trezor/type-utils';
|
||||
import type { OptionalKey, RequiredKey } from '@trezor/type-utils';
|
||||
|
||||
import type {
|
||||
AddressAlias,
|
||||
AvailableVsCurrencies,
|
||||
Address as BlockbookAddress,
|
||||
Block as BlockbookBlock,
|
||||
Token as BlockbookToken,
|
||||
TokenTransfer as BlockbookTokenTransfer,
|
||||
Tx as BlockbookTx,
|
||||
Utxo as BlockbookUtxo,
|
||||
ContractInfo,
|
||||
FiatTicker,
|
||||
MempoolTxidFilterEntries,
|
||||
StakingPool,
|
||||
Vin,
|
||||
Vout,
|
||||
WsAccountUtxoReq,
|
||||
WsBlockFilterReq,
|
||||
WsBlockFiltersBatchReq,
|
||||
WsBlockHashRes,
|
||||
WsEstimateFeeRes,
|
||||
WsInfoRes,
|
||||
WsMempoolFiltersReq,
|
||||
} from './blockbook-api';
|
||||
import type { AccountBalanceHistory, FiatRatesBySymbol, TokenStandard } from './common';
|
||||
import type {
|
||||
@@ -27,8 +31,6 @@ import type {
|
||||
RpcCallParams,
|
||||
} from './params';
|
||||
|
||||
type OptionalKey<M, K extends keyof M> = Omit<M, K> & Partial<Pick<M, K>>;
|
||||
|
||||
export type AccountUtxo = RequiredKey<BlockbookUtxo, 'address' | 'height' | 'value' | 'path'>[];
|
||||
|
||||
export interface Subscribe {
|
||||
@@ -39,24 +41,26 @@ export type ServerInfo = WsInfoRes;
|
||||
|
||||
export type BlockHash = WsBlockHashRes;
|
||||
|
||||
export interface Block {
|
||||
page: number;
|
||||
totalPages: number;
|
||||
itemsOnPage: number;
|
||||
hash: string;
|
||||
height: number;
|
||||
export type Block = Omit<
|
||||
RequiredKey<BlockbookBlock, 'page' | 'totalPages' | 'itemsOnPage'>,
|
||||
'txs' | 'confirmations' | 'size' | 'version' | 'merkleRoot' | 'nonce' | 'bits' | 'difficulty'
|
||||
> & {
|
||||
txCount: number;
|
||||
txs: Transaction[];
|
||||
}
|
||||
};
|
||||
|
||||
export interface FilterRequestParams {
|
||||
scriptType: 'taproot' | 'taproot-noordinals';
|
||||
M?: number;
|
||||
}
|
||||
type ScriptType = 'taproot' | 'taproot-noordinals';
|
||||
|
||||
export interface MempoolFiltersParams extends FilterRequestParams {
|
||||
fromTimestamp?: number;
|
||||
}
|
||||
export type FilterRequestParams = Omit<WsBlockFilterReq, 'scriptType' | 'blockHash'> & {
|
||||
scriptType: ScriptType;
|
||||
};
|
||||
|
||||
export type MempoolFiltersParams = Omit<
|
||||
OptionalKey<WsMempoolFiltersReq, 'fromTimestamp'>,
|
||||
'scriptType'
|
||||
> & {
|
||||
scriptType: ScriptType;
|
||||
};
|
||||
|
||||
export interface FilterResponse {
|
||||
P: number;
|
||||
@@ -114,60 +118,37 @@ export type BEP1155 = BaseERC & {
|
||||
standard: 'BEP1155';
|
||||
} & Required<Pick<BlockbookToken, 'multiTokenValues'>>;
|
||||
|
||||
export interface AccountInfo {
|
||||
address: string;
|
||||
balance: string;
|
||||
totalReceived: string;
|
||||
totalSent: string;
|
||||
txs: number;
|
||||
addrTxCount?: number;
|
||||
unconfirmedBalance: string;
|
||||
unconfirmedTxs: number;
|
||||
page?: number;
|
||||
itemsOnPage: number;
|
||||
totalPages: number;
|
||||
nonTokenTxs?: number;
|
||||
transactions?: Transaction[];
|
||||
nonce?: string;
|
||||
export type AccountInfo = Omit<
|
||||
RequiredKey<BlockbookAddress, 'totalReceived' | 'totalSent' | 'itemsOnPage' | 'totalPages'>,
|
||||
'tokens' | 'transactions'
|
||||
> & {
|
||||
tokens?: (XPUBAddress | ERC20 | ERC721 | ERC1155 | BEP20 | BEP721 | BEP1155)[];
|
||||
contractInfo?: ContractInfo;
|
||||
addressAliases?: { [key: string]: AddressAlias };
|
||||
stakingPools?: StakingPool[];
|
||||
}
|
||||
transactions?: Transaction[];
|
||||
};
|
||||
|
||||
export interface AccountUtxoParams {
|
||||
descriptor: string;
|
||||
}
|
||||
export type AccountUtxoParams = WsAccountUtxoReq;
|
||||
|
||||
export type VinVout = OptionalKey<Vin & Vout, 'addresses'>;
|
||||
|
||||
export interface Transaction extends BlockbookTx {
|
||||
fees: string; // optional in Tx, seems to always be there
|
||||
export type Transaction = Omit<RequiredKey<BlockbookTx, 'fees'>, 'tokenTransfers'> & {
|
||||
tokenTransfers?: (BlockbookTokenTransfer & {
|
||||
type: TokenStandard; // string in Tx, seems to always be ERC20 | ERC721 | ERC1155
|
||||
standard: TokenStandard;
|
||||
})[];
|
||||
}
|
||||
};
|
||||
|
||||
export interface Push {
|
||||
result: string;
|
||||
}
|
||||
|
||||
export type Fee = {
|
||||
feePerUnit: string;
|
||||
feePerTx?: string;
|
||||
feeLimit?: string;
|
||||
}[];
|
||||
export type Fee = Omit<RequiredKey<WsEstimateFeeRes, 'feePerUnit'>, 'eip1559'>[];
|
||||
|
||||
export interface BlockNotification {
|
||||
height: number;
|
||||
hash: string;
|
||||
}
|
||||
export type BlockNotification = Pick<BlockbookBlock, 'hash' | 'height'>;
|
||||
|
||||
export interface MempoolTransactionNotification extends Transaction {
|
||||
confirmationETABlocks: number;
|
||||
confirmationETASeconds: number;
|
||||
}
|
||||
export type MempoolTransactionNotification = RequiredKey<
|
||||
Transaction,
|
||||
'confirmationETASeconds' | 'confirmationETABlocks'
|
||||
>;
|
||||
|
||||
export interface AddressNotification {
|
||||
address: string;
|
||||
@@ -178,19 +159,15 @@ export interface FiatRatesNotification {
|
||||
rates: FiatRatesBySymbol;
|
||||
}
|
||||
|
||||
export interface TimestampedFiatRates {
|
||||
ts: number;
|
||||
export type TimestampedFiatRates = Omit<RequiredKey<FiatTicker, 'ts'>, 'error' | 'rates'> & {
|
||||
rates: FiatRatesBySymbol;
|
||||
}
|
||||
};
|
||||
|
||||
export interface FiatRatesForTimestamp {
|
||||
tickers: TimestampedFiatRates[];
|
||||
}
|
||||
|
||||
export interface AvailableCurrencies {
|
||||
ts: number;
|
||||
available_currencies: string[];
|
||||
}
|
||||
export type AvailableCurrencies = Omit<RequiredKey<AvailableVsCurrencies, 'ts'>, 'error'>;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
declare function FSend(method: 'getInfo'): Promise<ServerInfo>;
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import type tls from 'tls';
|
||||
|
||||
import type { OptionalKey, RequiredKey } from '@trezor/type-utils';
|
||||
|
||||
import { BaseCurrencyCode } from './baseCurrency';
|
||||
import type { Transaction as BlockbookTransaction, VinVout } from './blockbook';
|
||||
import type {
|
||||
AddressAlias,
|
||||
BalanceHistory,
|
||||
Token as BlockbookToken,
|
||||
TokenTransfer as BlockbookTokenTransfer,
|
||||
Utxo as BlockbookUtxo,
|
||||
ContractInfo,
|
||||
MultiTokenValue,
|
||||
StakingPool,
|
||||
} from './blockbook-api';
|
||||
import type { SolanaStakingAccount } from './solana';
|
||||
@@ -126,14 +130,12 @@ export type FiatRatesBySymbol = {
|
||||
[K in BaseCurrencyCode]?: number | undefined;
|
||||
};
|
||||
|
||||
export interface AccountBalanceHistory {
|
||||
time: number;
|
||||
txs: number;
|
||||
received: string;
|
||||
sent: string;
|
||||
sentToSelf?: string; // should always be there for blockbook >= 0.3.3
|
||||
export type AccountBalanceHistory = Omit<
|
||||
OptionalKey<BalanceHistory, 'sentToSelf'>,
|
||||
'txid' | 'rates'
|
||||
> & {
|
||||
rates: FiatRatesBySymbol;
|
||||
}
|
||||
};
|
||||
|
||||
export interface Transaction {
|
||||
type: 'sent' | 'recv' | 'self' | 'joint' | 'contract' | 'failed' | 'unknown';
|
||||
@@ -206,41 +208,32 @@ export interface AccountAddresses {
|
||||
anonymitySet?: AnonymitySet;
|
||||
}
|
||||
|
||||
export interface Utxo {
|
||||
txid: string;
|
||||
vout: number;
|
||||
export type Utxo = Omit<
|
||||
RequiredKey<BlockbookUtxo, 'address' | 'path'>,
|
||||
'value' | 'height' | 'lockTime'
|
||||
> & {
|
||||
amount: string;
|
||||
blockHeight: number;
|
||||
address: string;
|
||||
path: string;
|
||||
confirmations: number;
|
||||
coinbase?: boolean;
|
||||
cardanoSpecific?: {
|
||||
unit: string;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export interface TokenAccount {
|
||||
publicKey: string;
|
||||
balance: string;
|
||||
}
|
||||
|
||||
export interface TokenInfo {
|
||||
standard: TokenStandard; // token standard: ERC20...
|
||||
contract: string; // token address, token unit for ADA
|
||||
balance?: string; // token balance
|
||||
name?: string; // token name
|
||||
symbol?: string; // token symbol
|
||||
decimals: number; // token decimals or 0
|
||||
accounts?: TokenAccount[]; // token accounts for solana
|
||||
policyId?: string; // Cardano policy id
|
||||
fingerprint?: string; // Cardano starting with "asset"
|
||||
multiTokenValues?: MultiTokenValue[];
|
||||
ids?: string[];
|
||||
totalReceived?: string;
|
||||
totalSent?: string;
|
||||
export type TokenInfo = Omit<
|
||||
RequiredKey<OptionalKey<BlockbookToken, 'name'>, 'contract'>,
|
||||
'type' | 'standard' | 'path' | 'transfers' | 'baseValue' | 'secondaryValue'
|
||||
> & {
|
||||
standard: TokenStandard;
|
||||
accounts?: TokenAccount[];
|
||||
policyId?: string;
|
||||
fingerprint?: string;
|
||||
// transfers: number, // total transactions?
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This is Backend data for the account. Data can change over time as transactions happen.
|
||||
|
||||
@@ -20,6 +20,17 @@ export type UnionSubset<T, U extends T> = U;
|
||||
*/
|
||||
export type RequiredKey<M, K extends keyof M> = Omit<M, K> & Required<Pick<M, K>>;
|
||||
|
||||
/**
|
||||
* Make property of the object optional.
|
||||
*
|
||||
* Example:
|
||||
* ```
|
||||
* type T = { a: number; b: number; };
|
||||
* const t: OptionalKey<T, 'a'> = { b: 0 }; // 'a' is optional
|
||||
* ```
|
||||
*/
|
||||
export type OptionalKey<M, K extends keyof M> = Omit<M, K> & Partial<Pick<M, K>>;
|
||||
|
||||
/**
|
||||
* Get type of the object values.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user