Skip to content

Commit

Permalink
Merge pull request #35 from nautls/ergomatic-user-agent
Browse files Browse the repository at this point in the history
Include Ergomatic user agent
  • Loading branch information
ross-weir authored Sep 18, 2023
2 parents dcb6216 + 518936d commit 71aa4bb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/blockchain/clients/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
},
});
}

Expand Down
13 changes: 6 additions & 7 deletions src/blockchain/clients/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
},
});
}

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

async getInfo(): Promise<BlockchainInfo> {
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<TransactionId> {
async submitTx(signedTx: SignedTransaction): Promise<TransactionId> {
const response = await this.#http.post(
"/transactions",
signedTx,
Expand Down
4 changes: 4 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import version from "./version.ts";

export const ERGOMATIC_USER_AGENT =
`ergomatic/${version} (${Deno.build.os}; ${Deno.build.arch})`;

0 comments on commit 71aa4bb

Please sign in to comment.