Skip to content

Commit 518936d

Browse files
committed
add ergomatic user-agent in requests
1 parent 8d18688 commit 518936d

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/blockchain/clients/explorer.ts

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import axios, { AxiosInstance } from "axios";
1111
import { BlockchainClient, BlockchainInfo } from "./blockchain_client.ts";
1212
import { ErgomaticConfig } from "../../config.ts";
1313
import { Component } from "../../component.ts";
14+
import { ERGOMATIC_USER_AGENT } from "../../http.ts";
1415

1516
export class ExplorerClient extends Component implements BlockchainClient {
1617
readonly #http: AxiosInstance;
@@ -26,6 +27,9 @@ export class ExplorerClient extends Component implements BlockchainClient {
2627
this.#http = axios.create({
2728
// let URL handle any possible trailing slash,etc in the configured endpoint.
2829
baseURL: new URL("/api/v1", config.explorer.endpoint).href,
30+
headers: {
31+
"User-Agent": ERGOMATIC_USER_AGENT,
32+
},
2933
});
3034
}
3135

src/blockchain/clients/node.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { BlockchainClient, BlockchainInfo } from "./blockchain_client.ts";
1111
import { Component } from "../../component.ts";
1212
import { ErgomaticConfig } from "../../config.ts";
1313
import axios, { AxiosInstance } from "axios";
14+
import { ERGOMATIC_USER_AGENT } from "../../http.ts";
1415

1516
export class NodeClient extends Component implements BlockchainClient {
1617
readonly #http: AxiosInstance;
@@ -22,6 +23,9 @@ export class NodeClient extends Component implements BlockchainClient {
2223
this.#timeoutMs = httpTimeoutMs;
2324
this.#http = axios.create({
2425
baseURL: config.node.endpoint,
26+
headers: {
27+
"User-Agent": ERGOMATIC_USER_AGENT,
28+
},
2529
});
2630
}
2731

@@ -44,17 +48,12 @@ export class NodeClient extends Component implements BlockchainClient {
4448
}
4549

4650
async getInfo(): Promise<BlockchainInfo> {
47-
const response = await this.#http.get(
48-
"/info",
49-
this.#defaultRequestConfig,
50-
);
51+
const response = await this.#http.get("/info", this.#defaultRequestConfig);
5152

5253
return response.data;
5354
}
5455

55-
async submitTx(
56-
signedTx: SignedTransaction,
57-
): Promise<TransactionId> {
56+
async submitTx(signedTx: SignedTransaction): Promise<TransactionId> {
5857
const response = await this.#http.post(
5958
"/transactions",
6059
signedTx,

src/http.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import version from "./version.ts";
2+
3+
export const ERGOMATIC_USER_AGENT =
4+
`ergomatic/${version} (${Deno.build.os}; ${Deno.build.arch})`;

0 commit comments

Comments
 (0)