Skip to content

Commit

Permalink
Merge branch 'master' into payments-type-fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Dec 1, 2023
2 parents fab14ec + f3384ce commit c9b82c8
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 213 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ A breaking change will get clearly marked in this log.

## Unreleased

### Fixed
* The `SorobanRpc.Server.getEvents` method now correctly parses responses without a `contractId` field set. The `events[i].contractId` field on an event is now optional, omitted if there was no ID for the event (e.g. system events; ([#883](https://github.com/stellar/js-stellar-sdk/pull/883))).

### Breaking Changes
* The `PaymentCallBuilder` was incorrectly indicating that it would return a collection of `Payment` records, while [in reality](https://developers.stellar.org/api/horizon/resources/list-all-payments) it can return a handful of "payment-like" records ([#885](https://github.com/stellar/js-stellar-sdk/pull/885)).

Expand Down
4 changes: 2 additions & 2 deletions src/soroban/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export namespace Api {
}

interface EventResponse extends BaseEventResponse {
contractId: Contract;
contractId?: Contract;
topic: xdr.ScVal[];
value: xdr.ScVal;
}
Expand All @@ -171,7 +171,7 @@ export namespace Api {
inSuccessfulContractCall: boolean;
}

interface RawEventResponse extends BaseEventResponse {
export interface RawEventResponse extends BaseEventResponse {
contractId: string;
topic: string[];
value: {
Expand Down
8 changes: 6 additions & 2 deletions src/soroban/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ export function parseRawEvents(
return {
latestLedger: r.latestLedger,
events: (r.events ?? []).map((evt) => {
const clone: Omit<Api.RawEventResponse, 'contractId'> = { ...evt };
delete (clone as any).contractId; // `as any` hack because contractId field isn't optional

// the contractId may be empty so we omit the field in that case
return {
...evt,
contractId: new Contract(evt.contractId),
...clone,
...(evt.contractId !== '' && { contractId: new Contract(evt.contractId) }),
topic: evt.topic.map((topic) => xdr.ScVal.fromXDR(topic, 'base64')),
value: xdr.ScVal.fromXDR(evt.value.xdr, 'base64')
};
Expand Down
Loading

0 comments on commit c9b82c8

Please sign in to comment.