Skip to content

rpc: add registername with auto-commitment support#1

Open
mstrofnone wants to merge 1 commit intomasterfrom
registername-auto-commit
Open

rpc: add registername with auto-commitment support#1
mstrofnone wants to merge 1 commit intomasterfrom
registername-auto-commit

Conversation

@mstrofnone
Copy link
Copy Markdown
Owner

Add a new registername RPC method that wraps name_firstupdate with improved UX: if no matching name_new commitment is found in the wallet, one is created automatically before proceeding.

Motivation

As discussed in namecoin#576 and namecoin#579, the separate name_autoregister RPC creates UX friction by being its own method. This PR rolls that functionality into registername (the Bitcoin Core convention alias for name_firstupdate), giving average users a single-call registration flow while preserving the two-step manual procedure for power users.

Behaviour

When called as registername:

  1. Scan the wallet for a matching name_new commitment input.
  2. If not found, call name_new automatically to create one.
  3. Create the name_firstupdate transaction.
  4. If the transaction is mempool-eligible, broadcast it; otherwise commit it to the wallet for automatic rebroadcast after the name_new matures (via the wallet's blockConnected rebroadcast logic).

When called as name_firstupdate (the original method), the old behaviour is preserved — it simply fails if no commitment is found.

Implementation

  • name_firstupdate_impl() is a shared static helper parameterised by method name.
  • name_firstupdate() and registername() both delegate to it.
  • The auto-commitment path builds a fresh JSONRPCRequest for name_new reusing the caller's context.
  • A wallet-transaction fallback is added to getNamePrevout for when the just-created name_new output is not yet in CoinsTip (unconfirmed).
  • registername is registered as a separate RPC command (not an alias sharing unique_id) so it gets its own help text describing the auto-commitment behaviour.

Usage

# Simple one-call registration (auto-creates name_new if needed):
namecoin-cli registername "myname" "" "" "my-value"

# Power users can still do the two-step flow:
namecoin-cli name_new "myname"
# ... wait for confirmations ...
namecoin-cli name_firstupdate "myname" "rand" "txid" "my-value"

Ref: namecoin#576, namecoin#579

@mstrofnone mstrofnone force-pushed the registername-auto-commit branch 2 times, most recently from cf841f4 to ab6995f Compare March 24, 2026 09:30
Add a new 'registername' RPC method that provides a simple single-call
interface for name registration: registername "myname" "my-value"

Unlike name_firstupdate (which requires a prior name_new and takes
rand/tx/value as separate positional args), registername takes just
a name and value, handling the commitment automatically:

 1. Scan the wallet for a matching name_new commitment.
 2. If none is found, create one automatically via name_new.
 3. Build the name_firstupdate transaction.
 4. If mempool-eligible, broadcast; otherwise commit to wallet for
    automatic rebroadcast after the name_new matures.

Refactors the wallet scanning logic from name_firstupdate into a
shared findNameNewCommitment() helper that is reused by both
name_firstupdate and registername. This eliminates the duplicated
wallet scan code and makes the commitment-finding logic testable
independently.

name_firstupdate is completely unchanged in behavior -- power users
can still do the two-step manual procedure.

Returns {txid, rand} as a JSON object.

Includes functional tests covering:
- Basic registration with auto name_new
- Reuse of existing name_new commitment
- Duplicate name rejection
- Default (empty) value
- Parameter validation (name too long, value too long)
- Return format verification

Ref: namecoin#576, namecoin#579, namecoin#581
@mstrofnone mstrofnone force-pushed the registername-auto-commit branch from ab6995f to 907636a Compare March 24, 2026 09:33
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.

1 participant