devchain

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package devchain is an application's local stand-in chain command: bcommon's testchain served over HTTP, a node's JSON-RPC at /rpc (generatetoaddress, sendrawtransaction, getinfo), its asset API under /api/v1/ and a header source at /v1/root/<height> and /v1/tip. It checks what it is sent the way a node would (inputs exist and are unspent, coinbase is mature, scripts verify, nothing non-final is mined) but it has no proof of work and no peers: its proofs mean nothing outside it, and nothing it mines is money. Coinbase: only on a regtest chain you run, for development and tests. It is for a laptop, never for a network.

With -journal every accepted RPC call is appended to a file and replayed at start, so a restarted chain is the same chain: the same blocks, and the hosts' and the homes' state still matches it.

An application's cmd/devchain is one call:

func main() {
	os.Exit(devchain.Main(devchain.Options{App: "app", Version: version}, os.Args[1:], os.Stdout, os.Stderr))
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Journaled

func Journaled(chain http.Handler, path string, logf func(string, ...any)) (http.Handler, error)

Journaled is chain served with every accepted RPC call appended to the file at path, after replaying the file's calls into chain; an empty path serves chain as it is. logf takes a line about the replay.

func Main

func Main(o Options, args []string, stdout, stderr io.Writer) int

Main runs the command on args (without the program name) and returns its exit status: 0, 1 when the chain cannot start or stops with an error, 2 for a usage error. It serves until SIGINT or SIGTERM.

func WriteCerts

func WriteCerts(dir, app string, names []string, out io.Writer) error

WriteCerts writes a throwaway CA and a server certificate for each name (a DNS name, or an IP address) into dir: ca.pem, <name>.pem and <name>-key.pem, keys mode 0600, and a line per certificate to out. The CA's key is discarded, so nothing more can be signed by it. app names the CA. For a laptop's quickstart, never a network.

Types

type Options

type Options struct {
	// App is the application the chain is for, as its help names it.
	App string
	// Version is the command's stamped version.
	Version string
	// Certs adds `devchain certs -dir DIR -names NAME,...`, which writes a
	// throwaway CA and server certificates (WriteCerts), for an application
	// whose servers must be https on a laptop.
	Certs bool
}

Options are what differ between applications.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL