Skip to content

Commit

Permalink
Single-key native segwit Ocean implementation (#11)
Browse files Browse the repository at this point in the history
* Add DeleteAccount & Fix CreateAccountResponse

* Drop account key and refer to account only by name

* Fix account index type

* Update balance type

* Fix field type of BlockDetails

* Add core domains

* Add core portable interfaces

* Add implementations of core ports

* Add reusable packages

* Add core application services

* Add app-config

* Add Service interface and its grpc impelmentation

* Updates protos

* Add oceand

* Add CLI

* Add config

* Go mod

* Add git ignore

* Add makefile

* Add util scripts

* Add CI

* Fix

* Fixes

* Add TODO and remove useless files

* Fixes to proto

* Rename CreateAccount method

* Make use of switch statement

* Fixes to neutrino scanner after review

* Add birthday block to wallet

* Add birthday block to domain.Wallet and optional one for its accounts

* Add starting block height to WatchForAccount && Add methods to retrieve block info

* Add bc scanner to wallet service to retrieve birthday block info

* Pass wallet account starting block down to scanner watch

* Proto updates

* Fix  bc scanner abstraction

* Fix comment

* Update neutrino-elements version

* Add sighash type to sign methods

* Use user-defiened sighash type instead of hardcoding SIGHASH_ALL

* Add expiration date to selected utxos response

* Return expiration date of selected utxos

* Update go-elements & fix creation of new utxos

* Update go-elements version

* Order utxos by value asc in coin selection strategy

* Update go-elements

* Add proofs to partial tx

* Non-blokcing write to channel

* Update go-elements version

* Update protos

* Add domain.UtxoKey.Hash() and blinders to domain.UtxoInfo

* Fixes

* Handle closing of grpc server-side streams

* Update neutrino-elements version && Add persistent watch

* Fix wallet root derivation path

* Fix blockchain scanner start

* Update neutrino-elements version

* Add build info

* Add release flow

* Merge gh actions into ci.yml

* Fix ci

* Fix ci

* Update utxo type

* Add spent/confirmation block info to utxo

* Fix tx estimation

* Add method to lock wallet

* Enable all interfaces at startup

* Fix tests

* Update .goreleaser.yml

* Update .github/workflows/release.yml

* Update deps

* Fix buf.yaml

* Fixes

* Move proto to v1

* Fix race condition cause

* Update go-elements dep

Co-authored-by: Marco Argentieri <3596602+tiero@users.noreply.github.com>
  • Loading branch information
altafan and tiero authored Aug 16, 2022
1 parent e662f74 commit d03d19d
Show file tree
Hide file tree
Showing 127 changed files with 20,989 additions and 5,800 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/buf.yml

This file was deleted.

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

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
integration:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ">1.17.2"

- name: Checkout code
uses: actions/checkout@v3

- name: Seutup buf
uses: bufbuild/buf-setup-action@v1.3.1

- name: Check protos
run: make proto-lint

- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: '-severity high -quiet ./...'

- name: Get dependencies
run: go get -v -t -d ./...

- name: Test
run: make test
74 changes: 74 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: goreleaser

on:
workflow_dispatch:
push:
tags:
- "*"

jobs:
goreleaser:
runs-on: ubuntu-20.04
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup QEMU
uses: docker/setup-qemu-action@v1

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ">1.17.2"

- name: Cache Go modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# This because https://github.com/plentico/osxcross-target/issues/2#issuecomment-815850611
- name: Downgrade libssl
run: |
echo 'deb http://security.ubuntu.com/ubuntu bionic-security main' | sudo tee -a /etc/apt/sources.list
sudo apt update && apt-cache policy libssl1.0-dev
sudo apt-get install libssl1.0-dev
- name: Install OSX cross-compiling targets
run: |
mkdir ../../osxcross
git clone https://github.com/plentico/osxcross-target.git ../../osxcross/target
- name: Install Linux aarch64 cross-compiling targets
run: sudo apt install gcc make gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu


- name: Docker Login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist --debug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}

- name: Setup buf
uses: bufbuild/buf-setup-action@v1.3.1

- name: Publish protos to Buf Schema Registry
uses: bufbuild/buf-push-action@v1
with:
input: api-spec/protobuf
buf_token: ${{ secrets.BUF_TOKEN }}
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

/build/
/dist/

DS_Store
._.DS_Store
**/.DS_Store
**/._.DS_Store

test/e2e/*
!test/e2e/*.go

.vscode/
.idea

localhost.key
localhost.crt
181 changes: 181 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
builds:
# daemon

### Linux
- id: "oceand-linux-amd64"
main: ./cmd/oceand
ldflags:
- -s -X './cmd/oceand/main.version={{.Version}}' -X './cmd/oceand/main.commit={{.Commit}}' -X './cmd/oceand/main.date={{.Date}}'
env:
- CGO_ENABLED=1
goos:
- linux
goarch:
- amd64
binary: oceand-linux-amd64

- id: "oceand-linux-arm64"
main: ./cmd/oceand
ldflags:
- -s -X './cmd/oceand/main.version={{.Version}}' -X './cmd/oceand/main.commit={{.Commit}}' -X './cmd/oceand/main.date={{.Date}}'
env:
- CGO_ENABLED=1
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
goos:
- linux
goarch:
- arm64
binary: oceand-linux-arm64

### Darwin
- id: "oceand-darwin-amd64"
main: ./cmd/oceand
ldflags:
- -s -w
env:
- CGO_ENABLED=1
- CC=/home/runner/work/osxcross/target/bin/o64-clang
- CXX=/home/runner/work/osxcross/target/bin/o64-clang++
goos:
- darwin
goarch:
- amd64
binary: oceand-darwin-amd64

- id: "oceand-darwin-arm64"
main: ./cmd/oceand
ldflags:
- -s -X './cmd/oceand/main.version={{.Version}}' -X './cmd/oceand/main.commit={{.Commit}}' -X './cmd/oceand/main.date={{.Date}}'
env:
- CGO_ENABLED=1
- CC=/home/runner/work/osxcross/target/bin/oa64-clang
- CXX=/home/runner/work/osxcross/target/bin/oa64-clang++
goos:
- darwin
goarch:
- arm64
binary: oceand-darwin-arm64

# CLI
- id: "ocean"
main: ./cmd/ocean
ldflags:
- -s -X 'main.version={{.Version}}' -X 'main.commit={{.Commit}}' -X 'main.date={{.Date}}'
goos:
- linux
- darwin
goarch:
- amd64
- arm64
binary: ocean-darwin

## flag the semver v**.**.**-<tag>.* as pre-release on Github
release:
prerelease: auto

checksum:
name_template: "checksums.txt"


snapshot:
name_template: "{{ .Tag }}-next"

changelog:
use: github

archives:
- id: oceand
format: binary
builds:
- oceand-linux-amd64
- oceand-linux-arm64
- oceand-darwin-amd64
- oceand-darwin-arm64
name_template: "oceand-v{{ .Version }}-{{ .Os }}-{{ .Arch }}"

- id: ocean
format: binary
builds:
- ocean
name_template: "ocean-v{{ .Version }}-{{ .Os }}-{{ .Arch }}"

dockers:
###########################
# tag latest & prerelease #
###########################

#amd64
- image_templates:
- "ghcr.io/vulpemventures/oceand:{{ .Tag }}-amd64"
# push always either release or prerelease with a docker tag with the semver only
skip_push: "false"
use: buildx
dockerfile: Dockerfile
# GOOS of the built binaries/packages that should be used.
goos: linux
# GOARCH of the built binaries/packages that should be used.
goarch: amd64
# Template of the docker build flags.
build_flag_templates:
- "--platform=linux/amd64"
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title=oceand"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--build-arg=VERSION={{.Version}}"
- "--build-arg=COMMIT={{.Commit}}"
- "--build-arg=DATE={{.Date}}"

extra_files:
- go.mod
- go.sum
- internal
- pkg
- cmd
- api-spec

# arm64
- image_templates:
- "ghcr.io/vulpemventures/oceand:{{ .Tag }}-arm64v8"
# push always either release or prerelease with a docker tag with the semver only
skip_push: "false"
use: buildx
dockerfile: Dockerfile
# GOOS of the built binaries/packages that should be used.
goos: linux
# GOARCH of the built binaries/packages that should be used.
goarch: arm64
# Template of the docker build flags.
build_flag_templates:
- "--platform=linux/arm64/v8"
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title=oceand"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--build-arg=VERSION={{.Version}}"
- "--build-arg=COMMIT={{.Commit}}"
- "--build-arg=DATE={{.Date}}"

extra_files:
- go.mod
- go.sum
- internal
- pkg
- cmd
- api-spec

docker_manifests:
- name_template: ghcr.io/vulpemventures/oceand:{{ .Tag }}
image_templates:
- ghcr.io/vulpemventures/oceand:{{ .Tag }}-amd64
- ghcr.io/vulpemventures/oceand:{{ .Tag }}-arm64v8
skip_push: "false"

- name_template: ghcr.io/vulpemventures/oceand:latest
image_templates:
- ghcr.io/vulpemventures/oceand:{{ .Tag }}-amd64
- ghcr.io/vulpemventures/oceand:{{ .Tag }}-arm64v8
skip_push: auto
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# first image used to build the sources
FROM golang:1.17-buster AS builder

ARG VERSION
ARG COMMIT
ARG DATE
ARG TARGETOS
ARG TARGETARCH


WORKDIR /oceand

COPY . .
RUN go mod download

RUN CGO_ENABLED=1 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-X 'main.Version=${COMMIT}' -X 'main.Commit=${COMMIT}' -X 'main.Date=${COMMIT}'" -o oceand-linux cmd/oceand/main.go
RUN go build -ldflags="-X 'main.version=${VERSION}' -X 'main.commit=${COMMIT}' -X 'main.date=${DATE}'" -o ocean cmd/ocean/*

WORKDIR /build

RUN cp /oceand/oceand-linux .
RUN cp /oceand/ocean .

# Second image, running the oceand executable
FROM debian:buster

RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates

COPY --from=builder /build/oceand-linux /
COPY --from=builder /build/ocean /

RUN install /ocean /bin
# Prevents `VOLUME $HOME/.oceand/` being created as owned by `root`
RUN useradd -ms /bin/bash user
USER user
RUN mkdir -p "$HOME/.oceand/"

# Expose ports of grpc server and profiler
EXPOSE 18000
EXPOSE 18001

CMD /oceand-linux

Loading

0 comments on commit d03d19d

Please sign in to comment.