Skip to content
This repository has been archived by the owner on Oct 6, 2021. It is now read-only.

cbor decode for emitted events ; spellings #331

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

ssavvides
Copy link
Contributor

This PR:

  • Fixes a bug in packages/service/src/coder/oasis.ts when decoding a subscription event.
  • Fixes some minor spelling mistakes

@ssavvides ssavvides requested a review from nhynes December 3, 2019 07:09
@@ -3,7 +3,7 @@
* @param keystring is the EthHex encoding of the value
* @param littleEndian is true if the keystring should be interpreted as
* little endian. Otherwise, defaults to big endian.
* @returns the byte incoding of the value
* @returns the byte encoding of the value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

@@ -43,7 +43,8 @@ export class OasisCoder implements RpcCoder {
}

public async decodeSubscriptionEvent(e: any, _idl: Idl): Promise<any> {
const event = cbor.decode(bytes.parseHex(e.data));
const eventBytes = bytes.parseHex(e.data).slice(4); // remove size of event
Copy link
Contributor

@nhynes nhynes Dec 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const eventBytes = bytes.parseHex(e.data).slice(4); // remove size of event
const eventBytes = bytes.parseHex(e.data);
const payloadSize = new Uint32Array(new Uint8Array(eventBytes.splice(0, 4)))[0];
const payloadBytes = eventBytes).slice(payloadSize);

probably best not to ignore it. at the very least it's a sanity check

Copy link
Contributor Author

@ssavvides ssavvides Dec 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this meant to be const payloadBytes = eventBytes.slice(-payloadSize);?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. (0, payloadSize) thanks for catching

@@ -43,7 +43,8 @@ export class OasisCoder implements RpcCoder {
}

public async decodeSubscriptionEvent(e: any, _idl: Idl): Promise<any> {
const event = cbor.decode(bytes.parseHex(e.data));
const eventBytes = bytes.parseHex(e.data).slice(4); // remove size of event
const event = cbor.decode(eventBytes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const event = cbor.decode(eventBytes);
const event = cbor.decode(payloadBytes);

@nhynes
Copy link
Contributor

nhynes commented Dec 3, 2019

to get CI to pass, you'll want to update the toolchain installed in .circleci/config.yml to unstable

@nhynes nhynes force-pushed the master branch 2 times, most recently from 1f1aee7 to 1cedcb3 Compare February 21, 2020 16:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants