Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tezosconnector base #3

Merged
merged 65 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
652f281
Initial commit
denisandreenko Mar 16, 2023
195b0c9
add dockerignore
denisandreenko Mar 16, 2023
05c5d49
cmd init
denisandreenko Mar 16, 2023
441ff89
add Makefile
denisandreenko Mar 16, 2023
a11fd84
add dependencies
denisandreenko Mar 16, 2023
949fdb5
add Dockerfile
denisandreenko Mar 16, 2023
a9fe097
add golangci config
denisandreenko Mar 16, 2023
8c0d291
add vs code config
denisandreenko Mar 16, 2023
5c0ead9
update Makefile
denisandreenko Mar 17, 2023
1aed651
cmd run impl
denisandreenko Mar 17, 2023
03b7b0f
add git CI workflow
denisandreenko Mar 18, 2023
36da384
update dependencies
denisandreenko Mar 19, 2023
dfc8089
add message translates
denisandreenko Mar 20, 2023
65a9199
add mocks
denisandreenko Mar 20, 2023
011998e
update mockery version
denisandreenko Mar 21, 2023
47c615d
add config command
denisandreenko Mar 21, 2023
7f60039
update deps
denisandreenko Mar 22, 2023
b605e87
add stub FF Transaction Manager interface impl
denisandreenko Mar 24, 2023
4dc60ad
init go tezos client
denisandreenko Apr 16, 2023
bf4e613
DA-291 GetAddressBalance impl
denisandreenko Apr 17, 2023
6cf2b1a
DA-292 GetBlockInfo impl
denisandreenko Apr 18, 2023
f5908b2
DA-293 GetBlockInfoByNumber + block caching impl
denisandreenko Apr 19, 2023
c04c71e
DA-295 add new block listener with basic initialization
denisandreenko Apr 20, 2023
cdd4c84
DA-295 test tezos connector initialization
denisandreenko Apr 20, 2023
aaa8fe7
DA-295 block listener impl
denisandreenko Apr 21, 2023
6359808
DA-292 Fix GetBlockByHash null return + filter block operations
denisandreenko Apr 21, 2023
aea1cdc
DA-316 basic event stream start/stop implementation
denisandreenko Apr 25, 2023
fcec4a6
DA-328 nonce impl
denisandreenko Apr 27, 2023
3c68007
deps update (follow the evmconnect)
denisandreenko May 17, 2023
c1e81a5
add tezos client mocks
denisandreenko May 17, 2023
681a4b3
DA-384 TransactionPrepare impl
denisandreenko May 23, 2023
a7d5483
DA-385 TransactionSend impl
denisandreenko May 23, 2023
f55a239
DA-385 Add tezos transaction signer to the client
denisandreenko May 23, 2023
6af7103
DA-384 update config, remove TODO
denisandreenko May 25, 2023
59d5bdd
DA-385 save tx receipt to leveldb
denisandreenko May 25, 2023
99f9abf
DA-390 TransactionReceipt impl
denisandreenko May 25, 2023
4d965ab
Add blockchain plugin API support (rebase)
denisandreenko Jun 5, 2023
0136a90
DA-384 Add List/Set types support for FFI > Michelson converter
denisandreenko Jun 5, 2023
cb0ea02
DA-384 add address type support
denisandreenko Jun 14, 2023
1f63900
DA-384 add 'schema' type with support of structures and nested types
denisandreenko Jun 16, 2023
8c560cd
DA-384 add list type support to the FFI schema
denisandreenko Jun 18, 2023
43b7914
DA-408 Add 'variant' type support
denisandreenko Jun 24, 2023
d7cb76c
DA-328 NextNonceForSigner impl
denisandreenko Jul 2, 2023
31890d1
DA-432 move rpc/network configs to the config file
denisandreenko Jul 6, 2023
6f5ea2f
DA-428 remote tx signing impl
denisandreenko Jul 7, 2023
8b117fe
DA-434 (Tezos Connector) Replace using of tz client confiramtion mana…
denisandreenko Jul 10, 2023
f544ff8
DA-434 (Tezos Connector) Update deps
denisandreenko Jul 10, 2023
99735d4
update unit tests
denisandreenko Jul 10, 2023
7dd8e88
DA-434 refactoring
denisandreenko Jul 11, 2023
db07a66
DA-441 Add tx extra info into tx receipt
denisandreenko Jul 14, 2023
e735dd5
DA-464 Postgres support
denisandreenko Jul 24, 2023
9e974a8
remove deprecated network config
denisandreenko Jul 31, 2023
0d18f27
update config
denisandreenko Jul 31, 2023
f812251
DA-429 Add account revealing support
denisandreenko Aug 24, 2023
680bae4
DA-494 Add tezos block monitor reconnect logic
denisandreenko Aug 28, 2023
36a85e9
fix nonce assignment
denisandreenko Aug 31, 2023
83ab10d
Update README
denisandreenko Sep 6, 2023
b33a07b
DA-499 fix RPC node error parsing
denisandreenko Sep 7, 2023
fd4fc74
DA-399 GasPriceEstimate impl
denisandreenko Sep 11, 2023
4f70463
DA-505 service status API unit test coverage
denisandreenko Sep 12, 2023
ae257fc
DA-505 update mocks
denisandreenko Sep 13, 2023
9f2b639
DA-505 update deps
denisandreenko Sep 13, 2023
e7f54fc
DA-505 increase unit test coverage
denisandreenko Sep 13, 2023
6c392d2
Get block info fix
denisandreenko Sep 15, 2023
c9bacb0
Merge branch 'pr' into tezosconnector-base
denisandreenko Sep 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# IDE configs
.vscode
.idea
24 changes: 24 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Go

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Build and Test
run: make
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/*.jar
firefly-tezosconnect
coverage.txt
**/debug.test
.DS_Store
__debug*
.leveldb
.vscode/*.log
*.iml
.idea/
35 changes: 35 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
run:
tests: false
skip-dirs:
- "mocks"
linters-settings:
gocritic:
enabled-checks: []
disabled-checks:
- regexpMust
linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- errcheck
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Run tezosconnect",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/tezosconnect/main.go",
"args": [
"-f",
"${workspaceFolder}/tezosconnect_config.yml"
],
"env": {
"FIREFLY_PERSISTENCE_LEVELDB_PATH": "${workspaceFolder}/.leveldb"
}
}
]
}
54 changes: 54 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"go.formatFlags": [
"-s"
],
"go.lintTool": "golangci-lint",
"cSpell.words": [
"btcec",
"bytecode",
"ccache",
"Debugf",
"dklen",
"ethsigner",
"ethtypes",
"tezosconnect",
"ffcapi",
"ffconnector",
"ffconnectormocks",
"FFCPI",
"ffcserver",
"ffcservermocks",
"ffresty",
"fftm",
"fftypes",
"GJSON",
"httpserver",
"hyperledger",
"Infof",
"jsonrpcmocks",
"Kaleido",
"kdfparams",
"Keccak",
"keystorev",
"logrus",
"Nowarn",
"policyengine",
"policyengines",
"resty",
"rpcbackendmocks",
"secp",
"signerconfig",
"signermsgs",
"sigs",
"stretchr",
"Tracef",
"ufixed",
"unmarshalled",
"unmarshalling",
"Vyper",
"Warnf",
"wsclient"
],
"go.testTimeout": "10s"
}

23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:1.19-buster AS builder
ARG BUILD_VERSION
ENV BUILD_VERSION=${BUILD_VERSION}
ADD . /tezosconnect
WORKDIR /tezosconnect
RUN make

# Copy the migrations from FFTM down into our local migrations directory
RUN DB_MIGRATIONS_DIR=$(go list -f '{{.Dir}}' github.com/hyperledger/firefly-transaction-manager/pkg/ffcapi | sed 's|pkg/ffcapi|db|') \
&& cp -R $DB_MIGRATIONS_DIR db

FROM debian:buster-slim
WORKDIR /tezosconnect
RUN apt update -y \
&& apt install -y curl jq \
&& rm -rf /var/lib/apt/lists/* \
&& curl -sL "https://github.com/golang-migrate/migrate/releases/download/$(curl -sL https://api.github.com/repos/golang-migrate/migrate/releases/latest | jq -r '.name')/migrate.linux-amd64.tar.gz" | tar xz \
&& chmod +x ./migrate \
&& mv ./migrate /usr/bin/migrate
COPY --from=builder /tezosconnect/firefly-tezosconnect /usr/bin/tezosconnect
COPY --from=builder /tezosconnect/db/ /tezosconnect/db/

ENTRYPOINT [ "/usr/bin/tezosconnect" ]
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
VGO=go
GOFILES := $(shell find cmd internal -name '*.go' -print)
GOBIN := $(shell $(VGO) env GOPATH)/bin
LINT := $(GOBIN)/golangci-lint
MOCKERY := $(GOBIN)/mockery

.DELETE_ON_ERROR:

all: build test go-mod-tidy
test: deps
$(VGO) test ./internal/... ./cmd/... -cover -coverprofile=coverage.txt -covermode=atomic -timeout=30s
coverage.html:
$(VGO) tool cover -html=coverage.txt
coverage: test coverage.html
lint: ${LINT}
$(LINT) run -v --timeout 5m
${MOCKERY}:
$(VGO) install github.com/vektra/mockery/[email protected]
${LINT}:
$(VGO) install github.com/golangci/golangci-lint/cmd/[email protected]
mockpaths:
$(eval FFTM_PATH := $(shell $(VGO) list -f '{{.Dir}}' github.com/hyperledger/firefly-transaction-manager/pkg/fftm))
$(eval TEZOS_CLIENT_PATH := $(shell $(VGO) list -f '{{.Dir}}' blockwatch.cc/tzgo/rpc))

define makemock
mocks: mocks-$(strip $(1))-$(strip $(2))
mocks-$(strip $(1))-$(strip $(2)): ${MOCKERY} mockpaths
${MOCKERY} --case underscore --dir $(1) --name $(2) --outpkg $(3) --output mocks/$(strip $(3))
endef

$(eval $(call makemock, $$(FFTM_PATH), Manager, fftmmocks))
$(eval $(call makemock, $$(TEZOS_CLIENT_PATH), RpcClient, tzrpcbackendmocks))

firefly-tezosconnect: ${GOFILES}
$(VGO) build -o ./firefly-tezosconnect -ldflags "-X main.buildDate=`date -u +\"%Y-%m-%dT%H:%M:%SZ\"` -X main.buildVersion=$(BUILD_VERSION)" -tags=prod -v ./tezosconnect
go-mod-tidy: .ALWAYS
$(VGO) mod tidy
build: firefly-tezosconnect
.ALWAYS: ;
clean:
$(VGO) clean
deps:
$(VGO) get ./tezosconnect
reference:
$(VGO) test ./cmd -timeout=10s -tags docs
docker:
docker build --build-arg BUILD_VERSION=${BUILD_VERSION} ${DOCKER_ARGS} -t hyperledger/firefly-tezosconnect .
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Hyperledger FireFly Tezos Connector

This repo provides a reference implementation of the FireFly Connector API (FFCAPI)
for Tezos blockchain.

See the [Hyperledger Firefly Documentation](https://hyperledger.github.io/firefly/overview/public_vs_permissioned.html#firefly-architecture-for-public-chains)
and the [FireFly Transaction Manager](https://github.com/hyperledger/firefly-transaction-manager) repository for
more information.

# License

Apache 2.0

## Transaction signing

Tezosconnect leverages remote transaction signing through a powerful 'signatory' service, offering compatibility with multiple key management solutions. With the flexibility to use AWS KMS, Azure KMS, GCP KMS, Yubi HSM, etc. for transaction signing, you can secure your blockchain transactions efficiently and conveniently.

More info at: https://signatory.io/

## Configuration

For a full list of configuration options see [config.md](./config.md)

## Example configuration

```yaml
connector:
blockchain:
rpc: https://rpc.ghost.tzstats.com
network: ghostnet
signatory: http://localhost:6732
```

## Blockchain node compatibility

For Tezos connector to function properly, you should check the blockchain node supports the following RPC Methods:

### Chains
- `GET /chains/<chain_id>/blocks/<block_id>/hash`
- `GET /chains/<chain_id>/blocks/<block_id>/operations/<list_offset>`
- `GET /chains/<chain_id>/blocks/<block_id>/operations/<list_offset>/<operation_offset>`
- `POST /chains/<chain_id>/blocks/<block_id>/helpers/forge/operations`
- `POST /chains/<chain_id>/blocks/<block_id>/helpers/scripts/simulate_operation`
- `POST /chains/<chain_id>/blocks/<block_id>/helpers/scripts/run_operation`

### Block monitoring
- `GET /monitor/heads/<chain_id>`

### Injection
- `POST /injection/operation`
24 changes: 24 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"context"
"fmt"

"github.com/hyperledger/firefly-common/pkg/config"
"github.com/spf13/cobra"
)

func configCommand() *cobra.Command {
versionCmd := &cobra.Command{
Use: "docs",
Short: "Prints the config info as markdown",
Long: "",
RunE: func(cmd *cobra.Command, args []string) error {
InitConfig()
b, err := config.GenerateConfigMarkdown(context.Background(), "", config.GetKnownKeys())
fmt.Println(string(b))
return err
},
}
return versionCmd
}
27 changes: 27 additions & 0 deletions cmd/config_docs_generate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build docs
// +build docs

package cmd

import (
"context"
"os"
"path/filepath"
"testing"

"github.com/hyperledger/firefly-common/pkg/config"
"github.com/stretchr/testify/assert"
)

func TestGenerateConfigDocs(t *testing.T) {
// Initialize config of all plugins
InitConfig()
f, err := os.Create(filepath.Join("..", "config.md"))
assert.NoError(t, err)
generatedConfig, err := config.GenerateConfigMarkdown(context.Background(), "", config.GetKnownKeys())
assert.NoError(t, err)
_, err = f.Write(generatedConfig)
assert.NoError(t, err)
err = f.Close()
assert.NoError(t, err)
}
30 changes: 30 additions & 0 deletions cmd/config_docs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build !docs
// +build !docs

package cmd

import (
"context"
"crypto/sha1"
"os"
"path/filepath"
"testing"

"github.com/hyperledger/firefly-common/pkg/config"
"github.com/stretchr/testify/assert"
)

func TestConfigDocsUpToDate(t *testing.T) {
// Initialize config of all plugins
InitConfig()
generatedConfig, err := config.GenerateConfigMarkdown(context.Background(), "", config.GetKnownKeys())
assert.NoError(t, err)
configOnDisk, err := os.ReadFile(filepath.Join("..", "config.md"))
assert.NoError(t, err)

generatedConfigHash := sha1.New()
generatedConfigHash.Write(generatedConfig)
configOnDiskHash := sha1.New()
configOnDiskHash.Write(configOnDisk)
assert.Equal(t, configOnDiskHash.Sum(nil), generatedConfigHash.Sum(nil), "The config reference docs generated by the code did not match the config.md file in git. Did you forget to run `make docs`?")
}
14 changes: 14 additions & 0 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cmd

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestConfigMarkdown(t *testing.T) {
rootCmd.SetArgs([]string{"docs"})
defer rootCmd.SetArgs([]string{})
err := rootCmd.Execute()
assert.NoError(t, err)
}
Loading