Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from optakt/add-rosetta-api
Browse files Browse the repository at this point in the history
Add Rosetta API
  • Loading branch information
awfm9 authored Sep 24, 2021
2 parents 2797842 + 3f6be5e commit 67ca044
Show file tree
Hide file tree
Showing 190 changed files with 18,911 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Goal of this PR

Fixes #

## Checklist

- [ ] Is on the right branch
- [ ] Documentation is up-to-date
- [ ] Tests are up-to-date
107 changes: 107 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: CI

# Continuous integration will run whenever a pull request for the master branch
# is created or updated.
on:
workflow_dispatch:
pull_request:
branches:
- master

jobs:
check:
runs-on: ubuntu-latest

steps:
- name: Check out source code
uses: actions/checkout@v2

- name: Check out FlowGo
uses: actions/checkout@v2
with:
repository: onflow/flow-go
ref: c0afa789365eb7a22713ed76b8de1e3efaf3a70a
path: flow-go

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# Here, we simply print the exact go version, to have it as part of the
# action's output, which might be convenient.
- name: Print Go version
run: go version

# The protobuf steps uses the official instructions to install the
# pre-compiled binary, see:
# https://grpc.io/docs/protoc-installation/#install-pre-compiled-binaries-any-os
- name: Install Protobuf compiler
run: |
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
curl -LO $PB_REL/download/v3.17.3/protoc-3.17.3-linux-x86_64.zip
unzip protoc-3.17.3-linux-x86_64.zip -d $HOME/.local
export PATH="$PATH:$HOME/.local/bin"
git clean -fd
# In order to be able to generate the protocol buffer and GRPC files, we
# need to install the related Go modules.
- name: Install Protobuf dependencies
run: |
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
go install github.com/srikrsna/[email protected]
# Since building relic takes some time, we want to cache it.
- name: Cache Crypto package
uses: actions/cache@v2
with:
path: ./flow-go/crypto
key: ${{ runner.os }}-crypto
restore-keys: |
${{ runner.os }}-crypto
# In order to be able to build with flow-go and the relic tag, we need to
# run its go generate target.
- name: Install Flow Go's crypto
run: |
cd ./flow-go/crypto
go generate .
# This check makes sure that the `go.mod` and `go.sum` files for Go
# modules are always up-to-date.
- name: Verify Go modules
run: go mod tidy && git status && git --no-pager diff && git diff-index --quiet HEAD --

# This check makes sure that the generated protocol buffer files in Go
# have been updated in case there was a change in the definitions.
- name: Verify generated files
run: go generate ./... && git status && git --no-pager diff && git diff-index --quiet HEAD --

# This check makes sure that the source code is formatted according to the
# Go standard `go fmt` formatting.
- name: Verify source code formatting
run: go fmt ./... && git status && git --no-pager diff && git diff-index --quiet HEAD --

# This check makes sure that we can compile the binary as a pure Go binary
# without CGO support.
- name: Verify compilation
run: go build -tags relic ./...

# This check runs all unit tests with verbose output and ensures that all
# of the tests pass successfully.
- name: Verify unit tests
run: go test -tags relic -v ./...

# This check runs all integration tests with verbose output and ensures
# that they pass successfully.
- name: Verify integration tests
run: go test -v -tags="relic integration" ./...
97 changes: 97 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: AutoRelease

# AutoRelease will run whenever a tag is pushed.
on:
workflow_dispatch:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Check out FlowGo
uses: actions/checkout@v2
with:
repository: onflow/flow-go
ref: c0afa789365eb7a22713ed76b8de1e3efaf3a70a
path: flow-go

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# Here, we simply print the exact go version, to have it as part of the
# action's output, which might be convenient.
- name: Print Go version
run: go version

# The protobuf steps uses the official instructions to install the
# pre-compiled binary, see:
# https://grpc.io/docs/protoc-installation/#install-pre-compiled-binaries-any-os
- name: Install Protobuf compiler
run: |
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
curl -LO $PB_REL/download/v3.17.3/protoc-3.17.3-linux-x86_64.zip
unzip protoc-3.17.3-linux-x86_64.zip -d $HOME/.local
export PATH="$PATH:$HOME/.local/bin"
git clean -fd
# In order to be able to generate the protocol buffer and GRPC files, we
# need to install the related Go modules.
- name: Install Protobuf dependencies
run: |
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
go install github.com/srikrsna/[email protected]
# In order to be able to build with flow-go and the relic tag, we need to
# run its go generate target.
- name: Install Flow Go's crypto
run: |
cd ./flow-go/crypto
go generate .
# This check makes sure that the `go.mod` and `go.sum` files for Go
# modules are always up-to-date.
- name: Verify Go modules
run: go mod tidy && git status && git --no-pager diff && git diff-index --quiet HEAD --

# This check makes sure that the generated protocol buffer files in Go
# have been updated in case there was a change in the definitions.
- name: Generate files
run: go generate ./... && git status && git --no-pager diff && git diff-index --quiet HEAD --

# Install GoReleaser and print its version before running.
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
install-only: true

- name: Show GoReleaser version
run: goreleaser -v

# Run GoReleaser.
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/cmd/flow-rosetta-server/flow-rosetta-server
*.cdc
*.checkpoint
*.log
flow-go/
28 changes: 28 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# By default, builds only for darwin and linux, which works for us since FlowGo does not support
# Windows builds. We also can only build on amd64 architectures since all others are also not
# supported at the moment.
builds:
- id: rosetta-server
binary: rosetta-server
main: ./cmd/flow-rosetta-server
goos:
- linux
goarch:
- amd64
flags:
- -tags=relic

archives:
- replacements:
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
Empty file modified README.md
100644 → 100755
Empty file.
50 changes: 50 additions & 0 deletions api/rosetta/balance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2021 Optakt Labs OÜ
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.

package rosetta

import (
"github.com/labstack/echo/v4"

"github.com/optakt/flow-rosetta/rosetta/request"
"github.com/optakt/flow-rosetta/rosetta/response"
)

// Balance implements the /account/balance endpoint of the Rosetta Data API.
// See https://www.rosetta-api.org/docs/AccountApi.html#accountbalance
func (d *Data) Balance(ctx echo.Context) error {

var req request.Balance
err := ctx.Bind(&req)
if err != nil {
return unpackError(err)
}

err = d.validate.Request(req)
if err != nil {
return formatError(err)
}

rosBlockID, balances, err := d.retrieve.Balances(req.BlockID, req.AccountID, req.Currencies)
if err != nil {
return apiError(balancesRetrieval, err)
}

res := response.Balance{
BlockID: rosBlockID,
Balances: balances,
}

return ctx.JSON(statusOK, res)
}
Loading

0 comments on commit 67ca044

Please sign in to comment.