Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backend constructor option for routing requests #48

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/Substrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ type Configuration = {
* Request timeout in milliseconds. Default: 5m
*/
timeout?: number;

/**
* Switches between existing backend and newer backend
*/
backend?: "v0" | "v1";
};

/**
Expand All @@ -33,11 +38,18 @@ export class Substrate {
baseUrl: string;
apiVersion: string;
timeout: number;
backend: string;

/**
* Initialize the Substrate SDK.
*/
constructor({ apiKey, baseUrl, apiVersion, timeout }: Configuration) {
constructor({
apiKey,
baseUrl,
apiVersion,
timeout,
backend,
}: Configuration) {
if (!apiKey) {
throw new SubstrateError(
"An API Key is required. Specify it when constructing the Substrate client: `new Substrate({ apiKey: 'API_KEY' })`",
Expand All @@ -47,6 +59,7 @@ export class Substrate {
this.baseUrl = baseUrl ?? "https://api.substrate.run";
this.apiVersion = apiVersion ?? OpenAPIjson["info"]["version"];
this.timeout = timeout ?? 300000;
this.backend = backend ?? "v0";
}

/**
Expand Down Expand Up @@ -136,6 +149,9 @@ export class Substrate {
headers.append("X-Substrate-Runtime", props.runtime);
headers.append("X-Substrate-Runtime-Version", props.runtimeVersion);

// Switch between old and new backends
headers.append("X-Substrate-Backend", this.backend);

return headers;
}
}
Loading