Skip to content

Commit

Permalink
Add proper clone instead of field hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Nov 29, 2023
1 parent 16da990 commit a836c99
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/soroban/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ 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
const cid = evt.contractId;
delete (evt as any).contractId;
const rv = {
...evt as Omit<Api.RawEventResponse, 'contractId'>,
...(cid !== '' && { contractId: new Contract(cid) }),
return {
...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')
};
evt.contractId = cid; // put value back after parsing
return rv;
})
};
}
Expand Down

0 comments on commit a836c99

Please sign in to comment.