bch-development

Bitcoin Cash (BCH) API implementation rules. Critical pattern for embedding Bitcoin struct and overriding BCH-specific methods. Use when working on BCH-related code in internal/infrastructure/api/btc/bch/.

125 stars

Best use case

bch-development is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Bitcoin Cash (BCH) API implementation rules. Critical pattern for embedding Bitcoin struct and overriding BCH-specific methods. Use when working on BCH-related code in internal/infrastructure/api/btc/bch/.

Teams using bch-development should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/bch-development/SKILL.md --create-dirs "https://raw.githubusercontent.com/hiromaily/go-crypto-wallet/main/.claude/skills/bch-development/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/bch-development/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How bch-development Compares

Feature / Agentbch-developmentStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Bitcoin Cash (BCH) API implementation rules. Critical pattern for embedding Bitcoin struct and overriding BCH-specific methods. Use when working on BCH-related code in internal/infrastructure/api/btc/bch/.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# BCH (Bitcoin Cash) Development Rules

## 🚨 CRITICAL: Override Pattern for BCH-Specific Logic

**This is a non-negotiable architectural rule.** BCH implementation uses struct embedding with method override pattern.

### Architecture Overview

```go
// internal/infrastructure/api/btc/bch/bitcoin_cash.go
type BitcoinCash struct {
    apibtcimpl.Bitcoin  // Embeds BTC implementation
}
```

**Key Principle:** `BitcoinCash` embeds `Bitcoin`, inheriting all BTC methods by default.

## Rules

### ✅ DO: Override on BCH Side

When BCH requires different logic from BTC:

1. **Create a new file** in `internal/infrastructure/api/btc/bch/`
2. **Implement the method** with the same name on `BitcoinCash`
3. **This "overrides"** the embedded `Bitcoin` method

### ❌ DON'T: Modify BTC Side for BCH

- **NEVER** modify `internal/infrastructure/api/btc/btc/` for BCH-specific requirements
- **NEVER** add BCH conditionals in BTC code
- **NEVER** add BCH-specific types or logic to the BTC package

## Why This Pattern?

| Reason                     | Explanation                                    |
| -------------------------- | ---------------------------------------------- |
| **Separation of Concerns** | BTC code remains pure and focused              |
| **Maintainability**        | BCH changes don't affect BTC                   |
| **Clarity**                | BCH differences are explicit in BCH directory  |
| **Safety**                 | BTC modifications can't accidentally break BCH |

## Implementation Examples

### Example 1: GetAddressInfo Override

BCH has a different response structure for `getaddressinfo` RPC:

```go
// internal/infrastructure/api/btc/bch/address.go
// BCH-specific response type
type GetAddressInfoResult struct {
    Address      string `json:"address"`
    ScriptPubKey string `json:"scriptPubKey"`
    Label        string `json:"label,omitempty"`  // BCH uses Label (singular)
    Labels       []struct {                       // BCH has different Labels structure
        Name    string `json:"name"`
        Purpose string `json:"purpose"`
    } `json:"labels"`
    // ... other BCH-specific fields
}

// Override GetAddressInfo for BCH
func (b *BitcoinCash) GetAddressInfo(addr string) (*dtobtc.AddressInfo, error) {
    // BCH-specific implementation
    // ...
}
```

### Example 2: GetAccount Override

BCH requires different logic for getting account info:

```go
// internal/infrastructure/api/btc/bch/account.go
func (b *BitcoinCash) GetAccount(addr string) (string, error) {
    // BCH calls GetAddressInfo (which is also overridden)
    res, err := b.GetAddressInfo(addr)
    if err != nil {
        return "", fmt.Errorf("fail to call btc.GetAddressInfo() in bch: %w", err)
    }
    // BCH-specific label extraction
    if len(res.Labels) == 0 {
        return "", nil
    }
    return res.Labels[0], nil
}
```

### Example 3: Chain Parameters Override

BCH has different network magic numbers:

```go
// internal/infrastructure/api/btc/bch/bitcoin_cash.go
const (
    MainnetMagic wire.BitcoinNet = 0xe8f3e1e3  // BCH-specific
    TestnetMagic wire.BitcoinNet = 0xf4f3e5f4  // BCH-specific
    Regtestmagic wire.BitcoinNet = 0xfabfb5da  // BCH-specific
)

func (b *BitcoinCash) initChainParams() {
    // Override chain parameters for BCH
}
```

## BCH vs BTC: Feature Differences

| Feature        | BTC                     | BCH                 |
| -------------- | ----------------------- | ------------------- |
| SegWit         | ✅ Supported            | ❌ Not supported    |
| Taproot        | ✅ Supported            | ❌ Not supported    |
| Address Format | Legacy, SegWit, Taproot | Legacy, CashAddr    |
| Network Magic  | BTC values              | BCH-specific values |

## Directory Structure

```
internal/infrastructure/api/btc/
├── btc/                      # BTC implementation (DO NOT modify for BCH)
│   ├── bitcoin.go            # Bitcoin struct and methods
│   ├── account.go
│   ├── address.go
│   └── ...
├── bch/                      # BCH overrides (ADD new files here)
│   ├── bitcoin_cash.go       # BitcoinCash struct (embeds Bitcoin)
│   ├── account.go            # Override: GetAccount
│   ├── address.go            # Override: GetAddressInfo
│   └── ...
└── connection.go             # Shared connection logic
```

## Checklist for BCH Changes

When implementing BCH-specific logic:

- [ ] File created in `internal/infrastructure/api/btc/bch/` (NOT in `btc/`)
- [ ] Method has same signature as the BTC method being overridden
- [ ] No changes made to `internal/infrastructure/api/btc/btc/`
- [ ] BCH-specific types defined in BCH package (if needed)
- [ ] Error messages include "bch" for traceability

## Common Mistakes

### ❌ WRONG: Adding BCH Logic to BTC

```go
// internal/infrastructure/api/btc/btc/account.go
func (b *Bitcoin) GetAccount(addr string) (string, error) {
    if b.coinTypeCode == domainCoin.BCH {  // DON'T DO THIS!
        // BCH-specific logic
    }
    // BTC logic
}
```

### ✅ CORRECT: Override in BCH Package

```go
// internal/infrastructure/api/btc/bch/account.go
func (b *BitcoinCash) GetAccount(addr string) (string, error) {
    // BCH-specific logic here
}
```

## Technical Note: How Go Embedding Works

When `BitcoinCash` embeds `Bitcoin`:

1. All `Bitcoin` methods are "promoted" to `BitcoinCash`
2. If `BitcoinCash` defines a method with the same name, it takes precedence
3. The embedded `Bitcoin` methods can still be called via `b.Bitcoin.MethodName()`

```go
// Call overridden method (uses BitcoinCash.GetAddressInfo)
info, _ := bch.GetAddressInfo(addr)

// Call embedded method directly (uses Bitcoin.GetAddressInfo)
info, _ := bch.Bitcoin.GetAddressInfo(addr)
```

## Related Files

| File                                                  | Purpose                          |
| ----------------------------------------------------- | -------------------------------- |
| `internal/infrastructure/api/btc/bch/bitcoin_cash.go` | BitcoinCash struct definition    |
| `internal/infrastructure/api/btc/btc/bitcoin.go`      | Bitcoin struct (embedded by BCH) |
| `internal/application/ports/btc/interface.go`         | Bitcoiner interface              |

## Related Documentation

- [BCH Technical Docs](../../../docs/chains/bch/)
- [BTC Technical Docs](../../../docs/chains/btc/)

Related Skills

typescript-development

125
from hiromaily/go-crypto-wallet

TypeScript/JavaScript development workflow for apps/ directory. Use when modifying TypeScript code in xrpl-grpc-server or JavaScript in eth-contracts.

solidity-development

125
from hiromaily/go-crypto-wallet

Solidity smart contract development workflow. Use when modifying smart contracts in apps/eth-contracts/contracts/.

go-development

125
from hiromaily/go-crypto-wallet

Go development workflow including verification commands and self-review checklist. Use when modifying Go code in internal/, pkg/, or cmd/ directories.

wallet-cli

125
from hiromaily/go-crypto-wallet

How to run watch, keygen, and sign wallet CLI commands. Use when executing wallet commands or testing wallet functionality.

shell-scripts

125
from hiromaily/go-crypto-wallet

Shell script development workflow. Use when modifying files in scripts/ directory or any *.sh files.

openspec-propose

125
from hiromaily/go-crypto-wallet

Propose a new change with all artifacts generated in one step. Use when the user wants to quickly describe what they want to build and get a complete proposal with design, specs, and tasks ready for implementation.

openspec-explore

125
from hiromaily/go-crypto-wallet

Enter explore mode - a thinking partner for exploring ideas, investigating problems, and clarifying requirements. Use when the user wants to think through something before or during a change.

openspec-archive-change

125
from hiromaily/go-crypto-wallet

Archive a completed change in the experimental workflow. Use when the user wants to finalize and archive a change after implementation is complete.

openspec-apply-change

125
from hiromaily/go-crypto-wallet

Implement tasks from an OpenSpec change. Use when the user wants to start implementing, continue implementation, or work through tasks.

mockery

125
from hiromaily/go-crypto-wallet

Mock generation workflow for go-crypto-wallet. Activate whenever a developer asks to generate a mock for a new interface, add test coverage that requires a mock, or replace a manually-written test stub for a ports interface. Claude MUST use `make mockery` — never write mock struct code by hand.

makefile-update

125
from hiromaily/go-crypto-wallet

Makefile development workflow. Use when modifying Makefile or files in make/ directory.

label-context-mapping

125
from hiromaily/go-crypto-wallet

Maps GitHub labels to Skills and Context documents. Use when creating issues (github-issue-creation) or working on issues (fix-issue command).