Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor: remove unneeded bytes<->hex conversions in byte_to_base58 #24324

Merged

Conversation

theStack
Copy link
Contributor

It seems like the only reason for using hex strings in this method was to have a convenient way to convert to an integer from the input data interpreted as big-endian. In Python3 we have int.from_bytes(..., 'big') for that purpose, hence there is no need for that anymore and we can simply operate on bytes only.

@theStack theStack force-pushed the 202202-test-refactor_simplify-byte_to_base58 branch from 35ad44b to 6967579 Compare February 12, 2022 02:11
@theStack theStack changed the title test: refactor: remove uneeded bytes<->hex conversions in byte_to_base58 test: refactor: remove unneeded bytes<->hex conversions in byte_to_base58 Feb 12, 2022
@DrahtBot DrahtBot added the Tests label Feb 12, 2022
Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

Code Review ACK

This PR rewrites the byte_to_base58 function, which removes the need for bytes <-> hex conversion. I have manually tested the old and new code, and their results are identical.

Screenshot:

Master PR
Master PR

The updated code is clean and concise, and I agree that it can be merged.

@@ -55,17 +55,15 @@ def create_deterministic_address_bcrt1_p2tr_op_true():

def byte_to_base58(b, version):
result = ''
str = b.hex()
Copy link
Member

Choose a reason for hiding this comment

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

Oof, this was some terrible python code, thanks for improving it 😄

…ase58`

It seems like the only reason for using hex strings in this
method was to have a convenient way to convert to an integer
from the input data interpreted as big-endian.
In Python3 we have `int.from_bytes(..., 'big')` for that
purpose, hence there is no need for that anymore and we can
simply operate on bytes only.
@theStack theStack force-pushed the 202202-test-refactor_simplify-byte_to_base58 branch from 6967579 to f11dad2 Compare February 14, 2022 11:49
@laanwj
Copy link
Member

laanwj commented Feb 14, 2022

Code review ACK f11dad2

@maflcko maflcko merged commit 7164e00 into bitcoin:master Feb 15, 2022
@theStack theStack deleted the 202202-test-refactor_simplify-byte_to_base58 branch February 15, 2022 11:28
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 15, 2022
…ersions in `byte_to_base58`

f11dad2 test: refactor: remove unneeded bytes<->hex conversions in `byte_to_base58` (Sebastian Falbesoner)

Pull request description:

  It seems like the only reason for using hex strings in this method was to have a convenient way to convert to an integer from the input data interpreted as big-endian. In Python3 we have `int.from_bytes(..., 'big')` for that purpose, hence there is no need for that anymore and we can simply operate on bytes only.

ACKs for top commit:
  laanwj:
    Code review ACK f11dad2

Tree-SHA512: 9b1563010066ca74d85139c3b9259e9a5bb49e1f141c30b6506a0445afddb2bde7fd421fdd917dc516956e66f93610e2c21d720817640daee8f57f803be76ee4
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 7, 2022
…ase58`

Summary:
It seems like the only reason for using hex strings in this method was to have a convenient way to convert to an integer from the input data interpreted as big-endian.
In Python3 we have `int.from_bytes(..., 'big')` for that purpose, hence there is no need for that anymore and we can simply operate on bytes only.

This is a backport of [[bitcoin/bitcoin#24324 | core#24324]]

Depends on D11136

Test Plan: `ninja check-functional-extended`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11138
@bitcoin bitcoin locked and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants