# Class BSV::Wallet::CLI::Commands::Base <a id="class-BSV-Wallet-CLI-Commands-Base"></a>

**Inherits:** `Object`

Abstract base for <code>bin/wallet</code> subcommand classes. One instance per
dispatched invocation; +#call(ctx, args)+ is the entry point.

Contract (subclasses MUST):
    - implement +#name+        — the subcommand token (e.g. "balance")
    - implement +#call(args)+  — returns +Integer+ exit code
      (the boot +ctx+ is passed via +#initialize+; +#call+ only
      receives the remaining argv slice for this command)
    - implement +#build_parser+ — defines the per-command +OptionParser+

Helpers (subclasses MAY use):
    - +#emit_json(payload)+        — JSON to stdout, redacted, with
                                     NDJSON support for streamed
                                     output via +emit_ndjson_row+
    - +#emit_human(line)+          — human-readable line to stderr
    - +#read_binary_input(file:)+  — binmode-safe BEEF ingest
    - +#parse_pubkey_hex(hex)+     — validates hex pubkey, raises
                                     +UsageError+ on malformed input

Error contract:
    - +raise UsageError+ for bad flags / missing required args
    - +raise EngineError+ for engine-side failures (or let
      +BSV::Wallet::Error+ bubble; dispatcher wraps it)
    - never +abort+ or +exit+ inside +#call+ — bypasses the
      dispatcher's rescue and is untestable

## Constants
### `BASKET_NAME_CHARSET` <a id="constant-BASKET_NAME_CHARSET"></a> <a id="BASKET_NAME_CHARSET-constant"></a>
Not documented.

### `BASKET_NAME_MAX` <a id="constant-BASKET_NAME_MAX"></a> <a id="BASKET_NAME_MAX-constant"></a>
Not documented.

### `BASKET_NAME_MIN` <a id="constant-BASKET_NAME_MIN"></a> <a id="BASKET_NAME_MIN-constant"></a>
Validate a basket name against the schema's DB CHECK rules (mirrors all seven
<code>baskets_name_*</code> constraints in
<code>001_create_schema.rb:266-272</code>). Without this gate, invalid names
reach the engine and bubble as <code>Sequel::CheckConstraintViolation</code> —
outside the dispatcher's never-raises-uncaught rescue chain.

Schema floor (enforced here): length 5-300, lowercase ASCII
letters/digits/spaces, no consecutive spaces, no leading or trailing space,
not the literal +'default'+, no trailing +' basket'+ suffix. These are the DB
CHECK constraints; every path that writes to `baskets` obeys them.

NOT enforced here (BRC-100 conformance layer only
—+BSV::Wallet::BRC100#validate_basket_name!+): +'admin'+ prefix and +'p '+
prefix. Native <code>bin/wallet</code> legitimately uses these for
wallet-internal baskets (+'p wbikd'+ for WBIKD address slots per the WBIKD
draft; +'admin *'+ for permission tokens per ADR-029); the sibling
<code>bin/brc100</code> surface (HLR #431) is where those tighter
spec-mandated rules belong.

### `TEXT_REDACTION` <a id="constant-TEXT_REDACTION"></a> <a id="TEXT_REDACTION-constant"></a>
Same pattern, same source-of-truth as
<code>Dispatcher::MESSAGE_REDACTION</code> — built from
<code>Secrets::SENSITIVE_FIELD_NAMES_PATTERN</code> so all three redaction
surfaces (JSON, exception messages, human output) move together. Compound
identifiers like `sender_identity_key` pass through unredacted (interchange
identifier, not secret material).

## Public Instance Methods
### `build_parser()` <a id="method-i-build_parser"></a> <a id="build_parser-instance_method"></a>
Subclasses define their `OptionParser` here. Default is a banner-only parser
(no flags).
- **@return** [OptionParser]

### `call(_args)` <a id="method-i-call"></a> <a id="call-instance_method"></a>
Process `args` and emit results. Returns the process exit code.
- **@param** `args` [Array<String>] remaining argv after the
subcommand token (global flags and the subcommand have
already been consumed by +Dispatcher+).
- **@raise** [NotImplementedError]
- **@return** [Integer] exit code

### `help()` <a id="method-i-help"></a> <a id="help-instance_method"></a>
Print +@parser.help+. Used by the dispatcher when <code>--help</code> /
<code>-h</code> appears in the subcommand's argv slice.

### `initialize(ctx:, global_options:)` <a id="method-i-initialize"></a> <a id="initialize-instance_method"></a>
`ctx`: result of <code>CLI.boot</code> ({ engine:, utxo_pool:, ... }).
Subclasses access <code>ctx[:engine]</code>, <code>ctx[:utxo_pool]</code>,
etc. `global_options`: the `GlobalOptions` value object (read for
<code>--json</code> etc.).
- **@return** [Base] a new instance of Base

### `name()` <a id="method-i-name"></a> <a id="name-instance_method"></a>
Subcommand token. Subclasses override.
- **@return** [String]

### `parser()` <a id="method-i-parser"></a> <a id="parser-instance_method"></a>
Memoised OptionParser for the subcommand. Banner format is +Usage: bin/wallet
<name> [options] <args>+. Subclasses override <code>#build_parser</code> to
add flags.
- **@return** [OptionParser]
