Skip to content

Commit

Permalink
Merge pull request #220 from babylonchain/merge-main-into-dev-branch-2
Browse files Browse the repository at this point in the history
Merge main into dev branch 2
  • Loading branch information
jrwbabylonlab authored Jul 30, 2024
2 parents fcd2332 + af0607c commit e63b18c
Show file tree
Hide file tree
Showing 41 changed files with 1,383 additions and 180 deletions.
105 changes: 0 additions & 105 deletions .circleci/config.yml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: ci

on:
pull_request:
branches:
- '**'

jobs:
lint_test:
uses: babylonchain/.github/.github/workflows/[email protected]
with:
run-unit-tests: true
run-integration-tests: false
run-lint: false

docker_pipeline:
uses: babylonchain/.github/.github/workflows/[email protected]
secrets: inherit
with:
publish: false
dockerfile: ./contrib/images/staking-api-service/Dockerfile
25 changes: 25 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: docker_publish

on:
push:
branches:
- 'main'
- 'dev'
tags:
- '*'

jobs:
lint_test:
uses: babylonchain/.github/.github/workflows/[email protected]
with:
run-unit-tests: true
run-integration-tests: false
run-lint: false

docker_pipeline:
needs: ["lint_test"]
uses: babylonchain/.github/.github/workflows/[email protected]
secrets: inherit
with:
publish: true
dockerfile: ./contrib/images/staking-api-service/Dockerfile
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ run-unprocessed-events-replay-local:
--replay

generate-mock-interface:
cd internal/db && mockery --name=DBClient --output=../../tests/mocks --outpkg=dbmock --filename=mock_db_client.go
cd internal/db && mockery --name=DBClient --output=../../tests/mocks --outpkg=mocks --filename=mock_db_client.go
cd internal/clients/ordinals && mockery --name=OrdinalsClientInterface --output=../../../tests/mocks --outpkg=mocks --filename=mock_ordinal_client.go
cd internal/clients/unisat && mockery --name=UnisatClientInterface --output=../../../tests/mocks --outpkg=mocks --filename=mock_unisat_client.go

tests:
test:
./bin/local-startup.sh;
go test -v -cover -p 1 ./... -count=1

Expand Down
10 changes: 10 additions & 0 deletions bin/init-mongo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ mongosh --eval "rs.initiate({_id: 'RS', members: [{ _id: 0, host: 'localhost:270
# Wait for replica set to initiate
sleep 5

# Create the root user
mongosh --eval "
db = db.getSiblingDB('admin');
db.createUser({
user: 'root',
pwd: 'example',
roles: [{ role: 'root', db: 'admin' }]
});
"

# Create the necessary indexes
mongosh --eval "
db = db.getSiblingDB('staking-api-service');
Expand Down
5 changes: 3 additions & 2 deletions bin/local-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ $(docker ps -q -f name=^/${MONGO_CONTAINER_NAME}$) ]; then
else
echo "Starting MongoDB"
# Start MongoDB
docker-compose up mongodb -d
docker-compose up -d mongodb
fi

# Check if the RabbitMQ container is already running
Expand All @@ -17,5 +17,6 @@ if [ $(docker ps -q -f name=^/${RABBITMQ_CONTAINER_NAME}$) ]; then
else
echo "Starting RabbitMQ"
# Start RabbitMQ
docker-compose up rabbitmq -d
docker-compose up -d rabbitmq
sleep 10
fi
8 changes: 6 additions & 2 deletions cmd/staking-api-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/babylonchain/staking-api-service/cmd/staking-api-service/cli"
"github.com/babylonchain/staking-api-service/cmd/staking-api-service/scripts"
"github.com/babylonchain/staking-api-service/internal/api"
"github.com/babylonchain/staking-api-service/internal/clients"
"github.com/babylonchain/staking-api-service/internal/config"
"github.com/babylonchain/staking-api-service/internal/db/model"
"github.com/babylonchain/staking-api-service/internal/observability/healthcheck"
Expand Down Expand Up @@ -59,12 +60,15 @@ func main() {
if err != nil {
log.Fatal().Err(err).Msg("error while setting up staking db model")
}
services, err := services.New(ctx, cfg, params, finalityProviders)

// initialize clients package which is used to interact with external services
clients := clients.New(cfg)
services, err := services.New(ctx, cfg, params, finalityProviders, clients)
if err != nil {
log.Fatal().Err(err).Msg("error while setting up staking services layer")
}
// Start the event queue processing
queues := queue.New(&cfg.Queue, services)
queues := queue.New(cfg.Queue, services)

// Check if the replay flag is set
if cli.GetReplayFlag() {
Expand Down
15 changes: 14 additions & 1 deletion config/config-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ server:
write-timeout: 60s
read-timeout: 60s
idle-timeout: 60s
allowed-origins: [ "*" ]
allowed-origins: ["*"]
log-level: debug
btc-net: "mainnet"
max-content-length: 4096
health-check-interval: 300 # 5 minutes interval
db:
username: root
password: example
address: "mongodb://mongodb:27017"
db-name: staking-api-service
max-pagination-limit: 10
Expand All @@ -26,3 +28,14 @@ queue:
metrics:
host: 0.0.0.0
port: 2112
assets:
max_utxos: 100
ordinals:
host: "http://ord-poc.devnet.babylonchain.io"
port: 8888
timeout: 1000
unisat:
host: "https://open-api.unisat.io"
limit: 100
timeout: 1000
token: "add your token as ASSETS_UNISAT_TOKEN in environment variables"
15 changes: 14 additions & 1 deletion config/config-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ server:
write-timeout: 60s
read-timeout: 60s
idle-timeout: 60s
allowed-origins: [ "*" ]
allowed-origins: ["*"]
log-level: debug
btc-net: "signet"
max-content-length: 4096
health-check-interval: 300 # 5 minutes interval
db:
username: root
password: example
address: "mongodb://localhost:27017/?directConnection=true"
db-name: staking-api-service
max-pagination-limit: 10
Expand All @@ -26,3 +28,14 @@ queue:
metrics:
host: 0.0.0.0
port: 2112
assets:
max_utxos: 100
ordinals:
host: "http://ord-poc.devnet.babylonchain.io"
port: 8888
timeout: 5000
unisat:
host: "https://open-api-testnet.unisat.io"
limit: 100
timeout: 5000
token: "add your token as ASSETS_UNISAT_TOKEN in .env"
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ services:
hostname: mongodb
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
volumes:
- ./bin/init-mongo.sh:/init-mongo.sh
entrypoint: [ "/init-mongo.sh" ]
Expand Down
8 changes: 6 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,18 @@ const docTemplate = `{
"VALIDATION_ERROR",
"NOT_FOUND",
"BAD_REQUEST",
"FORBIDDEN"
"FORBIDDEN",
"UNPROCESSABLE_ENTITY",
"REQUEST_TIMEOUT"
],
"x-enum-varnames": [
"InternalServiceError",
"ValidationError",
"NotFound",
"BadRequest",
"Forbidden"
"Forbidden",
"UnprocessableEntity",
"RequestTimeout"
]
}
}
Expand Down
55 changes: 55 additions & 0 deletions docs/ordinals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Ordinals in API system

The Babylon Staking API allows for the option to deploy additional endpoints
that check whether a UTXO contains an inscription or not, with the aim to help
staking applications identify whether they should avoid spending a particular UTXO.
This is accomplished through a connection to the
[Ordinal Service](https://github.com/ordinals/ord) and
a connection to the Unisat API.
Due to Unisat being a payed service and applying rate limits,
the API initially tries to get the status of a UTXO through the Ordinals Service,
and if that fails, then contacts the Unisat API,
effectively using it as a back-up mechanism to handle downtime from the Ordinals Service.

NOTE: To enable the optional ordinal API endpoint, you will need to provide the
`ordinal` and `unisat` configurations under `assets`

## Ordinal service Client

WIP

## Unisat Service Client

You can find more information about Unisat's Ordinal/BRC-20/Runes related endpoints at:
https://docs.unisat.io/

In our service, we only utilize the following endpoint:
- `/v1/indexer/address/{{address}}/inscription-utxo-data`

### How to Use It

1. Log in via https://developer.unisat.io/account/login (create an account if you don't have one).
2. Copy the `API-Key`.
3. Set the key as an environment variable named `UNISAT_TOKEN`.
4. Configure the values for `unisat.host`, `limit`, `timeout`, etc. Refer to `config-docker.yml`.
5. Ensure you also set up the `ordinals` configuration, as this is a dependency.
6. Call the POST endpoint `/v1/ordinals/verify-utxos` as shown in the example below:
7. The calls to unisat will only be triggered if the ordinal service is not responding or returning errors
```POST
{
"utxos": [
{
"txid": "143c33b4ff4450a60648aec6b4d086639322cb093195226c641ae4f0ae33c3f5",
"vout": 2
},
{
"txid": "be3877c8dedd716f026cc77ef3f04f940b40b064d1928247cff5bb08ef1ba58e",
"vout": 0
},
{
"txid": "d7f65a37f59088b3b4e4bc119727daa0a0dd8435a645c49e6a665affc109539d",
"vout": 0
}
],
"address": "tb1pyqjxwcdv6pfcaj2l565ludclz2pwu2k5azs6uznz8kml74kkma6qm0gzlv"
}
Loading

0 comments on commit e63b18c

Please sign in to comment.