Skip to content

Commit

Permalink
Update to match stellar-sdk implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Nov 30, 2023
1 parent 5dd5ece commit 25095df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ export function parseRawEvents(
return {
latestLedger: r.latestLedger,
events: (r.events ?? []).map((evt) => {
const clone: Omit<SorobanRpc.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
2 changes: 1 addition & 1 deletion src/soroban_rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export namespace SorobanRpc {
}

interface EventResponse extends BaseEventResponse {
contractId: Contract;
contractId?: Contract;
topic: xdr.ScVal[];
value: xdr.ScVal;
}
Expand Down
3 changes: 2 additions & 1 deletion test/unit/server/get_events_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('Server#getEvents', function () {
})
.then(function (response) {
expect(response).to.be.deep.equal(parseEvents(result));
expect(response.events[0].contractId).to.be.undefined;
done();
})
.catch(done);
Expand Down Expand Up @@ -238,7 +239,7 @@ let getEventsResponseFixture = [
type: 'system',
ledger: '1',
ledgerClosedAt: '2022-11-16T16:10:41Z',
contractId,
contractId: '',
id: '0164090849041387521-0000000003',
pagingToken: '164090849041387521-3',
inSuccessfulContractCall: true,
Expand Down

0 comments on commit 25095df

Please sign in to comment.