Skip to content

Refactor: deduplicate isCashAddr into shared btc.HasCashAddrPrefix#2

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/refactor-duplicated-code
Draft

Refactor: deduplicate isCashAddr into shared btc.HasCashAddrPrefix#2
Copilot wants to merge 2 commits into
masterfrom
copilot/refactor-duplicated-code

Conversation

Copilot AI commented Mar 2, 2026

Copy link
Copy Markdown

The isCashAddr function was copy-pasted identically into both bchain/coins/bch and bchain/coins/ecash, differing only in the package-level prefix constants each referenced.

Changes

  • bchain/coins/btc/bitcoinlikeparser.go — Added shared utility HasCashAddrPrefix(addr string, prefixes ...string) bool; both bch and ecash already import this package
  • bchain/coins/bch/bcashparser.go — Removed isCashAddr, updated call site to btc.HasCashAddrPrefix(address, MainNetPrefix, TestNetPrefix, RegTestPrefix)
  • bchain/coins/ecash/ecashparser.go — Same as above
// Before (duplicated in both packages):
func isCashAddr(addr string) bool {
    n := len(addr)
    switch {
    case n > len(MainNetPrefix) && addr[0:len(MainNetPrefix)] == MainNetPrefix:
        return true
    // ...
    }
    return false
}

// After (single shared function in btc package):
func HasCashAddrPrefix(addr string, prefixes ...string) bool {
    n := len(addr)
    for _, prefix := range prefixes {
        if n > len(prefix) && addr[0:len(prefix)] == prefix {
            return true
        }
    }
    return false
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/bin/wget wget REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…ix utility

Co-authored-by: Trinaj037 <207996474+Trinaj037@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for better maintainability Refactor: deduplicate isCashAddr into shared btc.HasCashAddrPrefix Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants