Skip to content

Commit

Permalink
Merge branch 'master' into feat/more-better
Browse files Browse the repository at this point in the history
* master:
  Drop all usage of array-based passing (#924)
  Release v11.2.2 (#918)
  Ensure that event streaming tests write a valid stream (#917)
  Release v11.2.1 (#913)
  Eliminating `utility-types` dependency entirely (#912)
  Prepare v11.2.0 for release (#908)
  Update README to flow better (#907)
  Add support for new `sendTransaction` response field (#905)
  Export the individual event response instance (#904)
  Bump follow-redirects from 1.15.3 to 1.15.4 (#906)
  Update examples to use new module and package structure. (#900)
  • Loading branch information
chadoh committed Mar 5, 2024
2 parents 93e0b2f + 0e4a0b0 commit 523812e
Show file tree
Hide file tree
Showing 16 changed files with 629 additions and 566 deletions.
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: [18, 20]
node-version: [18, 20, 21]

steps:
- name: Checkout
Expand Down
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ A breaking change will get clearly marked in this log.

## Unreleased

### Fixed
* `SorobanRpc`: remove all instances of array-based parsing to conform to future breaking changes in Soroban RPC ([#924](https://github.com/stellar/js-stellar-sdk/pull/924)).


## [v11.2.2](https://github.com/stellar/js-stellar-sdk/compare/v11.2.1...v11.2.2)

### Fixed
* Event streaming tests now pass on Node 20, which seems to have tighter conformance to the spec ([#917](https://github.com/stellar/js-stellar-sdk/pull/917)).
* `@stellar/stellar-base` has been upgraded to its latest major version ([#918](https://github.com/stellar/js-stellar-sdk/pull/918), see [v11.0.0](https://github.com/stellar/js-stellar-base/releases/tag/v11.0.0) for release notes).


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

### Fixed
* An unnecessary dependency has been removed which was causing a TypeScript error in certain environments ([#912](https://github.com/stellar/js-stellar-sdk/pull/912)).
* Dependencies have been upgraded (see [`stellar-base@v10.0.2`](https://github.com/stellar/js-stellar-base/releases/tag/v10.0.2) for release notes, [#913](https://github.com/stellar/js-stellar-sdk/pull/913)).


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

### Added
* Support for the new, optional `diagnosticEventsXdr` field on the `SorobanRpc.Server.sendTransaction` method. The raw field will be present when using the `_sendTransaction` method, while the normal method will have an already-parsed `diagnosticEvents: xdr.DiagnosticEvent[]` field, instead ([#905](https://github.com/stellar/js-stellar-sdk/pull/905)).
* A new exported interface `SorobanRpc.Api.EventResponse` so that developers can type-check individual events ([#904](https://github.com/stellar/js-stellar-sdk/pull/904)).

### Updated
* Dependencies have been updated to their latest versions ([#906](https://github.com/stellar/js-stellar-sdk/pull/906), [#908](https://github.com/stellar/js-stellar-sdk/pull/908)).


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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ module.exports = {

There is also a [sample](https://github.com/fnando/rn-stellar-sdk-sample) that you can follow.

**Note**: Only the V8 compiler (on Android) and JSC (on iOS) have proper support for `Buffer` and `Uint8Array` as is needed by this library. Otherwise, you may see bizarre errors when doing XDR encoding/decoding such as `source not specified`.

#### Usage with Expo managed workflows

1. Install `yarn add --dev rn-nodeify`
Expand Down
33 changes: 16 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stellar/stellar-sdk",
"version": "11.2.0",
"version": "11.2.2",
"description": "A library for working with the Stellar network, including communication with the Horizon and Soroban RPC servers.",
"keywords": [
"stellar"
Expand Down Expand Up @@ -77,11 +77,11 @@
]
},
"devDependencies": {
"@babel/cli": "^7.23.0",
"@babel/core": "^7.23.7",
"@babel/eslint-parser": "^7.22.15",
"@babel/cli": "^7.23.9",
"@babel/core": "^7.23.9",
"@babel/eslint-parser": "^7.23.10",
"@babel/eslint-plugin": "^7.22.10",
"@babel/preset-env": "^7.23.8",
"@babel/preset-env": "^7.23.9",
"@babel/preset-typescript": "^7.23.0",
"@babel/register": "^7.23.7",
"@definitelytyped/dtslint": "^0.1.2",
Expand All @@ -93,11 +93,11 @@
"@types/json-schema": "^7.0.15",
"@types/lodash": "^4.14.199",
"@types/mocha": "^10.0.2",
"@types/node": "^20.10.8",
"@types/node": "^20.11.17",
"@types/randombytes": "^2.0.1",
"@types/sinon": "^17.0.2",
"@types/urijs": "^1.19.20",
"@typescript-eslint/parser": "^6.18.1",
"@typescript-eslint/parser": "^6.20.0",
"ava": "^5.3.1",
"axios-mock-adapter": "^1.22.0",
"babel-loader": "^9.1.3",
Expand All @@ -119,40 +119,39 @@
"ghooks": "^2.0.4",
"husky": "^8.0.3",
"jsdoc": "^4.0.2",
"json-schema-faker": "^0.5.4",
"json-schema-faker": "^0.5.5",
"karma": "^6.4.1",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.2.1",
"karma-firefox-launcher": "^2.1.1",
"karma-mocha": "^2.0.0",
"karma-sinon-chai": "^2.0.2",
"karma-webpack": "^5.0.0",
"lint-staged": "^15.2.0",
"karma-webpack": "^5.0.1",
"lint-staged": "^15.2.2",
"lodash": "^4.17.21",
"minami": "^1.1.1",
"mocha": "^10.2.0",
"mocha": "^10.3.0",
"node-polyfill-webpack-plugin": "^3.0.0",
"nyc": "^15.1.0",
"prettier": "^3.1.1",
"prettier": "^3.2.5",
"randombytes": "^2.1.0",
"sinon": "^17.0.1",
"sinon-chai": "^3.7.0",
"taffydb": "^2.7.3",
"terser-webpack-plugin": "^5.3.10",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"utility-types": "^3.7.0",
"webpack": "^5.88.2",
"webpack": "^5.90.1",
"webpack-cli": "^5.0.1"
},
"dependencies": {
"@stellar/stellar-base": "10.0.1",
"axios": "^1.6.5",
"@stellar/stellar-base": "^11.0.0",
"axios": "^1.6.7",
"bignumber.js": "^9.1.2",
"eventsource": "^2.0.2",
"randombytes": "^2.1.0",
"toml": "^3.0.0",
"typescript": "^5.3.3",
"urijs": "^1.19.1"
},
"ava": {
Expand Down
3 changes: 1 addition & 2 deletions src/contract_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,9 +912,8 @@ const PRIMITIVE_DEFINITONS: { [key: string]: JSONSchema7Definition } = {
};

/**
*
* @param typeDef type to convert to json schema reference
* @returns
* @returns {JSONSchema7} a schema describing the type
*/
function typeRef(typeDef: xdr.ScSpecTypeDef): JSONSchema7 {
let t = typeDef.switch();
Expand Down
1 change: 0 additions & 1 deletion src/horizon/server_api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Asset } from "@stellar/stellar-base";
import { Omit } from "utility-types";
import { HorizonApi } from "./horizon_api";

// more types
Expand Down
31 changes: 2 additions & 29 deletions src/soroban/jsonrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,11 @@ export interface Error<E = any> {
data?: E;
}

/**
* Sends the jsonrpc 'params' as an array.
*/
export async function post<T>(
url: string,
method: string,
...params: any
): Promise<T> {
if (params && params.length < 1) {
params = null;
}
const response = await axios.post<Response<T>>(url, {
jsonrpc: "2.0",
// TODO: Generate a unique request id
id: 1,
method,
params,
});
if (hasOwnProperty(response.data, "error")) {
throw response.data.error;
} else {
return response.data?.result;
}
}

/**
* Sends the jsonrpc 'params' as the single 'param' obj, no array wrapper is applied.
*/
/** Sends the jsonrpc 'params' as a single 'param' object (no array support). */
export async function postObject<T>(
url: string,
method: string,
param: any,
param: any = null,
): Promise<T> {
const response = await axios.post<Response<T>>(url, {
jsonrpc: "2.0",
Expand Down
19 changes: 10 additions & 9 deletions src/soroban/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class Server {
* });
*/
public async getHealth(): Promise<Api.GetHealthResponse> {
return jsonrpc.post<Api.GetHealthResponse>(
return jsonrpc.postObject<Api.GetHealthResponse>(
this.serverURL.toString(),
'getHealth'
);
Expand Down Expand Up @@ -276,10 +276,11 @@ export class Server {

public async _getLedgerEntries(...keys: xdr.LedgerKey[]) {
return jsonrpc
.post<Api.RawGetLedgerEntriesResponse>(
.postObject<Api.RawGetLedgerEntriesResponse>(
this.serverURL.toString(),
'getLedgerEntries',
keys.map((k) => k.toXDR('base64'))
'getLedgerEntries', {
keys: keys.map((k) => k.toXDR('base64'))
}
);
}

Expand Down Expand Up @@ -350,7 +351,7 @@ export class Server {
public async _getTransaction(
hash: string
): Promise<Api.RawGetTransactionResponse> {
return jsonrpc.post(this.serverURL.toString(), 'getTransaction', hash);
return jsonrpc.postObject(this.serverURL.toString(), 'getTransaction', {hash});
}

/**
Expand Down Expand Up @@ -427,7 +428,7 @@ export class Server {
* });
*/
public async getNetwork(): Promise<Api.GetNetworkResponse> {
return await jsonrpc.post(this.serverURL.toString(), 'getNetwork');
return await jsonrpc.postObject(this.serverURL.toString(), 'getNetwork');
}

/**
Expand All @@ -446,7 +447,7 @@ export class Server {
* });
*/
public async getLatestLedger(): Promise<Api.GetLatestLedgerResponse> {
return jsonrpc.post(this.serverURL.toString(), 'getLatestLedger');
return jsonrpc.postObject(this.serverURL.toString(), 'getLatestLedger');
}

/**
Expand Down Expand Up @@ -647,10 +648,10 @@ export class Server {
public async _sendTransaction(
transaction: Transaction | FeeBumpTransaction
): Promise<Api.RawSendTransactionResponse> {
return jsonrpc.post(
return jsonrpc.postObject(
this.serverURL.toString(),
'sendTransaction',
transaction.toXDR()
{ transaction: transaction.toXDR() }
);
}

Expand Down
13 changes: 8 additions & 5 deletions test/integration/client_headers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ describe("integration tests: client headers", function (done) {
let query = url.parse(request.url, true).query;
expect(query["X-Client-Name"]).to.be.equal("js-stellar-sdk");
expect(query["X-Client-Version"]).to.match(versionPattern);

// write a valid event stream so that we don't error prematurely
response.writeHead(200, {
"Content-Type": "text/event-stream",
});
response.write("retry: 10\nevent: close\ndata: byebye\n\n");
response.end();

server.close(() => {
closeStream();
done();
Expand All @@ -62,11 +69,7 @@ describe("integration tests: client headers", function (done) {
allowHttp: true,
})
.operations()
.stream({
onerror: (err) => {
done(err);
},
});
.stream({ onerror: (err) => done(err) });
});
});
});
4 changes: 2 additions & 2 deletions test/unit/server/soroban/get_account_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Server#getAccount", function () {
jsonrpc: "2.0",
id: 1,
method: "getLedgerEntries",
params: [[key.toXDR("base64")]],
params: { keys: [ key.toXDR("base64") ] },
})
.returns(
Promise.resolve({
Expand Down Expand Up @@ -62,7 +62,7 @@ describe("Server#getAccount", function () {
jsonrpc: "2.0",
id: 1,
method: "getLedgerEntries",
params: [[key.toXDR("base64")]],
params: { keys: [ key.toXDR("base64") ] },
})
.returns(
Promise.resolve({
Expand Down
4 changes: 2 additions & 2 deletions test/unit/server/soroban/get_contract_data_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("Server#getContractData", function () {
jsonrpc: "2.0",
id: 1,
method: "getLedgerEntries",
params: [[ledgerKey.toXDR("base64")]],
params: { keys: [ledgerKey.toXDR("base64")] },
})
.returns(
Promise.resolve({
Expand Down Expand Up @@ -99,7 +99,7 @@ describe("Server#getContractData", function () {
jsonrpc: "2.0",
id: 1,
method: "getLedgerEntries",
params: [[ledgerKeyDupe.toXDR("base64")]],
params: { keys: [ledgerKeyDupe.toXDR("base64")] },
})
.returns(Promise.resolve({ data: { result: { entries: [] } } }));

Expand Down
2 changes: 1 addition & 1 deletion test/unit/server/soroban/get_ledger_entries_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("Server#getLedgerEntries", function () {
jsonrpc: "2.0",
id: 1,
method: "getLedgerEntries",
params: [requests],
params: {keys: requests},
})
.returns(
Promise.resolve({
Expand Down
2 changes: 1 addition & 1 deletion test/unit/server/soroban/get_transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("Server#getTransaction", function () {
jsonrpc: "2.0",
id: 1,
method: "getTransaction",
params: [this.hash],
params: { hash: this.hash },
})
.returns(Promise.resolve({ data: { id: 1, result } }));
};
Expand Down
2 changes: 1 addition & 1 deletion test/unit/server/soroban/request_airdrop_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe("Server#requestAirdrop", function () {
jsonrpc: "2.0",
id: 1,
method: "getLedgerEntries",
params: [[accountKey.toXDR("base64")]],
params: { keys: [accountKey.toXDR("base64")] },
})
.returns(
Promise.resolve({
Expand Down
4 changes: 2 additions & 2 deletions test/unit/server/soroban/send_transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("Server#sendTransaction", function () {
jsonrpc: "2.0",
id: 1,
method: "sendTransaction",
params: [this.blob],
params: { transaction: this.blob },
})
.returns(
Promise.resolve({
Expand Down Expand Up @@ -78,7 +78,7 @@ describe("Server#sendTransaction", function () {
jsonrpc: "2.0",
id: 1,
method: "sendTransaction",
params: [this.blob],
params: { transaction: this.blob },
})
.returns(
Promise.resolve({
Expand Down
Loading

0 comments on commit 523812e

Please sign in to comment.