Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions services/asset/httpimpl/get_policy.go
Original file line number Diff line number Diff line change
@@ -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,
},
})
}
3 changes: 3 additions & 0 deletions services/asset/httpimpl/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading