diff --git a/src/blockchain/clients/explorer.ts b/src/blockchain/clients/explorer.ts index e2f3f41..40013b7 100644 --- a/src/blockchain/clients/explorer.ts +++ b/src/blockchain/clients/explorer.ts @@ -11,6 +11,7 @@ import axios, { AxiosInstance } from "axios"; import { BlockchainClient, BlockchainInfo } from "./blockchain_client.ts"; import { ErgomaticConfig } from "../../config.ts"; import { Component } from "../../component.ts"; +import { ERGOMATIC_USER_AGENT } from "../../http.ts"; export class ExplorerClient extends Component implements BlockchainClient { readonly #http: AxiosInstance; @@ -26,6 +27,9 @@ export class ExplorerClient extends Component implements BlockchainClient { this.#http = axios.create({ // let URL handle any possible trailing slash,etc in the configured endpoint. baseURL: new URL("/api/v1", config.explorer.endpoint).href, + headers: { + "User-Agent": ERGOMATIC_USER_AGENT, + }, }); } diff --git a/src/blockchain/clients/node.ts b/src/blockchain/clients/node.ts index efc1ed8..0c1ba25 100644 --- a/src/blockchain/clients/node.ts +++ b/src/blockchain/clients/node.ts @@ -11,6 +11,7 @@ import { BlockchainClient, BlockchainInfo } from "./blockchain_client.ts"; import { Component } from "../../component.ts"; import { ErgomaticConfig } from "../../config.ts"; import axios, { AxiosInstance } from "axios"; +import { ERGOMATIC_USER_AGENT } from "../../http.ts"; export class NodeClient extends Component implements BlockchainClient { readonly #http: AxiosInstance; @@ -22,6 +23,9 @@ export class NodeClient extends Component implements BlockchainClient { this.#timeoutMs = httpTimeoutMs; this.#http = axios.create({ baseURL: config.node.endpoint, + headers: { + "User-Agent": ERGOMATIC_USER_AGENT, + }, }); } @@ -44,17 +48,12 @@ export class NodeClient extends Component implements BlockchainClient { } async getInfo(): Promise { - const response = await this.#http.get( - "/info", - this.#defaultRequestConfig, - ); + const response = await this.#http.get("/info", this.#defaultRequestConfig); return response.data; } - async submitTx( - signedTx: SignedTransaction, - ): Promise { + async submitTx(signedTx: SignedTransaction): Promise { const response = await this.#http.post( "/transactions", signedTx, diff --git a/src/http.ts b/src/http.ts new file mode 100644 index 0000000..07476d0 --- /dev/null +++ b/src/http.ts @@ -0,0 +1,4 @@ +import version from "./version.ts"; + +export const ERGOMATIC_USER_AGENT = + `ergomatic/${version} (${Deno.build.os}; ${Deno.build.arch})`;