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

Feature/bank module #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
94 changes: 94 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')

export GO111MODULE = on

###############################################################################
### All ###
###############################################################################

all: build test-unit

###############################################################################
### Build flags ###
###############################################################################

LD_FLAGS = -X github.com/forbole/juno/v5/cmd.Version=$(VERSION) \
-X github.com/forbole/juno/v5/cmd.Commit=$(COMMIT)
BUILD_FLAGS := -ldflags '$(LD_FLAGS)'

ifeq ($(LINK_STATICALLY),true)
LD_FLAGS += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif

build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

BUILD_FLAGS := -ldflags '$(LD_FLAGS)' -tags "$(build_tags)"

###############################################################################
### Build ###
###############################################################################

build: go.sum
ifeq ($(OS),Windows_NT)
@echo "building callisto binary..."
@go build -mod=readonly $(BUILD_FLAGS) -o build/callisto.exe ./cmd/callisto
else
@echo "building callisto binary..."
@go build -mod=readonly $(BUILD_FLAGS) -o build/bdjuno ./cmd/bdjuno
endif
.PHONY: build

###############################################################################
### Install ###
###############################################################################

install: go.sum
@echo "installing callisto binary..."
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/bdjuno
.PHONY: install

###############################################################################
### Tests & Simulation ###
###############################################################################

stop-docker-test:
@echo "Stopping Docker container..."
@docker stop callisto-test-db || true && docker rm callisto-test-db || true
.PHONY: stop-docker-test

start-docker-test: stop-docker-test
@echo "Starting Docker container..."
@docker run --name callisto-test-db -e POSTGRES_USER=callisto -e POSTGRES_PASSWORD=password -e POSTGRES_DB=callisto -d -p 6433:5432 postgres
.PHONY: start-docker-test

test-unit: start-docker-test
@echo "Executing unit tests..."
@go test -mod=readonly -v -coverprofile coverage.txt ./...
.PHONY: test-unit

###############################################################################
### Linting ###
###############################################################################
golangci_lint_cmd=github.com/golangci/golangci-lint/cmd/golangci-lint

lint:
@echo "--> Running linter"
@go run $(golangci_lint_cmd) run --timeout=10m

lint-fix:
@echo "--> Running linter"
@go run $(golangci_lint_cmd) run --fix --out-format=tab --issues-exit-code=0

.PHONY: lint lint-fix

format:
find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*_mocks.go' | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*_mocks.go' | xargs misspell -w
find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*_mocks.go' | xargs goimports -w -local github.com/forbole/callisto
.PHONY: format

clean:
rm -f tools-stamp ./build/**
.PHONY: clean
33 changes: 33 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
chain:
bech32_prefix: rarimo
modules:
- bank

node:
type: remote
config:
rpc:
client_name: juno
address:
max_connections: 20
grpc:
address: localhost:9090
insecure: true
parsing:
workers: 1
start_height: 1
average_block_time: 5s
listen_new_blocks: true
parse_old_blocks: true
parse_genesis: true
database:
url:
max_open_connections: 1
max_idle_connections: 1
partition_size: 100000
partition_batch: 1000
logging:
level: debug
format: text
actions:
port: 3000
25 changes: 25 additions & 0 deletions database/coin_transfer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package database

import (
"fmt"

dbtypes "github.com/rarimo/bdjuno/database/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lib/pq"
)

// SaveCoinTransfer allows to save tokens transfers
func (db *Db) SaveCoinTransfer(coin sdk.Coins, height int64, event, address string, txHash string) error {
query := `
INSERT INTO coin_transfer (coins, height, event, address, tx_hash)
VALUES ($1, $2, $3, $4, $5)
`

_, err := db.SQL.Exec(query, pq.Array(dbtypes.NewDbCoins(coin)), height, event, address, txHash)
if err != nil {
return fmt.Errorf("error while storing tokens transfer: %s", err)
}

return nil
}
1 change: 1 addition & 0 deletions database/schema/02-bank.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ CREATE INDEX supply_height_index ON supply (height);

-- +migrate Down
DROP TABLE supply;

13 changes: 13 additions & 0 deletions database/schema/18-coin-transfer-bank.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- +migrate Up
CREATE TABLE coin_transfer
(
id SERIAL PRIMARY KEY,
event TEXT,
address TEXT,
coins COIN[] NOT NULL,
height BIGINT NOT NULL,
tx_hash TEXT
);

-- +migrate Down
DROP TABLE coin_transfer;
23 changes: 23 additions & 0 deletions database/types/coin_transfer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package types

// CoinTransferRow represents a coin transfer
type CoinTransferRow struct {
ID int64 `db:"id"`
Coin *DbCoin `db:"coin"`
Height int64 `db:"height"`
Event string `db:"event"`
Address string `db:"address"`
TxHash string `db:"tx_hash"`
}

// NewCoinTransferRow allows to easily create a new CoinTransferRow
func NewCoinTransferRow(id int64, coin DbCoin, height int64, event, address string, txHash string) CoinTransferRow {
return CoinTransferRow{
ID: id,
Coin: &coin,
Height: height,
Event: event,
Address: address,
TxHash: txHash,
}
}
30 changes: 21 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ require (

require (
cloud.google.com/go v0.112.2 // indirect
cloud.google.com/go/compute v1.25.1 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.7 // indirect
cloud.google.com/go/storage v1.39.1 // indirect
Expand Down Expand Up @@ -71,10 +70,13 @@ require (
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/github/smimesign v0.2.0 // indirect
github.com/go-gorp/gorp/v3 v3.0.2 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gobuffalo/logger v1.0.7 // indirect
Expand All @@ -97,6 +99,7 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
Expand All @@ -111,28 +114,26 @@ require (
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.2 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/iden3/go-iden3-crypto v0.0.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/keybase/go-crypto v0.0.0-20200123153347-de78d2cb44f4 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.20.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/petermattis/goid v0.0.0-20240327183114-c42a807a84ba // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand All @@ -142,18 +143,23 @@ require (
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/tsdb v0.7.1 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/rarimo/certificate-transparency-go v0.0.0-20240305114501-050b1f19639a // indirect
github.com/rarimo/go-merkle v0.0.0-20231004122345-36fa49031c66 // indirect
github.com/rarimo/ldif-sdk v0.4.6-rc.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rjeczalik/notify v0.9.1 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.1 // indirect
github.com/status-im/keycard-go v0.2.0 // indirect
Expand All @@ -173,20 +179,25 @@ require (
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
gitlab.com/distributed_lab/logan v3.8.1+incompatible // indirect
go.etcd.io/bbolt v1.3.9 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.170.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
Expand All @@ -205,4 +216,5 @@ replace (
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/tendermint/tendermint => github.com/tendermint/tendermint v0.34.24
google.golang.org/grpc => google.golang.org/grpc v1.55.0
nhooyr.io/websocket => github.com/coder/websocket v1.8.7
)
Loading