Deterministic Bitcoin Tool Dispatch in Go
Research question
A deterministic dispatcher maps an allowed tool name to a fixed engine route.
The model cannot choose an arbitrary URL, method or header. This example accepts already parsed typed arguments and repeats the network and address-type checks. A real transport layer must separately reject unknown and duplicate JSON fields before constructing Args, inject the key locally, disable redirects and set timeouts. A successful route decision does not establish wallet authorization or engine availability. Compare this with the HTTP client in Stage 02.
Reference implementation
1package main
2
3import (
4 "encoding/json"
5 "errors"
6 "fmt"
7)
8
9type Args struct {
10 Net string `json:"net"`
11 Type string `json:"type"`
12}
13
14// Accept typed values after strict parsing and schema validation.
15func route(name string, a Args) (string, []byte, error) {
16 if name != "wab_wallet_balance" {
17 return "", nil, errors.New("unknown tool")
18 }
19 if a.Net != "test" || (a.Type != "segwit" && a.Type != "taproot") {
20 return "", nil, errors.New("invalid arguments")
21 }
22 body, err := json.Marshal(a)
23 return "/api/v5/btc/wallet/balance", body, err
24}
25
26func main() {
27 path, body, err := route("wab_wallet_balance", Args{"test", "segwit"})
28 if err != nil { panic(err) }
29 fmt.Printf("POST %s %s\n", path, body)
30}Applying the example
Run go run dispatch.go to print the planned request without sending it. Connect the returned route and body to a separately reviewed HTTP client only if needed.
Scope and limitations
This is an independent educational design, not a mandatory SDK or a live-tested integration. The engine remains authoritative. No SEND or recovery tools are exposed. Do not put BTC KEY in tool arguments or model context. Verify the deployed API contract before connecting a wallet.
