Skip to content

Commit 3988271

Browse files
authored
Added Horizon.Server.root to obtain information from the Horizon root endpoint. (#1122)
1 parent 3304995 commit 3988271

File tree

5 files changed

+154
-0
lines changed

5 files changed

+154
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ A breaking change will get clearly marked in this log.
99
### Fixed
1010
* When using a friendbot that points to a Horizon instance that has ledger metadata disabled, you can no longer extract the account sequence from the response. Instead, we hit RPC directly ([#1107](https://github.com/stellar/js-stellar-sdk/pull/1107/)).
1111

12+
### Added
13+
* Added `Horizon.Server.root` to obtain information from the Horizon root endpoint. ([#1122](https://github.com/stellar/js-stellar-sdk/pull/1122/))
1214

1315
## [v13.0.0](https://github.com/stellar/js-stellar-sdk/compare/v12.3.0...v13.0.0)
1416
This is a direct re-tag of rc.2 with the only change being an upgrade to the `stellar-base` library to incorporate a patch release. Nonetheless, the entire changelog from the prior major version here is replicated for a comprehensive view on what's broken, added, and fixed.

src/horizon/call_builder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class CallBuilder<
4747
T extends
4848
| HorizonApi.FeeStatsResponse
4949
| HorizonApi.BaseResponse
50+
| HorizonApi.RootResponse
5051
| ServerApi.CollectionPage<HorizonApi.BaseResponse>
5152
> {
5253
protected url: URI;

src/horizon/horizon_api.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,4 +707,18 @@ export namespace HorizonApi {
707707
};
708708
result_xdr: string;
709709
}
710+
711+
export interface RootResponse {
712+
horizon_version: string;
713+
core_version: string;
714+
ingest_latest_ledger: number;
715+
history_latest_ledger: number;
716+
history_latest_ledger_closed_at: string;
717+
history_elder_ledger: number;
718+
core_latest_ledger: number;
719+
network_passphrase: string;
720+
current_protocol_version: number;
721+
supported_protocol_version: number;
722+
core_supported_protocol_version: number;
723+
}
710724
}

src/horizon/server.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ export class HorizonServer {
199199
return cb.call();
200200
}
201201

202+
/**
203+
* Fetch the Horizon server's root endpoint.
204+
* @returns {Promise<HorizonApi.RootResponse>} Promise that resolves to the root endpoint returned by Horizon.
205+
*/
206+
public async root(): Promise<HorizonApi.RootResponse> {
207+
const cb = new CallBuilder<HorizonApi.RootResponse>(
208+
URI(this.serverURL as any),
209+
);
210+
return cb.call();
211+
}
212+
202213
/**
203214
* Submits a transaction to the network.
204215
*

test/unit/server/horizon/server_test.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,132 @@ describe("server.js non-transaction tests", function () {
3737
});
3838
});
3939

40+
describe("Server.root", function () {
41+
let response = {
42+
_links: {
43+
account: {
44+
href: "https://horizon.stellar.org/accounts/{account_id}",
45+
templated: true,
46+
},
47+
accounts: {
48+
href: "https://horizon.stellar.org/accounts{?signer,sponsor,asset,liquidity_pool,cursor,limit,order}",
49+
templated: true,
50+
},
51+
account_transactions: {
52+
href: "https://horizon.stellar.org/accounts/{account_id}/transactions{?cursor,limit,order}",
53+
templated: true,
54+
},
55+
claimable_balances: {
56+
href: "https://horizon.stellar.org/claimable_balances{?asset,sponsor,claimant,cursor,limit,order}",
57+
templated: true,
58+
},
59+
assets: {
60+
href: "https://horizon.stellar.org/assets{?asset_code,asset_issuer,cursor,limit,order}",
61+
templated: true,
62+
},
63+
effects: {
64+
href: "https://horizon.stellar.org/effects{?cursor,limit,order}",
65+
templated: true,
66+
},
67+
fee_stats: {
68+
href: "https://horizon.stellar.org/fee_stats",
69+
},
70+
ledger: {
71+
href: "https://horizon.stellar.org/ledgers/{sequence}",
72+
templated: true,
73+
},
74+
ledgers: {
75+
href: "https://horizon.stellar.org/ledgers{?cursor,limit,order}",
76+
templated: true,
77+
},
78+
liquidity_pools: {
79+
href: "https://horizon.stellar.org/liquidity_pools{?reserves,account,cursor,limit,order}",
80+
templated: true,
81+
},
82+
offer: {
83+
href: "https://horizon.stellar.org/offers/{offer_id}",
84+
templated: true,
85+
},
86+
offers: {
87+
href: "https://horizon.stellar.org/offers{?selling,buying,seller,sponsor,cursor,limit,order}",
88+
templated: true,
89+
},
90+
operation: {
91+
href: "https://horizon.stellar.org/operations/{id}",
92+
templated: true,
93+
},
94+
operations: {
95+
href: "https://horizon.stellar.org/operations{?cursor,limit,order,include_failed}",
96+
templated: true,
97+
},
98+
order_book: {
99+
href: "https://horizon.stellar.org/order_book{?selling_asset_type,selling_asset_code,selling_asset_issuer,buying_asset_type,buying_asset_code,buying_asset_issuer,limit}",
100+
templated: true,
101+
},
102+
payments: {
103+
href: "https://horizon.stellar.org/payments{?cursor,limit,order,include_failed}",
104+
templated: true,
105+
},
106+
self: {
107+
href: "https://horizon.stellar.org/",
108+
},
109+
strict_receive_paths: {
110+
href: "https://horizon.stellar.org/paths/strict-receive{?source_assets,source_account,destination_account,destination_asset_type,destination_asset_issuer,destination_asset_code,destination_amount}",
111+
templated: true,
112+
},
113+
strict_send_paths: {
114+
href: "https://horizon.stellar.org/paths/strict-send{?destination_account,destination_assets,source_asset_type,source_asset_issuer,source_asset_code,source_amount}",
115+
templated: true,
116+
},
117+
trade_aggregations: {
118+
href: "https://horizon.stellar.org/trade_aggregations?base_asset_type={base_asset_type}\u0026base_asset_code={base_asset_code}\u0026base_asset_issuer={base_asset_issuer}\u0026counter_asset_type={counter_asset_type}\u0026counter_asset_code={counter_asset_code}\u0026counter_asset_issuer={counter_asset_issuer}",
119+
templated: true,
120+
},
121+
trades: {
122+
href: "https://horizon.stellar.org/trades?base_asset_type={base_asset_type}\u0026base_asset_code={base_asset_code}\u0026base_asset_issuer={base_asset_issuer}\u0026counter_asset_type={counter_asset_type}\u0026counter_asset_code={counter_asset_code}\u0026counter_asset_issuer={counter_asset_issuer}",
123+
templated: true,
124+
},
125+
transaction: {
126+
href: "https://horizon.stellar.org/transactions/{hash}",
127+
templated: true,
128+
},
129+
transactions: {
130+
href: "https://horizon.stellar.org/transactions{?cursor,limit,order}",
131+
templated: true,
132+
},
133+
},
134+
horizon_version: "22.0.1-dd8a9b473a303cfcdd383d1db45dace93ea0861c",
135+
core_version:
136+
"stellar-core 22.1.0.rc1 (fdd833d57c86cfe0c5057da5b2319953ab841de0)",
137+
ingest_latest_ledger: 54837706,
138+
history_latest_ledger: 54837706,
139+
history_latest_ledger_closed_at: "2024-12-15T11:39:19Z",
140+
history_elder_ledger: 48530161,
141+
core_latest_ledger: 54837706,
142+
network_passphrase: "Public Global Stellar Network ; September 2015",
143+
current_protocol_version: 22,
144+
supported_protocol_version: 22,
145+
core_supported_protocol_version: 22,
146+
};
147+
148+
it("returns the root endpoint", function (done) {
149+
this.axiosMock
150+
.expects("get")
151+
.withArgs(sinon.match("https://horizon-live.stellar.org:1337/"))
152+
.returns(Promise.resolve({ data: response }));
153+
154+
this.server
155+
.root()
156+
.then((root) => {
157+
expect(root).to.be.equal(response);
158+
done();
159+
})
160+
.catch(function (err) {
161+
done(err);
162+
});
163+
});
164+
});
165+
40166
describe("Server.fetchTimebounds", function () {
41167
let clock;
42168

0 commit comments

Comments
 (0)