Skip to content

Commit

Permalink
Merge branch 'master' into add-dtslint
Browse files Browse the repository at this point in the history
  • Loading branch information
ShantelPeters authored Nov 9, 2024
2 parents 9881c65 + cfea8de commit 232d6bd
Show file tree
Hide file tree
Showing 11 changed files with 1,158 additions and 1,295 deletions.
26 changes: 17 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ A breaking change will get clearly marked in this log.
## Unreleased


## [v13.0.0-beta.1](https://github.com/stellar/js-stellar-sdk/compare/v12.3.0...v13.0.0-beta.1)
## [v13.0.0-rc.1](https://github.com/stellar/js-stellar-sdk/compare/v12.3.0...v13.0.0-rc.1)

### Breaking Changes
- `contract.AssembledTransaction#signAuthEntries` now takes an `address` instead of a `publicKey`. This brings the API more inline with its actual functionality: It can be used to sign all the auth entries for a particular _address_, whether that is the address of an account (public key) or a contract. ([#1044](https://github.com/stellar/js-stellar-sdk/pull/1044)).

- The Node.js code will now Babelify to Node 18 instead of Node 16, but we stopped supporting Node 16 long ago so this shouldn't be a breaking change.

- Deprecated RPC APIs have been removed ([#1084](https://github.com/stellar/js-stellar-sdk/pull/1084)):
* `simulateTransaction`'s `cost` field is removed
* `getEvents` returns a `cursor` field that matches `pagingToken` and `id`
* `getTransactions` returns a `txHash` field
- Horizon Server API types: removed fields `transaction_count`, `base_fee`, and `base_reserve` (deprecated since [v10.0.1](https://github.com/stellar/js-stellar-sdk/releases/tag/v10.0.1))
- `SentTransaction.init` and `new SentTransaction` now take _one_ (1) argument instead of _two_ (2). The first argument had previously been deprecated and ignored. To update:

```diff
-SentTransaction(nonsense, realStuff)
+SentTransaction(realStuff)
-new SentTransaction(nonsense, realStuff)
+new SentTransaction(realStuff)
```

- `SorobanRpc` import, previously deprecated, has been removed. You can import `rpc` instead:

```diff
-import { SorobanRpc } from '@stellar/stellar-sdk'
+import { rpc } from '@stellar/stellar-sdk'
Expand All @@ -36,7 +34,17 @@ A breaking change will get clearly marked in this log.
import { Server } from '@stellar/stellar-sdk/rpc'
```

- Horizon Server API types: removed fields `transaction_count`, `base_fee`, and `base_reserve` (deprecated since [v10.0.1](https://github.com/stellar/js-stellar-sdk/releases/tag/v10.0.1))

### Added
- `rpc.Server` now has a `pollTransaction` method to retry transaction retrieval ([#1092]https://github.com/stellar/js-stellar-sdk/pull/1092).


## [v13.0.0-beta.1](https://github.com/stellar/js-stellar-sdk/compare/v12.3.0...v13.0.0-beta.1)

### Breaking Changes
- `contract.AssembledTransaction#signAuthEntries` now takes an `address` instead of a `publicKey`. This brings the API more inline with its actual functionality: It can be used to sign all the auth entries for a particular _address_, whether that is the address of an account (public key) or a contract. ([#1044](https://github.com/stellar/js-stellar-sdk/pull/1044)).

- The Node.js code will now Babelify to Node 18 instead of Node 16, but we stopped supporting Node 16 long ago so this shouldn't be a breaking change.

### Added
- You can now build the browser bundle without various dependencies:
Expand Down
8 changes: 7 additions & 1 deletion config/.jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
"source": {
"include": ["lib/", "js-stellar-base/src"],
"includePattern": "\\.(js|ts)$",
"exclude": "js-stellar-base/src/generated"
"exclude": [
"js-stellar-base/src/generated",
"lib/minimal",
"lib/no-axios",
"lib/no-eventsource",
"lib/contract/utils.d.ts"
]
},
"opts": {
"encoding": "utf8",
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stellar/stellar-sdk",
"version": "13.0.0-beta.1",
"version": "13.0.0-rc.1",
"description": "A library for working with the Stellar network, including communication with the Horizon and Soroban RPC servers.",
"keywords": [
"stellar"
Expand Down Expand Up @@ -143,21 +143,21 @@
]
},
"devDependencies": {
"@babel/cli": "^7.25.6",
"@babel/core": "^7.24.9",
"@babel/eslint-plugin": "^7.24.7",
"@babel/preset-env": "^7.25.4",
"@babel/preset-typescript": "^7.24.7",
"@babel/register": "^7.24.6",
"@definitelytyped/dtslint": "^0.2.25",
"@babel/cli": "^7.25.9",
"@babel/core": "^7.26.0",
"@babel/eslint-plugin": "^7.25.9",
"@babel/preset-env": "^7.26.0",
"@babel/preset-typescript": "^7.26.0",
"@babel/register": "^7.25.9",
"@definitelytyped/dtslint": "^0.2.27",
"@istanbuljs/nyc-config-babel": "3.0.0",
"@stellar/tsconfig": "^1.0.2",
"@types/chai": "^4.3.19",
"@types/detect-node": "^2.0.0",
"@types/eventsource": "^1.1.12",
"@types/json-schema": "^7.0.15",
"@types/lodash": "^4.17.7",
"@types/mocha": "^10.0.8",
"@types/lodash": "^4.17.13",
"@types/mocha": "^10.0.9",
"@types/node": "^20.14.11",
"@types/randombytes": "^2.0.1",
"@types/sinon": "^17.0.2",
Expand Down Expand Up @@ -186,8 +186,8 @@
"eslint-webpack-plugin": "^4.2.0",
"ghooks": "^2.0.4",
"husky": "^9.1.6",
"jsdoc": "^4.0.2",
"json-schema-faker": "^0.5.6",
"jsdoc": "^4.0.4",
"json-schema-faker": "^0.5.8",
"karma": "^6.4.3",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
Expand All @@ -198,7 +198,7 @@
"karma-webpack": "^5.0.1",
"lint-staged": "^15.2.10",
"lodash": "^4.17.21",
"mocha": "^10.6.0",
"mocha": "^10.8.2",
"node-polyfill-webpack-plugin": "^3.0.0",
"null-loader": "^4.0.1",
"nyc": "^17.0.0",
Expand All @@ -209,12 +209,12 @@
"taffydb": "^2.7.3",
"terser-webpack-plugin": "^5.3.10",
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"webpack": "^5.94.0",
"typescript": "^5.6.3",
"webpack": "^5.96.1",
"webpack-cli": "^5.0.1"
},
"dependencies": {
"@stellar/stellar-base": "13.0.0-beta.1",
"@stellar/stellar-base": "^13.0.0",
"axios": "^1.7.7",
"bignumber.js": "^9.1.2",
"eventsource": "^2.0.2",
Expand Down
31 changes: 20 additions & 11 deletions src/rpc/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import { Contract, SorobanDataBuilder, xdr } from '@stellar/stellar-base';

/* tslint:disable-next-line:no-namespace */
export namespace Api {

export interface Cost {
cpuInsns: string;
memBytes: string;
}

export interface GetHealthResponse {
status: 'healthy';
}
Expand Down Expand Up @@ -72,6 +66,7 @@ export namespace Api {

interface GetAnyTransactionResponse {
status: GetTransactionStatus;
txHash: string;
latestLedger: number;
latestLedgerCloseTime: number;
oldestLedger: number;
Expand Down Expand Up @@ -119,15 +114,17 @@ export namespace Api {
latestLedgerCloseTime: number;
oldestLedger: number;
oldestLedgerCloseTime: number;
txHash: string;

// the fields below are set if status is SUCCESS
applicationOrder?: number;
feeBump?: boolean;
ledger?: number;
createdAt?: number;

envelopeXdr?: string;
resultXdr?: string;
resultMetaXdr?: string;
ledger?: number;
createdAt?: number;
diagnosticEventsXdr?: string[];
}

Expand All @@ -143,6 +140,8 @@ export namespace Api {
createdAt: number;
applicationOrder: number;
feeBump: boolean;
txHash: string;

envelopeXdr?: string;
resultXdr?: string;
resultMetaXdr?: string;
Expand All @@ -155,6 +154,8 @@ export namespace Api {
createdAt: number;
applicationOrder: number;
feeBump: boolean;
txHash: string;

envelopeXdr: xdr.TransactionEnvelope;
resultXdr: xdr.TransactionResult;
resultMetaXdr: xdr.TransactionMeta;
Expand Down Expand Up @@ -209,6 +210,7 @@ export namespace Api {
type: EventType;
ledger: number;
ledgerClosedAt: string;
cursor: string;
pagingToken: string;
inSuccessfulContractCall: boolean;
txHash: string;
Expand Down Expand Up @@ -317,7 +319,6 @@ export namespace Api {
extends BaseSimulateTransactionResponse {
transactionData: SorobanDataBuilder;
minResourceFee: string;
cost: Cost;

/** present only for invocation simulation */
result?: SimulateHostFunctionResult;
Expand Down Expand Up @@ -403,7 +404,6 @@ export namespace Api {
* invokeHostFunctionOperation is supported per transaction.
* */
results?: RawSimulateHostFunctionResult[];
cost?: Cost;
/** Present if succeeded but has expired ledger entries */
restorePreamble?: {
minResourceFee: string;
Expand All @@ -416,9 +416,18 @@ export namespace Api {

export interface GetVersionInfoResponse {
version: string;
commitHash: string;
buildTimestamp: string;
captiveCoreVersion: string;
protocolVersion: number; // uint32

/// @deprecated
commit_hash: string;
build_time_stamp: string;
/// @deprecated
build_timestamp: string;
/// @deprecated
captive_core_version: string;
/// @deprecated
protocol_version: number; // uint32
}

Expand Down
12 changes: 7 additions & 5 deletions src/rpc/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ export function parseRawSendTransaction(
return { ...raw } as Api.BaseSendTransactionResponse;
}

export function parseTransactionInfo(raw: Api.RawTransactionInfo | Api.RawGetTransactionResponse): Omit<Api.TransactionInfo, 'status'> {
export function parseTransactionInfo(
raw: Api.RawTransactionInfo | Api.RawGetTransactionResponse
): Omit<Api.TransactionInfo, 'status' | 'txHash'> {
const meta = xdr.TransactionMeta.fromXDR(raw.resultMetaXdr!, 'base64');
const info: Omit<Api.TransactionInfo, 'status'> = {
const info: Omit<Api.TransactionInfo, 'status' | 'txHash'> = {
ledger: raw.ledger!,
createdAt: raw.createdAt!,
applicationOrder: raw.applicationOrder!,
Expand Down Expand Up @@ -64,6 +66,7 @@ export function parseRawTransactions(
): Api.TransactionInfo {
return {
status: r.status,
txHash: r.txHash,
...parseTransactionInfo(r),
};
}
Expand Down Expand Up @@ -147,11 +150,10 @@ function parseSuccessful(
...partial,
transactionData: new SorobanDataBuilder(sim.transactionData!),
minResourceFee: sim.minResourceFee!,
cost: sim.cost!,
...// coalesce 0-or-1-element results[] list into a single result struct
// coalesce 0-or-1-element results[] list into a single result struct
// with decoded fields if present
// eslint-disable-next-line no-self-compare
((sim.results?.length ?? 0 > 0) && {
...((sim.results?.length ?? 0 > 0) && {
result: sim.results!.map((row) => ({
auth: (row.auth ?? []).map((entry) =>
xdr.SorobanAuthorizationEntry.fromXDR(entry, 'base64')
Expand Down
1 change: 1 addition & 0 deletions src/rpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ export class RpcServer {

const result: Api.GetTransactionResponse = {
status: raw.status,
txHash: hash,
latestLedger: raw.latestLedger,
latestLedgerCloseTime: raw.latestLedgerCloseTime,
oldestLedger: raw.oldestLedger,
Expand Down
8 changes: 4 additions & 4 deletions test/unit/server/soroban/get_events_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ let getEventsResponseFixture = [
ledgerClosedAt: "2022-11-16T16:10:41Z",
contractId: "",
id: "0164090849041387521-0000000003",
pagingToken: "164090849041387521-3",
cursor: "164090849041387521-3",
inSuccessfulContractCall: true,
topic: topicVals.slice(0, 2),
value: eventVal,
Expand All @@ -254,7 +254,7 @@ let getEventsResponseFixture = [
ledgerClosedAt: "2022-11-16T16:10:41Z",
contractId,
id: "0164090849041387521-0000000003",
pagingToken: "164090849041387521-3",
cursor: "164090849041387521-3",
inSuccessfulContractCall: true,
topic: topicVals.slice(0, 2),
value: eventVal,
Expand All @@ -266,7 +266,7 @@ let getEventsResponseFixture = [
ledgerClosedAt: "2022-11-16T16:10:41Z",
contractId,
id: "0164090849041387521-0000000003",
pagingToken: "164090849041387521-3",
cursor: "164090849041387521-3",
inSuccessfulContractCall: true,
topic: [topicVals[0]],
value: eventVal,
Expand All @@ -278,7 +278,7 @@ let getEventsResponseFixture = [
ledgerClosedAt: "2022-12-14T01:01:20Z",
contractId,
id: "0000000171798695936-0000000001",
pagingToken: "0000000171798695936-0000000001",
cursor: "0000000171798695936-0000000001",
inSuccessfulContractCall: true,
topic: topicVals,
value: eventVal,
Expand Down
10 changes: 5 additions & 5 deletions test/unit/server/soroban/get_transaction_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe("Server#getTransaction", function () {
transaction.sign(keypair);

this.transaction = transaction;
this.hash = this.transaction.hash().toString("hex");
this.blob = transaction.toEnvelope().toXDR().toString("base64");
this.prepareAxios = (result) => {
this.axiosMock
Expand All @@ -42,7 +41,7 @@ describe("Server#getTransaction", function () {
jsonrpc: "2.0",
id: 1,
method: "getTransaction",
params: { hash: this.hash },
params: { hash: result.txHash },
})
.returns(Promise.resolve({ data: { id: 1, result } }));
};
Expand All @@ -58,7 +57,7 @@ describe("Server#getTransaction", function () {
this.prepareAxios(result);

this.server
.getTransaction(this.hash)
.getTransaction(result.txHash)
.then(function (response) {
expect(response).to.be.deep.equal(result);
done();
Expand All @@ -84,7 +83,7 @@ describe("Server#getTransaction", function () {
.returnValue();

this.server
.getTransaction(this.hash)
.getTransaction(result.txHash)
.then((resp) => {
expect(Object.keys(resp)).to.eql(Object.keys(expected));
expect(resp).to.eql(expected);
Expand All @@ -99,7 +98,7 @@ describe("Server#getTransaction", function () {
this.prepareAxios(result);

this.server
.getTransaction(this.hash)
.getTransaction(result.txHash)
.then((resp) => {
expect(resp).to.be.deep.equal(result);
done();
Expand Down Expand Up @@ -152,6 +151,7 @@ function makeTxResult(status, addSoroban = true) {

return {
status,
txHash: "ae9f315c048d87a5f853bc15bf284a2c3c89eb0e1cb38c10409b77a877b830a8",
latestLedger: 100,
latestLedgerCloseTime: 12345,
oldestLedger: 50,
Expand Down
1 change: 1 addition & 0 deletions test/unit/server/soroban/get_transactions_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function makeTxResult(ledger, applicationOrder, status) {
return {
status: status,
ledger: ledger,
txHash: "ae9f315c048d87a5f853bc15bf284a2c3c89eb0e1cb38c10409b77a877b830a8",
createdAt: ledger * 25 + 100,
applicationOrder: applicationOrder,
feeBump: false,
Expand Down
Loading

0 comments on commit 232d6bd

Please sign in to comment.