diff --git a/services/asset/httpimpl/get_policy.go b/services/asset/httpimpl/get_policy.go new file mode 100644 index 000000000..bd4e53aef --- /dev/null +++ b/services/asset/httpimpl/get_policy.go @@ -0,0 +1,55 @@ +package httpimpl + +import ( + "net/http" + "time" + + "github.com/labstack/echo/v4" +) + +// FeeAmount represents the mining fee as satoshis per bytes +type FeeAmount struct { + Satoshis uint64 `json:"satoshis"` + Bytes uint64 `json:"bytes"` +} + +// Policy contains the node's policy settings in ARC format +type Policy struct { + MaxScriptSizePolicy uint64 `json:"maxscriptsizepolicy"` + MaxTxSigopsCountsPolicy uint64 `json:"maxtxsigopscountspolicy"` + MaxTxSizePolicy uint64 `json:"maxtxsizepolicy"` + MiningFee FeeAmount `json:"miningFee"` + StandardFormatSupported bool `json:"standardFormatSupported"` +} + +// PolicyResponse is the response format for GET /v1/policy +type PolicyResponse struct { + Timestamp time.Time `json:"timestamp"` + Policy Policy `json:"policy"` +} + +func (h *HTTP) GetPolicy(c echo.Context) error { + policy := h.settings.Policy + if policy == nil { + return echo.NewHTTPError(http.StatusInternalServerError, "policy settings not configured") + } + + // Convert MinMiningTxFee (BSV/kB) to satoshis/bytes ratio + // MinMiningTxFee is in BSV per kilobyte + // 1 BSV = 100,000,000 satoshis, 1 kB = 1000 bytes + satoshisPerKB := uint64(policy.MinMiningTxFee * 100_000_000) + + return c.JSON(http.StatusOK, &PolicyResponse{ + Timestamp: time.Now().UTC(), + Policy: Policy{ + MaxScriptSizePolicy: uint64(policy.MaxScriptSizePolicy), + MaxTxSigopsCountsPolicy: uint64(policy.MaxTxSigopsCountsPolicy), + MaxTxSizePolicy: uint64(policy.MaxTxSizePolicy), + MiningFee: FeeAmount{ + Satoshis: satoshisPerKB, + Bytes: 1000, + }, + StandardFormatSupported: true, + }, + }) +} diff --git a/services/asset/httpimpl/http.go b/services/asset/httpimpl/http.go index 3a4977f8c..3ad58a12f 100644 --- a/services/asset/httpimpl/http.go +++ b/services/asset/httpimpl/http.go @@ -248,6 +248,9 @@ func New(logger ulogger.Logger, tSettings *settings.Settings, repo *repository.R apiGroup.GET("/blockgraphdata/:period", h.GetBlockGraphData) apiGroup.GET("/chainparams", h.GetChainParams) + // ARC-compatible policy endpoint (https://bitcoin-sv.github.io/arc/api.html) + e.GET("/v1/policy", h.GetPolicy) + apiGroup.GET("/lastblocks", h.GetLastNBlocks) apiGroup.GET("/utxo/:hash", h.GetUTXO(BINARY_STREAM))