Skip to content

feat(asset): add ARC-compatible /v1/policy endpoint#456

Open
freemans13 wants to merge 1 commit intobsv-blockchain:mainfrom
freemans13:stu/new-policy-and-fees-endpoint
Open

feat(asset): add ARC-compatible /v1/policy endpoint#456
freemans13 wants to merge 1 commit intobsv-blockchain:mainfrom
freemans13:stu/new-policy-and-fees-endpoint

Conversation

@freemans13
Copy link
Collaborator

@freemans13 freemans13 commented Jan 29, 2026

Summary

Adds an ARC-compatible GET /v1/policy endpoint that returns the node's policy settings in the format specified by the ARC API.

This enables clients using ARC-compatible APIs to query Teranode for its transaction acceptance policies.

Changes

  • New file: services/asset/httpimpl/get_policy.go - Handler returning policy settings
  • Modified: services/asset/httpimpl/http.go - Route registration for /v1/policy

Response Format

{
  "timestamp": "2026-01-29T18:30:00.123456789Z",
  "policy": {
    "maxscriptsizepolicy": 500000,
    "maxtxsigopscountspolicy": 0,
    "maxtxsizepolicy": 10485760,
    "miningFee": {
      "satoshis": 500,
      "bytes": 1000
    },
    "standardFormatSupported": true
  }
}

Field Mapping

ARC Field Teranode Source Notes
maxscriptsizepolicy Policy.MaxScriptSizePolicy Max script size in bytes
maxtxsigopscountspolicy Policy.MaxTxSigopsCountsPolicy Max signature operations per tx
maxtxsizepolicy Policy.MaxTxSizePolicy Max transaction size in bytes
miningFee.satoshis Policy.MinMiningTxFee * 1e8 Converted from BSV to satoshis
miningFee.bytes 1000 Per kilobyte (matching MinMiningTxFee unit)
standardFormatSupported true Teranode supports standard tx format

Test Plan

  • Build: make build-teranode
  • Test endpoint: curl http://localhost:8090/v1/policy
  • Verify JSON response matches ARC format
  • Run existing tests: make test

🤖 Generated with Claude Code

@freemans13 freemans13 self-assigned this Jan 29, 2026
@freemans13 freemans13 changed the title new endpoint for policy and fees feat(asset): add ARC-compatible /v1/policy endpoint Jan 29, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2026

🤖 Claude Code Review

Status: Complete


Issues Found

1. Missing Unit Tests

File: services/asset/httpimpl/get_policy.go

The new handler lacks unit tests. All similar handlers in this codebase have corresponding test files (e.g., GetChainParams.go has tests, GetBlockStats_test.go, etc.).

Required test coverage:

  • Successful policy response with valid settings
  • Error handling when h.settings.Policy is nil
  • Fee conversion calculation correctness (BSV to satoshis)
  • JSON response format validation
  • Edge cases like zero or negative fees

2. Potential Float-to-Uint Conversion Issue

File: services/asset/httpimpl/get_policy.go:40

satoshisPerKB := uint64(policy.MinMiningTxFee * 100_000_000)

Problem: Direct conversion from float64 to uint64 without bounds checking. While unlikely with typical values (default 0.000005), extreme values could cause:

  • Integer overflow if fee > 184,467 BSV/kB
  • Loss of precision due to float64 limits
  • Undefined behavior with negative values

Suggested fix: Add validation before conversion:

feeFloat := policy.MinMiningTxFee * 100_000_000
if feeFloat < 0 || feeFloat > float64(math.MaxUint64) {
    return echo.NewHTTPError(http.StatusInternalServerError, "invalid fee configuration")
}
satoshisPerKB := uint64(feeFloat)

Risk: Low (defaults are safe), but defensive coding is best practice.


Positive Aspects

  • Clean code structure matching existing patterns (GetChainParams.go)
  • Proper nil checking for policy settings
  • Well-documented with ARC API reference
  • Logical route registration in http.go
  • Clear type definitions with JSON tags

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
10.5% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant