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

fix: pretty print PublicKey objects in node and in the browser #29062

Merged
merged 1 commit into from Dec 9, 2022
Merged

fix: pretty print PublicKey objects in node and in the browser #29062

merged 1 commit into from Dec 9, 2022

Conversation

steveluscher
Copy link
Contributor

Problem

console.log(publicKey) is unreadable in Node.

Summary of Changes

Add an object stringifier that includes the base58 string.

Test plan

Node
$ node
Welcome to Node.js v16.18.1.
Type ".help" for more information.
> const {PublicKey} = require('./lib/index.cjs.js')
undefined
> console.log(PublicKey.default.toString())
11111111111111111111111111111111
undefined
> console.log(PublicKey.default)
PublicKey [PublicKey(11111111111111111111111111111111)] {
  _bn: <BN: 0>
}
undefined
Browser

image

Fixes #20022.

@github-actions github-actions bot added the web3.js Related to the JavaScript client label Dec 3, 2022
@steveluscher
Copy link
Contributor Author

I'll have to double check that this doesn't narrow our browser compatibility too much (eg. for browsers that are missing Symbol) and that it still works in React Native. cc/ @jacobcreech

@codecov
Copy link

codecov bot commented Dec 3, 2022

Codecov Report

Merging #29062 (287f838) into master (35f3c18) will decrease coverage by 0.0%.
The diff coverage is 100.0%.

@@            Coverage Diff            @@
##           master   #29062     +/-   ##
=========================================
- Coverage    76.8%    76.7%   -0.1%     
=========================================
  Files          55       55             
  Lines        3127     3141     +14     
  Branches      466      472      +6     
=========================================
+ Hits         2403     2411      +8     
- Misses        559      565      +6     
  Partials      165      165             

@steveluscher
Copy link
Contributor Author

Tested in React Native 0.70 with Hermes. Works fine.

Symbol is supported all the way back to 2015 in major browsers.

Shipping it.

@steveluscher steveluscher added the automerge Merge this Pull Request automatically once CI passes label Dec 9, 2022
@mergify mergify bot removed the automerge Merge this Pull Request automatically once CI passes label Dec 9, 2022
@mergify
Copy link
Contributor

mergify bot commented Dec 9, 2022

automerge label removed due to a CI failure

@steveluscher steveluscher merged commit ffcebbb into solana-labs:master Dec 9, 2022
@steveluscher steveluscher deleted the pretty-print-pubkey branch December 9, 2022 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
web3.js Related to the JavaScript client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prettify Node.Js Web3 Public Key Logging
1 participant