Skip to content

Commit

Permalink
all: update with coinmarketcap specs
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Jun 21, 2023
1 parent eab5219 commit 99cb9d2
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
name: generate tags
id: meta
with:
images: ghcr.io/n8maninger/sia-coinbased
images: ghcr.io/siafoundation/cmc-supply-api
tags: |
type=ref,event=branch
type=sha,prefix=
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
with:
flavor: |
suffix=-testnet,onlatest=true
images: ghcr.io/n8maninger/sia-coinbased
images: ghcr.io/siafoundation/cmc-supply-api
tags: |
type=ref,event=branch
type=sha,prefix=
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ Implements a minimal Sia subscriber for processing data from Sia's consensus set

# Usage
```
statsd --dir ~/statsd
cmcd -dir ~/cmcd
```

## Building
```
go build -o bin/ ./cmd/subscriberd
go build -o bin/ ./cmd/cmcd
```

### Testnet
```
go build -o bin/ -tags testnet ./cmd/subscriberd
go build -o bin/ -tags testnet ./cmd/cmcd
```
28 changes: 24 additions & 4 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ package api

import (
"net/http"
"strings"

"github.com/n8maninger/sia-coinbased/stats"
"github.com/shopspring/decimal"
"go.sia.tech/cmc-supply-api/stats"
"go.sia.tech/jape"
"go.uber.org/zap"
)

const (
supplyTypeTotal = "total"
supplyTypeCirculating = "circulating"
)

type (

// A StatProvider provides statistics about the current state of the Sia network.
StatProvider interface {
Stats() stats.BlockStats
Expand All @@ -21,8 +29,20 @@ type (
}
)

func (a *api) handleGETStats(c jape.Context) {
c.Encode(a.sp.Stats())
func (a *api) handleGETSupply(c jape.Context) {
var supplyType string
if err := c.DecodeParam("type", &supplyType); err != nil {
return
}

stats := a.sp.Stats()

switch strings.ToLower(supplyType) {
case supplyTypeTotal:
c.Encode(decimal.NewFromBigInt(stats.TotalSupply.Big(), -24).InexactFloat64()) // 1 SC = 10^24 H
case supplyTypeCirculating:
c.Encode(decimal.NewFromBigInt(stats.CirculatingSupply.Big(), -24).InexactFloat64()) // 1 SC = 10^24 H
}
}

// NewServer returns an http.Handler that serves the API.
Expand All @@ -33,6 +53,6 @@ func NewServer(sp StatProvider, log *zap.Logger) http.Handler {
}

return jape.Mux(map[string]jape.Handler{
"GET /stats": a.handleGETStats,
"GET /stats/supply/:type": a.handleGETSupply,
})
}
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/coinbased/main.go → cmd/cmcd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"syscall"
"time"

"github.com/n8maninger/sia-coinbased/api"
"github.com/n8maninger/sia-coinbased/stats"
"go.sia.tech/cmc-supply-api/api"
"go.sia.tech/cmc-supply-api/stats"
"go.sia.tech/siad/modules/consensus"
"go.sia.tech/siad/modules/gateway"
"go.sia.tech/siad/modules/transactionpool"
Expand Down
8 changes: 4 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ WORKDIR /coinbase
COPY . .
# build
# RUN go generate ./...
RUN go build -o bin/ -tags='netgo timetzdata' -trimpath -a -ldflags '-s -w -linkmode external -extldflags "-static"' ./cmd/coinbased
RUN go build -o bin/ -tags='netgo timetzdata' -trimpath -a -ldflags '-s -w -linkmode external -extldflags "-static"' ./cmd/cmcd

FROM docker.io/library/alpine:3
LABEL maintainer="The Sia Foundation <info@sia.tech>" \
org.opencontainers.image.description.vendor="The Sia Foundation" \
org.opencontainers.image.description="A coinbase container - provides coinbase statistics for the Sia network" \
org.opencontainers.image.source="https://github.com/n8maninger/sia-coinbased" \
org.opencontainers.image.description="A Sia supply API - provides the Siacoin supply in the format specified by statistics for the Sia network" \
org.opencontainers.image.source="https://github.com/SiaFoundation/cmc-supply-api" \
org.opencontainers.image.licenses=MIT

ENV PUID=0
Expand All @@ -28,4 +28,4 @@ EXPOSE 9981/tcp

USER ${PUID}:${PGID}

ENTRYPOINT [ "coinbased", "-log.stdout", "-dir", "/data", "-api", ":9980" ]
ENTRYPOINT [ "cmcd", "-log.stdout", "-dir", "/data", "-api", ":9980" ]
8 changes: 4 additions & 4 deletions docker/Dockerfile.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ WORKDIR /coinbase
COPY . .
# build
# RUN go generate ./...
RUN go build -o bin/ -tags='testnet netgo timetzdata' -trimpath -a -ldflags '-s -w -linkmode external -extldflags "-static"' ./cmd/coinbased
RUN go build -o bin/ -tags='testnet netgo timetzdata' -trimpath -a -ldflags '-s -w -linkmode external -extldflags "-static"' ./cmd/cmcd

FROM docker.io/library/alpine:3
LABEL maintainer="The Sia Foundation <info@sia.tech>" \
org.opencontainers.image.description.vendor="The Sia Foundation" \
org.opencontainers.image.description="A coinbase container - provides coinbase statistics for the Sia network" \
org.opencontainers.image.source="https://github.com/n8maninger/sia-coinbased" \
org.opencontainers.image.description="A Sia supply API - provides the Siacoin supply in the format specified by statistics for the Sia network" \
org.opencontainers.image.source="https://github.com/SiaFoundation/cmc-supply-api" \
org.opencontainers.image.licenses=MIT

ENV PUID=0
Expand All @@ -28,4 +28,4 @@ EXPOSE 9881/tcp

USER ${PUID}:${PGID}

ENTRYPOINT [ "coinbased", "-log.stdout", "-dir", "/data", "-api", ":9880" ]
ENTRYPOINT [ "cmcd", "-log.stdout", "-dir", "/data", "-api", ":9880" ]
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/n8maninger/sia-coinbased
module go.sia.tech/cmc-supply-api

go 1.20

require (
github.com/shopspring/decimal v1.3.1
gitlab.com/NebulousLabs/encoding v0.0.0-20200604091946-456c3dc907fe
go.sia.tech/core v0.1.12-0.20230502175005-71bb29c5f388
go.sia.tech/jape v0.9.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand Down

0 comments on commit 99cb9d2

Please sign in to comment.