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

Make bytes methods type strict #244

Merged
merged 6 commits into from
Apr 27, 2020
Merged

Make bytes methods type strict #244

merged 6 commits into from
Apr 27, 2020

Conversation

cgewecke
Copy link
Contributor

@cgewecke cgewecke commented Apr 24, 2020

Part of #172 Breaking API changes

  • Enforces Buffer input for setLengthLeft, setLengthRight
  • Removes setLength (alias for setLengthLeft)
  • Removes stripZeros (alias for unPad)
  • Splits unpad into:
    • unpadBuffer
    • unpadHexString
    • unpadArray

(Will make similar changes for the methods in hash.ts and signature.ts in a separate PR)

@cgewecke cgewecke changed the base branch from enforce-buffer-accounts to master April 27, 2020 07:00
@github-actions
Copy link

Coverage Status

Coverage increased (+0.01%) to 99.672% when pulling d1fc502 on split-bytes-methods into 2e0ec40 on master.

@cgewecke cgewecke marked this pull request as ready for review April 27, 2020 07:08
src/bytes.ts Show resolved Hide resolved
@cgewecke cgewecke requested a review from holgerd77 April 27, 2020 07:15
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Generally looks good, two things (+ 1 typo) to address.

src/bytes.ts Outdated
*/
export const setLengthLeft = function(msg: any, length: number, right: boolean = false) {
export const setLengthLeft = function(msg: Buffer, length: number, right: boolean = false) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this is pretty confusing to have this boolean right parameter in the API. Can we instead do an internal setLength method and move the logic over there and do function signature (so: function(msg: Buffer, length: number)) and internal structure analogue to setLengthRight?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's definitely nicer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in a2a50ae

src/bytes.ts Outdated
* @param a (Buffer)
* @return (Buffer)
*/
export const unpadBuffer = function(a: any): Buffer {
Copy link
Member

Choose a reason for hiding this comment

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

I assume having an any type here is a mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ai! Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 1f2803c

src/bytes.ts Outdated
}

/**
* Trims leading zeros from a `Array` (of numbers).
Copy link
Member

Choose a reason for hiding this comment

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

Nit-pick "an Array"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 82ab4b4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 82ab4b4

src/bytes.ts Show resolved Hide resolved
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Looks good

@holgerd77 holgerd77 merged commit ca2a31c into master Apr 27, 2020
@holgerd77 holgerd77 deleted the split-bytes-methods branch April 27, 2020 17:45
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.

None yet

2 participants