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

feat(bitcoinAddress): Multiple bitcoin address types and testnet #2922

Merged
merged 45 commits into from
Jun 5, 2024

Conversation

madoke
Copy link
Contributor

@madoke madoke commented May 25, 2024

The faker.finance.bitcoinAddress() only generates legacy and segwit addresses at random choice, and only for mainnet. In some cases the user might need to generate different types of addresses and use different networks. All of them are slightly different in terms of prefix, characters allowed and length.

The different types of bitcoin addresses and their prefixes are explained in the following articles:

This PR introduces an options parameter that will allow the user to specify different types of address and also different networks. Examples:

const defaultBehavior = faker.finance.bitcoinAddress();
// 1TeZEFLmGPLEQrSRdAcnZLoWwYeiHwmRog  (legacy mainnet)

const bech32Address = faker.finance.bitcoinAddress({ type: 'bech32'})
// bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4 (bech32 mainnet)

const taprootTestnetAddress = faker.finance.bitcoinAddress({ type: 'taproot', network: 'testnet' })
// tb1phy9d80yes2vx72pa0vzyltvq3gr3vprp6j0jczgkxzcqk6h4vuyse0uspv (taproot testnet)

Note: The current faker.finance.bitcoinAddress function generates both legacy and segwit addresses, while in the current implementation with the type parameter, the default behavior is to generate legacy addresses only. Happy make some changes here to preserve the original behavior

@madoke madoke requested a review from a team as a code owner May 25, 2024 18:13
Copy link

netlify bot commented May 25, 2024

Deploy Preview for fakerjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 857a2c8
🔍 Latest deploy log https://app.netlify.com/sites/fakerjs/deploys/665f8d7e90d2620008469c00
😎 Deploy Preview https://deploy-preview-2922.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented May 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.96%. Comparing base (badaa6d) to head (857a2c8).

Additional details and impacted files
@@           Coverage Diff            @@
##             next    #2922    +/-   ##
========================================
  Coverage   99.96%   99.96%            
========================================
  Files        2986     2987     +1     
  Lines      215926   216037   +111     
  Branches      599      598     -1     
========================================
+ Hits       215841   215952   +111     
  Misses         85       85            
Files Coverage Δ
src/index.ts 100.00% <100.00%> (ø)
src/modules/finance/bitcoin.ts 100.00% <100.00%> (ø)
src/modules/finance/index.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent m: finance Something is referring to the finance module labels May 25, 2024
src/modules/finance/index.ts Outdated Show resolved Hide resolved
src/modules/finance/index.ts Outdated Show resolved Hide resolved
src/modules/finance/index.ts Outdated Show resolved Hide resolved
src/definitions/finance.ts Outdated Show resolved Hide resolved
src/modules/finance/index.ts Outdated Show resolved Hide resolved
src/modules/finance/index.ts Outdated Show resolved Hide resolved
src/modules/finance/index.ts Outdated Show resolved Hide resolved
src/modules/finance/index.ts Outdated Show resolved Hide resolved
src/modules/finance/index.ts Outdated Show resolved Hide resolved
@import-brain import-brain changed the title feat(bitcoinAddress): Mutltiple bitcoin address types and testnet feat(bitcoinAddress): Multiple bitcoin address types and testnet May 25, 2024
madoke and others added 8 commits May 25, 2024 22:17
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
Co-authored-by: ST-DDT <ST-DDT@gmx.de>
test/modules/finance.spec.ts Outdated Show resolved Hide resolved
test/modules/finance.spec.ts Outdated Show resolved Hide resolved
test/modules/finance.spec.ts Outdated Show resolved Hide resolved
test/modules/finance.spec.ts Outdated Show resolved Hide resolved
Copy link
Member

@xDivisionByZerox xDivisionByZerox left a comment

Choose a reason for hiding this comment

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

Great work so far! ❤️

src/modules/finance/bitcoin.ts Outdated Show resolved Hide resolved
src/modules/finance/index.ts Outdated Show resolved Hide resolved
src/modules/finance/index.ts Outdated Show resolved Hide resolved
src/modules/finance/index.ts Outdated Show resolved Hide resolved
src/modules/finance/index.ts Outdated Show resolved Hide resolved
test/modules/finance.spec.ts Outdated Show resolved Hide resolved
@xDivisionByZerox xDivisionByZerox requested review from a team May 27, 2024 15:28
@xDivisionByZerox xDivisionByZerox added this to the vAnytime milestone May 27, 2024
Co-authored-by: DivisionByZero <leyla.jaehnig@gmx.de>
src/modules/finance/index.ts Outdated Show resolved Hide resolved
test/modules/finance.spec.ts Outdated Show resolved Hide resolved
test/modules/finance.spec.ts Outdated Show resolved Hide resolved
test/modules/finance.spec.ts Outdated Show resolved Hide resolved
test/modules/finance.spec.ts Outdated Show resolved Hide resolved
@madoke madoke dismissed stale reviews from import-brain and ST-DDT via 3efd52a June 3, 2024 20:10
madoke and others added 7 commits June 3, 2024 21:10
Co-authored-by: Shinigami <chrissi92@hotmail.de>
Co-authored-by: Shinigami <chrissi92@hotmail.de>
Co-authored-by: Shinigami <chrissi92@hotmail.de>
Co-authored-by: Shinigami <chrissi92@hotmail.de>
Co-authored-by: Shinigami <chrissi92@hotmail.de>
@madoke
Copy link
Contributor Author

madoke commented Jun 3, 2024

Thanks for submitting suggestions folks, makes addressing comments a lot easier !

Copy link
Member

@xDivisionByZerox xDivisionByZerox left a comment

Choose a reason for hiding this comment

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

Last questions and suggestions from my side.

src/modules/finance/bitcoin.ts Outdated Show resolved Hide resolved
src/modules/finance/bitcoin.ts Outdated Show resolved Hide resolved
src/modules/finance/bitcoin.ts Outdated Show resolved Hide resolved
src/modules/finance/bitcoin.ts Outdated Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
madoke and others added 5 commits June 4, 2024 00:08
Co-authored-by: DivisionByZero <leyla.jaehnig@gmx.de>
Co-authored-by: DivisionByZero <leyla.jaehnig@gmx.de>
Co-authored-by: DivisionByZero <leyla.jaehnig@gmx.de>
Co-authored-by: DivisionByZero <leyla.jaehnig@gmx.de>
Co-authored-by: DivisionByZero <leyla.jaehnig@gmx.de>
@ST-DDT
Copy link
Member

ST-DDT commented Jun 4, 2024

I'm somewhat confused by the lint error. IMO the current code looks correct to me. Maybe the two blocks need to be swapped?
e.g. enum first, then the type

Like this one:

faker/src/index.ts

Lines 39 to 40 in e6a2a9f

export { Aircraft } from './modules/airline';
export type { AircraftType, AirlineModule } from './modules/airline';

src/index.ts Outdated Show resolved Hide resolved
@Shinigami92 Shinigami92 marked this pull request as draft June 4, 2024 15:34
@ST-DDT ST-DDT requested review from a team June 4, 2024 23:08
@Shinigami92 Shinigami92 marked this pull request as ready for review June 5, 2024 03:28
Copy link
Member

@xDivisionByZerox xDivisionByZerox left a comment

Choose a reason for hiding this comment

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

Thank you for your review. It has been a pleasure to work with you.

@ST-DDT ST-DDT merged commit 3ae9393 into faker-js:next Jun 5, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: feature Request for new feature m: finance Something is referring to the finance module p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants