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

refactoring jellyfish-address #302

Closed
wants to merge 9 commits into from
Closed

Conversation

ivan-zynesis
Copy link
Contributor

What kind of PR is this?:

/kind feature

What this PR does / why we need it:

better code coverage
less logical branches

Which issue(s) does this PR fixes?:

Fixes #

Additional comments?:

@ivan-zynesis ivan-zynesis requested a review from fuxingloh as a code owner May 27, 2021 08:08
@ivan-zynesis ivan-zynesis marked this pull request as draft May 27, 2021 08:08
@defichain-bot defichain-bot added the kind/feature New feature request label May 27, 2021
@codeclimate
Copy link

codeclimate bot commented May 27, 2021

Code Climate has analyzed commit c624624 and detected 6 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 6

View more on Code Climate.

@netlify
Copy link

netlify bot commented May 27, 2021

✔️ Deploy Preview for jellyfish-defi ready!

🔨 Explore the source changes: 779d119

🔍 Inspect the deploy log: https://app.netlify.com/sites/jellyfish-defi/deploys/60af5395a945c100086dfc97

😎 Browse the preview: https://deploy-preview-302--jellyfish-defi.netlify.app

@github-actions
Copy link

github-actions bot commented May 27, 2021

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
packages/jellyfish/dist/jellyfish.umd.js 19.6 KB (0%) 393 ms (0%) 149 ms (-0.27% 🔽) 541 ms

@codecov
Copy link

codecov bot commented May 27, 2021

Codecov Report

Merging #302 (c624624) into main (9dfd345) will increase coverage by 0.39%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #302      +/-   ##
==========================================
+ Coverage   96.92%   97.31%   +0.39%     
==========================================
  Files          89       89              
  Lines        2404     2425      +21     
  Branches      308      324      +16     
==========================================
+ Hits         2330     2360      +30     
+ Misses         74       65       -9     
Impacted Files Coverage Δ
packages/jellyfish-address/src/address.ts 100.00% <100.00%> (+16.00%) ⬆️
packages/jellyfish-address/src/index.ts 100.00% <100.00%> (+2.22%) ⬆️
packages/jellyfish-address/src/p2pkh.ts 100.00% <100.00%> (ø)
packages/jellyfish-address/src/p2sh.ts 100.00% <100.00%> (+9.09%) ⬆️
packages/jellyfish-address/src/p2wpkh.ts 100.00% <100.00%> (ø)
packages/jellyfish-address/src/p2wsh.ts 100.00% <100.00%> (ø)
packages/jellyfish-wallet/src/wallet_account.ts 100.00% <100.00%> (ø)
packages/jellyfish-api-core/src/category/wallet.ts 100.00% <0.00%> (ø)
...ackages/jellyfish-api-core/src/category/account.ts 100.00% <0.00%> (ø)
...ackages/jellyfish-transaction-builder/src/index.ts 100.00% <0.00%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9dfd345...c624624. Read the comment docs.

packages/jellyfish-address/src/p2sh.ts Show resolved Hide resolved
packages/jellyfish-address/src/p2pkh.ts Show resolved Hide resolved
packages/jellyfish-address/src/p2wpkh.ts Outdated Show resolved Hide resolved
packages/jellyfish-address/src/p2wpkh.ts Show resolved Hide resolved
let valid: boolean
let prefix: string
let data: string = ''
try {
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

multiple "similar blocks" found

p2wsh similar to p2wpkh (bech32), however, refactoring them to parent class with require abstract methods like getDataLength() / getExpectedPrefixes()

@ivan-zynesis ivan-zynesis marked this pull request as ready for review May 28, 2021 04:19
@ivan-zynesis ivan-zynesis linked an issue May 28, 2021 that may be closed by this pull request
@ivan-zynesis ivan-zynesis requested a review from canonbrother May 28, 2021 08:25
Comment on lines 13 to 17
/**
* @param net to be validated against the decoded one from the raw address
* @param address raw human readable address (utf-8)
* @returns DefiAddress or a child class
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

gonna update the jsdoc

*/
static to (net: Network | NetworkName, h160: string, witnessVersion = 0x00): P2WPKH {
static to (net: Network | NetworkName, h160: string | Buffer, witnessVersion = 0x00): P2WPKH {
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

*/
static to (net: Network | NetworkName, hex: string, witnessVersion = 0x00): P2WSH {
static to (net: Network | NetworkName, data: string | Buffer, witnessVersion = 0x00): P2WSH {
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

* @throws when h160 input string is not 64 characters long (32 bytes)
* @returns {P2SH}
*/
static to (net: NetworkName | Network, h160: string | Buffer): P2SH {
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

* @throws when h160 input string is not 40 characters long (20 bytes)
* @returns {P2WSH}
*/
static to (net: NetworkName | Network, h160: string | Buffer): P2PKH {
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

Comment on lines +51 to +58
try {
const decoded = Bs58.toHash160(utf8String)
buffer = decoded.buffer
network = [MainNet, TestNet, RegTest].find(net => net.scriptHashPrefix === decoded.prefix)
valid = network !== undefined
} catch {
// non b58 string, invalid address
}
Copy link
Contributor

Choose a reason for hiding this comment

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

try.. catch without handling??

Copy link
Contributor Author

@ivan-zynesis ivan-zynesis Jun 1, 2021

Choose a reason for hiding this comment

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

Intended.

const addressStr = takeUserInput()
const address = DeFiAddress.from(addressStr)

It try instantiate multiple types of address and return if any valid. Return one with valid flag false even none is possible. (eg typo or extra space character pasted)

@fuxingloh
Copy link
Contributor

this is still too complicated in my opinion, let keep it open for now

@fuxingloh fuxingloh marked this pull request as draft June 10, 2021 03:44
@fuxingloh
Copy link
Contributor

This PR will be superseded by the introduction of #670, I will refactor jellyfish-address when #670 is done to simplify address logic.

@fuxingloh fuxingloh closed this Sep 21, 2021
canonbrother pushed a commit that referenced this pull request Jun 1, 2022
* Bump @defichain/jellyfish dependencies

* fixed deps resolution

Co-authored-by: Fuxing Loh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor jellyfish-address implementation to be lighter
4 participants