From 663aac5a1033625599b96c5f36ea96f56fa1d122 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 04:20:40 +0100 Subject: [PATCH] feat: add 3 HSD sidechain actions for go-lns integration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit blockchain.hsd.info — sidechain chain/height/tree_root blockchain.hsd.resolve — name → DNS records from sidechain blockchain.hsd.height — sidechain block height 33 total Core actions. Ready for go-lns to call these via c.Run("blockchain.hsd.resolve", opts). Co-Authored-By: Charon --- actions.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/actions.go b/actions.go index 0cd1d82..b394480 100644 --- a/actions.go +++ b/actions.go @@ -8,6 +8,7 @@ import ( "dappco.re/go/core" + hsdpkg "dappco.re/go/core/blockchain/hsd" "dappco.re/go/core/blockchain/chain" "dappco.re/go/core/blockchain/crypto" "dappco.re/go/core/blockchain/types" @@ -398,3 +399,60 @@ func RegisterAllActions(c *core.Core, ch *chain.Chain) { RegisterAssetActions(c) RegisterForgeActions(c) } + +// RegisterHSDActions registers sidechain query actions. +// +// blockchain.RegisterHSDActions(c, hsdClient) +func RegisterHSDActions(c *core.Core, hsdURL, hsdKey string) { + c.Action("blockchain.hsd.info", makeHSDInfo(hsdURL, hsdKey)) + c.Action("blockchain.hsd.resolve", makeHSDResolve(hsdURL, hsdKey)) + c.Action("blockchain.hsd.height", makeHSDHeight(hsdURL, hsdKey)) +} + +func makeHSDInfo(url, key string) core.ActionHandler { + return func(ctx context.Context, opts core.Options) core.Result { + client := hsdpkg.NewClient(url, key) + info, err := client.GetBlockchainInfo() + if err != nil { + return core.Result{OK: false} + } + return core.Result{Value: map[string]interface{}{ + "chain": info.Chain, "height": info.Blocks, + "tree_root": info.TreeRoot, + }, OK: true} + } +} + +func makeHSDResolve(url, key string) core.ActionHandler { + return func(ctx context.Context, opts core.Options) core.Result { + name := opts.String("name") + if name == "" { + return core.Result{OK: false} + } + client := hsdpkg.NewClient(url, key) + resource, err := client.GetNameResource(name) + if err != nil { + return core.Result{OK: false} + } + var records []map[string]interface{} + for _, r := range resource.Records { + records = append(records, map[string]interface{}{ + "type": r.Type, "address": r.Address, "txt": r.TXT, "ns": r.NS, + }) + } + return core.Result{Value: map[string]interface{}{ + "name": name, "records": records, + }, OK: true} + } +} + +func makeHSDHeight(url, key string) core.ActionHandler { + return func(ctx context.Context, opts core.Options) core.Result { + client := hsdpkg.NewClient(url, key) + height, err := client.GetHeight() + if err != nil { + return core.Result{OK: false} + } + return core.Result{Value: height, OK: true} + } +}