diff --git a/CHANGELOG.md b/CHANGELOG.md index 786bbfead..794afe90f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,22 @@ A breaking change will get clearly marked in this log. ## Unreleased +### Added +- `rpc.Server` now has a `getVersionInfo` method which reports version information of the RPC instance it is connected to. ([#997](https://github.com/stellar/js-stellar-sdk/issues/997)): + +```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 diff --git a/package.json b/package.json index 6903e2636..d1a246ab6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/rpc/api.ts b/src/rpc/api.ts index b0e52764d..836c2ebcb 100644 --- a/src/rpc/api.ts +++ b/src/rpc/api.ts @@ -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; diff --git a/src/rpc/server.ts b/src/rpc/server.ts index 45616ddaf..b774fc993 100644 --- a/src/rpc/server.ts +++ b/src/rpc/server.ts @@ -865,4 +865,15 @@ export class Server { public async getFeeStats(): Promise { return jsonrpc.postObject(this.serverURL.toString(), 'getFeeStats'); } + + /** + * Provides information about the current version details of the Soroban RPC and captive-core + * + * @returns {Promise} the version info + * @see https://developers.stellar.org/docs/data/rpc/api-reference/methods/getVersionInfo + */ + public async getVersionInfo(): Promise { + return jsonrpc.postObject(this.serverURL.toString(), 'getVersionInfo'); + } + } diff --git a/test/unit/server/soroban/get_version_info_test.js b/test/unit/server/soroban/get_version_info_test.js new file mode 100644 index 000000000..aa262a2a0 --- /dev/null +++ b/test/unit/server/soroban/get_version_info_test.js @@ -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); + }); + }); +});