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 support for getVersionInfo endpoint #1028

Merged
merged 4 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ A breaking change will get clearly marked in this log.
## Unreleased


### Added
- `rpc.Server` now has a `getVersionInfo` method which retrieves version information about the RPC and Captive core. RPC manages its own, pared-down version of Stellar Core optimized for its own subset of needs. we'll refer to this as a "Captive Core" instance. ([#997](https://github.com/stellar/js-stellar-sdk/issues/997)):
psheth9 marked this conversation as resolved.
Show resolved Hide resolved

```typescript

export interface GetVersionInfoResponse {
version: string;
commit_hash: string;
build_time_stamp: string;
captive_core_version: string;
protocol_version: number;
}

```


## [v12.2.0](https://github.com/stellar/js-stellar-sdk/compare/v12.1.0...v12.2.0)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"test:node": "yarn _nyc mocha --recursive 'test/unit/**/*.js'",
"test:integration": "yarn _nyc mocha --recursive 'test/integration/**/*.js'",
"test:browser": "karma start config/karma.conf.js",
"fmt": "yarn eslint -c .eslintrc.js src/ --fix && yarn _prettier",
"fmt": "yarn _prettier && yarn eslint -c .eslintrc.js src/ --fix",
"preversion": "yarn clean && yarn _prettier && yarn build:prod && yarn test",
"prepare": "yarn build:prod",
"_build": "yarn build:node && yarn build:test && yarn build:browser",
Expand Down
8 changes: 8 additions & 0 deletions src/rpc/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,14 @@ export namespace Api {
stateChanges?: RawLedgerEntryChange[];
}

export interface GetVersionInfoResponse {
version: string;
commit_hash: string;
build_time_stamp: string;
captive_core_version: string;
protocol_version: number; // uint32
}

export interface GetFeeStatsResponse {
sorobanInclusionFee: FeeDistribution;
inclusionFee: FeeDistribution;
Expand Down
10 changes: 10 additions & 0 deletions src/rpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,14 @@ export class Server {
public async getFeeStats(): Promise<Api.GetFeeStatsResponse> {
return jsonrpc.postObject(this.serverURL.toString(), 'getFeeStats');
}

/**
* Provides information about the current version details of the Soroban RPC and captive-core
* @returns {Promise<Api.GetVersionInfoResponse>} the version info
* @see https://developers.stellar.org/docs/data/rpc/api-reference/methods/getVersionInfo
* */
psheth9 marked this conversation as resolved.
Show resolved Hide resolved
public async getVersionInfo(): Promise<Api.GetVersionInfoResponse> {
return jsonrpc.postObject(this.serverURL.toString(), 'getVersionInfo');
}

}
44 changes: 44 additions & 0 deletions test/unit/server/soroban/get_version_info_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { Server, AxiosClient } = StellarSdk.rpc;

describe("Server#getVersionInfo", function () {
beforeEach(function () {
this.server = new Server(serverUrl);
this.axiosMock = sinon.mock(AxiosClient);
});

afterEach(function () {
this.axiosMock.verify();
this.axiosMock.restore();
});

it("requests the correct endpoint", function (done) {
let result = {
version: "21.4.0-dbb390c6bb99024122fccb12c8219af67d50db04",
commit_hash: "dbb390c6bb99024122fccb12c8219af67d50db04",
build_time_stamp: "2024-07-10T14:50:09",
captive_core_version:
"stellar-core 21.1.1 (b3aeb14cc798f6d11deb2be913041be916f3b0cc)",
protocol_version: 21,
};

this.axiosMock
.expects("post")
.withArgs(serverUrl, {
jsonrpc: "2.0",
id: 1,
method: "getVersionInfo",
params: null,
})
.returns(Promise.resolve({ data: { result } }));

this.server
.getVersionInfo()
.then(function (response) {
expect(response).to.be.deep.equal(result);
done();
})
.catch(function (err) {
done(err);
});
});
});
Loading