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

Merge the Soroban RPC client into this library #860

Merged
merged 30 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
41bff1f
Move Horizon SDK into subfolders
Shaptic Jul 18, 2023
689f716
Move types also
Shaptic Jul 18, 2023
13a2f7d
WIP merge
Shaptic Aug 4, 2023
ffeed24
Upgrade all dependencies to their latest versions
Shaptic Sep 6, 2023
59b841c
Drop redundancies, tests pass!
Shaptic Sep 7, 2023
820c9ba
Move over latest soroban-client source code
Shaptic Sep 14, 2023
5b2c403
Trying to update Soroban tests to pass
Shaptic Sep 14, 2023
455fab8
More moving, formatting pass
Shaptic Sep 15, 2023
4a6cdc6
Merge branch 'master' into soroban-merge
Shaptic Sep 15, 2023
9cb919d
Holy crap, node tests pass???
Shaptic Sep 15, 2023
aa9f9d6
Fixup browser tests, too, LFGGGG
Shaptic Sep 15, 2023
90df6de
Prettier
Shaptic Sep 15, 2023
df2526d
Prettier: smaller diff
Shaptic Sep 15, 2023
5d8019a
Prettier fixup for easier merge?
Shaptic Sep 22, 2023
4181b0a
Merge branch 'master' into soroban-merge
Shaptic Sep 22, 2023
4fc2934
Drop Node 20 tests
Shaptic Sep 22, 2023
21bd09f
Minimize formatting changes
Shaptic Sep 22, 2023
fdfe795
:cmonBruh:
Shaptic Sep 22, 2023
7b34b1d
Move namespaces around to isolate srpc and hz
Shaptic Oct 11, 2023
bc5ff0f
Final testing fixups
Shaptic Oct 12, 2023
4412f7d
Merge branch 'master' into soroban-merge
Shaptic Oct 12, 2023
b4ffa9c
Merge fixup
Shaptic Oct 12, 2023
0b08af8
Upgrade soroban library + tests from v1.0.0-beta.3
Shaptic Oct 13, 2023
1ab6696
Fixup and revert unneeded changes
Shaptic Oct 13, 2023
4947082
Moving/Renaming Sep10 stuff around a bit
Shaptic Oct 13, 2023
3212204
Move friendbot API into a separate module
Shaptic Oct 16, 2023
9efd446
Reset changelog find/replace and add entry
Shaptic Oct 23, 2023
879e3a4
Buncha SEP-related module/file renames
Shaptic Oct 23, 2023
e455ac3
Finish moving and renaming, add friendbot export
Shaptic Oct 23, 2023
63e62ed
Merge branch 'master' into soroban-merge
Shaptic Oct 23, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
max-parallel: 4
matrix:
node-version: [16, 18, 20]
node-version: [16, 18]

steps:
- name: Checkout
Expand Down
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ This version is marked by a major version bump because of the significant upgrad

### Add

- Add [SEP-1](https://stellar.org/protocol/sep-1) fields to `StellarTomlResolver` for type checks ([#794](https://github.com/stellar/js-stellar-sdk/pull/794)).
Shaptic marked this conversation as resolved.
Show resolved Hide resolved
- Add [SEP-1](https://stellar.org/protocol/sep-1) fields to `TomlResolver` for type checks ([#794](https://github.com/stellar/js-stellar-sdk/pull/794)).
- Add support for passing `X-Auth-Token` as a custom header ([#795](https://github.com/stellar/js-stellar-sdk/pull/795)).

### Update
Expand Down Expand Up @@ -1142,7 +1142,7 @@ Many thanks to @Ffloriel and @Akuukis for their help with this release!

## 0.8.2

- Added `timeout` option to `StellarTomlResolver` and `FederationServer` calls
- Added `timeout` option to `TomlResolver` and `FederationServer` calls
(https://github.com/stellar/js-stellar-sdk/issues/158).
- Fixed adding random value to URLs multiple times
(https://github.com/stellar/js-stellar-sdk/issues/169).
Expand Down Expand Up @@ -1210,7 +1210,7 @@ Many thanks to @Ffloriel and @Akuukis for their help with this release!
- **Breaking change** Upgraded `stellar-base` to `0.6.0`. `ed25519` package is
now an optional dependency. Check `StellarSdk.FastSigning` variable to check
if `ed25519` package is available. More in README file.
- New `StellarTomlResolver` class that allows getting `stellar.toml` file for a
- New `TomlResolver` class that allows getting `stellar.toml` file for a
domain.
- New `Config` class to set global config values.

Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@
"build:prod": "cross-env NODE_ENV=production yarn _build",
"build:node": "yarn _babel && yarn build:ts",
"build:ts": "tsc -p ./config/tsconfig.json",
"build:test": "tsc -p ./test/tsconfig.json",
"build:browser": "webpack -c config/webpack.config.browser.js",
"build:docs": "cross-env NODE_ENV=docs yarn _babel",
"clean": "rm -rf lib/ dist/ coverage/ .nyc_output/ jsdoc/",
"docs": "yarn build:docs && jsdoc -c ./config/.jsdoc.json --verbose",
"test": "yarn test:node && yarn test:integration && yarn test:browser",
"test": "yarn build:test && yarn test:node && yarn test:integration && yarn test:browser",
"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",
"preversion": "yarn clean && yarn fmt && yarn build:prod && yarn test",
"prepare": "yarn build:prod",
"_build": "yarn build:node && yarn build:browser",
"_build": "yarn build:node && yarn build:test && yarn build:browser",
"_babel": "babel --extensions '.ts' --out-dir lib/ src/",
"_nyc": "nyc --nycrc-path config/.nycrc",
"_prettier": "prettier --ignore-path config/.prettierignore --write './**/*.js'"
"_prettier": "prettier --ignore-path config/.prettierignore --write './test/**/*.js'"
},
"husky": {
"hooks": {
Expand All @@ -51,8 +52,7 @@
},
"lint-staged": {
"**/*.{js,json,ts}": [
"yarn fmt",
"yarn lint"
"yarn fmt"
]
},
"mocha": {
Expand All @@ -66,7 +66,7 @@
],
"sort": true,
"recursive": true,
"timeout": 60000
"timeout": 30000
},
"nyc": {
"instrument": false,
Expand All @@ -86,11 +86,14 @@
"@definitelytyped/dtslint": "^0.0.182",
"@istanbuljs/nyc-config-babel": "3.0.0",
"@stellar/tsconfig": "^1.0.2",
"@types/chai": "^4.3.6",
"@types/detect-node": "^2.0.0",
"@types/eventsource": "^1.1.12",
"@types/lodash": "^4.14.199",
"@types/mocha": "^10.0.2",
"@types/node": "^20.8.2",
"@types/randombytes": "^2.0.1",
"@types/sinon": "^10.0.19",
"@types/urijs": "^1.19.20",
"@typescript-eslint/parser": "^6.7.4",
"axios-mock-adapter": "^1.22.0",
Expand Down Expand Up @@ -143,7 +146,7 @@
"bignumber.js": "^9.1.2",
"eventsource": "^2.0.2",
"randombytes": "^2.1.0",
"stellar-base": "10.0.0-beta.2",
"stellar-base": "10.0.0-beta.3",
"toml": "^3.0.0",
"urijs": "^1.19.1"
}
Expand Down
4 changes: 2 additions & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Horizon } from "./horizon_api";
import { HorizonApi } from "./horizon/horizon_api";

// For ES5 compatibility (https://stackoverflow.com/a/55066280).
/* tslint:disable:variable-name max-classes-per-file */

export class NetworkError extends Error {
public response: {
data?: Horizon.ErrorResponseData;
data?: HorizonApi.ErrorResponseData;
status?: number;
statusText?: string;
url?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import axios from "axios";
import { StrKey } from "stellar-base";
import URI from "urijs";

import { Config } from "./config";
import { BadResponseError } from "./errors";
import { StellarTomlResolver } from "./stellar_toml_resolver";
import { Config } from "../config";
import { BadResponseError } from "../errors";
import { TomlResolver } from "./stellar_toml_resolver";

// FEDERATION_RESPONSE_MAX_SIZE is the maximum size of response from a federation server
export const FEDERATION_RESPONSE_MAX_SIZE = 100 * 1024;
Expand Down Expand Up @@ -129,7 +129,7 @@ export class FederationServer {
domain: string,
opts: FederationServer.Options = {},
): Promise<FederationServer> {
const tomlObject = await StellarTomlResolver.resolve(domain, opts);
const tomlObject = await TomlResolver.resolve(domain, opts);
if (!tomlObject.FEDERATION_SERVER) {
return Promise.reject(
new Error("stellar.toml does not contain FEDERATION_SERVER field"),
Expand Down
9 changes: 9 additions & 0 deletions src/federation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export {
FederationServer as Server,
FEDERATION_RESPONSE_MAX_SIZE
} from './federation_server';

export {
TomlResolver,
STELLAR_TOML_MAX_SIZE
} from './stellar_toml_resolver';
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import axios from "axios";
import { Networks } from "stellar-base";
import toml from "toml";
import { Config } from "./config";
import { Networks } from "stellar-base";

import { Config } from "../config";

// STELLAR_TOML_MAX_SIZE is the maximum size of stellar.toml file
/** the maximum size of stellar.toml file */
export const STELLAR_TOML_MAX_SIZE = 100 * 1024;

// axios timeout doesn't catch missing urls, e.g. those with no response
// so we use the axios cancel token to ensure the timeout
const CancelToken = axios.CancelToken;

/**
* StellarTomlResolver allows resolving `stellar.toml` files.
*/
export class StellarTomlResolver {
/** TomlResolver allows resolving `stellar.toml` files. */
export class TomlResolver {
/**
* Returns a parsed `stellar.toml` file for a given domain.
* ```js
* StellarSdk.StellarTomlResolver.resolve('acme.com')
* StellarSdk.TomlResolver.resolve('acme.com')
* .then(stellarToml => {
* // stellarToml in an object representing domain stellar.toml file.
* })
Expand All @@ -34,8 +33,8 @@ export class StellarTomlResolver {
*/
public static async resolve(
domain: string,
opts: StellarTomlResolver.StellarTomlResolveOptions = {},
): Promise<StellarTomlResolver.StellarToml> {
opts: TomlResolver.StellarTomlResolveOptions = {},
): Promise<TomlResolver.StellarToml> {
const allowHttp =
typeof opts.allowHttp === "undefined"
? Config.isAllowHttp()
Expand Down Expand Up @@ -84,7 +83,7 @@ export class StellarTomlResolver {
}

/* tslint:disable-next-line: no-namespace */
export namespace StellarTomlResolver {
export namespace TomlResolver {
export interface StellarTomlResolveOptions {
allowHttp?: boolean;
timeout?: number;
Expand Down
6 changes: 6 additions & 0 deletions src/friendbot/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export namespace Api {
// Just the fields we are interested in
export interface Response {
result_meta_xdr: string;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ export class AccountCallBuilder extends CallBuilder<
this.url.setQuery("liquidity_pool", id);
return this;
}
}
}
8 changes: 4 additions & 4 deletions src/account_response.ts → src/horizon/account_response.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* tslint:disable:variable-name */

import { Account as BaseAccount } from "stellar-base";
import { Horizon } from "./horizon_api";
import { HorizonApi } from "./horizon_api";
import { ServerApi } from "./server_api";

/**
Expand All @@ -27,9 +27,9 @@ export class AccountResponse {
public readonly inflation_destination?: string;
public readonly last_modified_ledger!: number;
public readonly last_modified_time!: string;
public readonly thresholds!: Horizon.AccountThresholds;
public readonly flags!: Horizon.Flags;
public readonly balances!: Horizon.BalanceLine[];
public readonly thresholds!: HorizonApi.AccountThresholds;
public readonly flags!: HorizonApi.Flags;
public readonly balances!: HorizonApi.BalanceLine[];
public readonly signers!: ServerApi.AccountRecordSigners[];
public readonly data!: (options: {
value: string;
Expand Down
File renamed without changes.
24 changes: 11 additions & 13 deletions src/call_builder.ts → src/horizon/call_builder.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import URI from "urijs";
import URITemplate from "urijs/src/URITemplate";

import { BadRequestError, NetworkError, NotFoundError } from "./errors";
import { Horizon } from "./horizon_api";
import HorizonAxiosClient from "./horizon_axios_client";
import { ServerApi } from "./server_api";
import { BadRequestError, NetworkError, NotFoundError } from "../errors";

/* tslint:disable-next-line:no-var-requires */
const version = require("../package.json").version;
import { HorizonApi } from "./horizon_api";
import { AxiosClient, version } from "./horizon_axios_client";
import { ServerApi } from "./server_api";

// Resources which can be included in the Horizon response via the `join`
// query-param.
Expand Down Expand Up @@ -35,9 +33,9 @@ let EventSource: Constructable<EventSource> = anyGlobal.EventSource ??
*/
export class CallBuilder<
T extends
| Horizon.FeeStatsResponse
| Horizon.BaseResponse
| ServerApi.CollectionPage<Horizon.BaseResponse>
| HorizonApi.FeeStatsResponse
| HorizonApi.BaseResponse
| ServerApi.CollectionPage<HorizonApi.BaseResponse>
> {
protected url: URI;
public filter: string[][];
Expand Down Expand Up @@ -278,7 +276,7 @@ export class CallBuilder<
* @param {bool} [link.templated] Whether the link is templated
* @returns {function} A function that requests the link
*/
private _requestFnForLink(link: Horizon.ResponseLink): (opts?: any) => any {
private _requestFnForLink(link: HorizonApi.ResponseLink): (opts?: any) => any {
return async (opts: any = {}) => {
let uri;

Expand Down Expand Up @@ -327,7 +325,7 @@ export class CallBuilder<
// are loading from the server or in-memory (via join).
json[key] = async () => record;
} else {
json[key] = this._requestFnForLink(n as Horizon.ResponseLink);
json[key] = this._requestFnForLink(n as HorizonApi.ResponseLink);
}
}
return json;
Expand All @@ -344,7 +342,7 @@ export class CallBuilder<
url = url.protocol(this.url.protocol());
}

return HorizonAxiosClient.get(url.toString())
return AxiosClient.get(url.toString())
.then((response) => response.data)
.catch(this._handleNetworkError);
}
Expand Down Expand Up @@ -404,4 +402,4 @@ export class CallBuilder<
return Promise.reject(new Error(error.message));
}
}
}
}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/horizon_api.ts → src/horizon/horizon_api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AssetType, MemoType } from "stellar-base";

/* tslint:disable-next-line:no-namespace */
export namespace Horizon {
export namespace HorizonApi {
export interface ResponseLink {
href: string;
templated?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios, { AxiosResponse } from "axios";
import URI from "urijs";

/* tslint:disable-next-line:no-var-requires */
const version = require("../package.json").version;
export const version = require("../../package.json").version;

export interface ServerTime {
serverTime: number;
Expand All @@ -23,7 +23,7 @@ export interface ServerTime {
*/
export const SERVER_TIME_MAP: Record<string, ServerTime> = {};

const HorizonAxiosClient = axios.create({
export const AxiosClient = axios.create({
headers: {
"X-Client-Name": "js-stellar-sdk",
"X-Client-Version": version,
Expand All @@ -34,7 +34,7 @@ function _toSeconds(ms: number): number {
return Math.floor(ms / 1000);
}

HorizonAxiosClient.interceptors.response.use(
AxiosClient.interceptors.response.use(
function interceptorHorizonResponse(response: AxiosResponse) {
const hostname = URI(response.config.url!).hostname();
const serverTime = _toSeconds(Date.parse(response.headers.date));
Expand All @@ -51,7 +51,7 @@ HorizonAxiosClient.interceptors.response.use(
},
);

export default HorizonAxiosClient;
export default AxiosClient;

/**
* Given a hostname, get the current time of that server (i.e., use the last-
Expand Down
15 changes: 15 additions & 0 deletions src/horizon/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Expose all types
export * from "./horizon_api";
export * from "./server_api";

// stellar-sdk classes to expose
export * from "./account_response";

export { Server } from "./server";
export {
default as AxiosClient,
SERVER_TIME_MAP,
getCurrentServerTime
} from "./horizon_axios_client";

export default module.exports;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading