From 41a2c5472beca82a55d626fc88ebb85c02e9b28e Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Wed, 12 Apr 2023 23:24:47 +0200 Subject: [PATCH] Update generation of typescript documentation from golang types --- api/types.go | 2 +- blockbook-api.d.ts => blockbook-api.ts | 29 +++++++++++----------- build/tools/typescriptify/typescriptify.go | 4 +-- server/ws_types.go | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) rename blockbook-api.d.ts => blockbook-api.ts (96%) diff --git a/api/types.go b/api/types.go index a6b56035..30b02014 100644 --- a/api/types.go +++ b/api/types.go @@ -230,7 +230,7 @@ type EthereumSpecific struct { Error string `json:"error,omitempty"` Nonce uint64 `json:"nonce"` GasLimit *big.Int `json:"gasLimit"` - GasUsed *big.Int `json:"gasUsed"` + GasUsed *big.Int `json:"gasUsed,omitempty"` GasPrice *Amount `json:"gasPrice"` Data string `json:"data,omitempty"` ParsedData *bchain.EthereumParsedInputData `json:"parsedData,omitempty"` diff --git a/blockbook-api.d.ts b/blockbook-api.ts similarity index 96% rename from blockbook-api.d.ts rename to blockbook-api.ts index adb058e7..66bf78ef 100644 --- a/blockbook-api.d.ts +++ b/blockbook-api.ts @@ -12,7 +12,7 @@ export interface EthereumInternalTransfer { type: number; from: string; to: string; - value?: string; + value: string; } export interface EthereumParsedInputParam { type: string; @@ -30,9 +30,9 @@ export interface EthereumSpecific { status: number; error?: string; nonce: number; - gasLimit?: string; - gasUsed?: string; - gasPrice?: string; + gasLimit: number; + gasUsed?: number; + gasPrice: string; data?: string; parsedData?: EthereumParsedInputData; internalTransfers?: EthereumInternalTransfer[]; @@ -93,7 +93,7 @@ export interface Tx { blockTime: number; size?: number; vsize?: number; - value?: string; + value: string; valueIn?: string; fees?: string; hex?: string; @@ -105,7 +105,7 @@ export interface Tx { } export interface FeeStats { txCount: number; - totalFeesSat?: string; + totalFeesSat: string; averageFeePerKb: number; decilesFeePerKb: number[]; } @@ -139,10 +139,10 @@ export interface Address { totalPages?: number; itemsOnPage?: number; address: string; - balance?: string; + balance: string; totalReceived?: string; totalSent?: string; - unconfirmedBalance?: string; + unconfirmedBalance: string; unconfirmedTxs: number; txs: number; nonTokenTxs?: number; @@ -164,7 +164,7 @@ export interface Address { export interface Utxo { txid: string; vout: number; - value?: string; + value: string; height?: number; confirmations: number; address?: string; @@ -175,9 +175,9 @@ export interface Utxo { export interface BalanceHistory { time: number; txs: number; - received?: string; - sent?: string; - sentToSelf?: string; + received: string; + sent: string; + sentToSelf: string; rates?: { [key: string]: number }; txid?: string; } @@ -268,8 +268,8 @@ export interface BlockbookInfo { about: string; } export interface SystemInfo { - blockbook?: BlockbookInfo; - backend?: BackendInfo; + blockbook: BlockbookInfo; + backend: BackendInfo; } export interface FiatTicker { ts?: number; @@ -290,6 +290,7 @@ export interface WsReq { | 'getAccountInfo' | 'getInfo' | 'getBlockHash' + | 'getBlock' | 'getAccountUtxo' | 'getBalanceHistory' | 'getTransaction' diff --git a/build/tools/typescriptify/typescriptify.go b/build/tools/typescriptify/typescriptify.go index 0de13003..0174575c 100644 --- a/build/tools/typescriptify/typescriptify.go +++ b/build/tools/typescriptify/typescriptify.go @@ -18,7 +18,7 @@ func main() { t.ManageType(api.Amount{}, typescriptify.TypeOptions{TSType: "string"}) t.ManageType([]api.Amount{}, typescriptify.TypeOptions{TSType: "string[]"}) - t.ManageType(big.Int{}, typescriptify.TypeOptions{TSType: "string"}) + t.ManageType(big.Int{}, typescriptify.TypeOptions{TSType: "number"}) t.ManageType(time.Time{}, typescriptify.TypeOptions{TSType: "string", TSDoc: "Time in ISO 8601 YYYY-MM-DDTHH:mm:ss.sssZd"}) // API - REST and Websocket @@ -57,7 +57,7 @@ func main() { t.Add(server.WsFiatRatesForTimestampsReq{}) t.Add(server.WsFiatRatesTickersListReq{}) - err := t.ConvertToFile("blockbook-api.d.ts") + err := t.ConvertToFile("blockbook-api.ts") if err != nil { panic(err.Error()) } diff --git a/server/ws_types.go b/server/ws_types.go index edcaabe8..6422798b 100644 --- a/server/ws_types.go +++ b/server/ws_types.go @@ -4,7 +4,7 @@ import "encoding/json" type WsReq struct { ID string `json:"id"` - Method string `json:"method" ts_type:"'getAccountInfo' | 'getInfo' | 'getBlockHash' | 'getAccountUtxo' | 'getBalanceHistory' | 'getTransaction' | 'getTransactionSpecific' | 'estimateFee' | 'sendTransaction' | 'subscribeNewBlock' | 'unsubscribeNewBlock' | 'subscribeNewTransaction' | 'unsubscribeNewTransaction' | 'subscribeAddresses' | 'unsubscribeAddresses' | 'subscribeFiatRates' | 'unsubscribeFiatRates' | 'ping' | 'getCurrentFiatRates' | 'getFiatRatesForTimestamps' | 'getFiatRatesTickersList'"` + Method string `json:"method" ts_type:"'getAccountInfo' | 'getInfo' | 'getBlockHash'| 'getBlock' | 'getAccountUtxo' | 'getBalanceHistory' | 'getTransaction' | 'getTransactionSpecific' | 'estimateFee' | 'sendTransaction' | 'subscribeNewBlock' | 'unsubscribeNewBlock' | 'subscribeNewTransaction' | 'unsubscribeNewTransaction' | 'subscribeAddresses' | 'unsubscribeAddresses' | 'subscribeFiatRates' | 'unsubscribeFiatRates' | 'ping' | 'getCurrentFiatRates' | 'getFiatRatesForTimestamps' | 'getFiatRatesTickersList'"` Params json.RawMessage `json:"params" ts_type:"any"` }