Skip to content

Commit e1e3aab

Browse files
Merge pull request #1 from hyle-team/feature/nft-module
Feature/nft module
2 parents 21f9077 + 685ed26 commit e1e3aab

File tree

8,278 files changed

+2434
-2288227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

8,278 files changed

+2434
-2288227
lines changed

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
.idea/
2-
build/
2+
build/
3+
4+
config.local.yaml
5+
# Coverage
6+
coverage.*
7+
vendor

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ RUN git config --global url."https://olegfomenkodev:${CI_ACCESS_TOKEN}@github.co
1818

1919
COPY . .
2020

21+
RUN go mod vendor
2122
RUN go build -mod=vendor -o /usr/local/bin/callisto /go/src/github.com/forbole/callisto/cmd/bdjuno
2223

2324

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ test-unit: start-docker-test
7373
###############################################################################
7474
golangci_lint_cmd=github.com/golangci/golangci-lint/cmd/golangci-lint
7575

76+
##TODO fix linter
7677
lint:
7778
@echo "--> Running linter"
7879
@go run $(golangci_lint_cmd) run --timeout=10m

cmd/bdjuno/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/forbole/juno/v4/modules/messages"
1010

1111
migratecmd "github.com/forbole/bdjuno/v4/cmd/migrate"
12+
migratedbcmd "github.com/forbole/bdjuno/v4/cmd/migrate_db"
1213
parsecmd "github.com/forbole/bdjuno/v4/cmd/parse"
1314

1415
"github.com/forbole/bdjuno/v4/types/config"
@@ -40,6 +41,7 @@ func main() {
4041
parsecmd.NewParseCmd(cfg.GetParseConfig()),
4142
migratecmd.NewMigrateCmd(cfg.GetName(), cfg.GetParseConfig()),
4243
startcmd.NewStartCmd(cfg.GetParseConfig()),
44+
migratedbcmd.NewMigrateDBCmd(cfg.GetParseConfig()),
4345
)
4446

4547
executor := cmd.PrepareRootCmd(cfg.GetName(), rootCmd)

cmd/migrate_db/migrate_db.go

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package migrate_db
2+
3+
import (
4+
"database/sql"
5+
"github.com/cosmos/cosmos-sdk/types/errors"
6+
"github.com/forbole/bdjuno/v4/database"
7+
parsecmdtypes "github.com/forbole/juno/v4/cmd/parse/types"
8+
"github.com/forbole/juno/v4/logging"
9+
"github.com/forbole/juno/v4/types/config"
10+
migrate "github.com/rubenv/sql-migrate"
11+
12+
"github.com/spf13/cobra"
13+
)
14+
15+
var migrations = &migrate.EmbedFileSystemMigrationSource{
16+
FileSystem: database.Migrations,
17+
Root: "schema",
18+
}
19+
20+
func NewMigrateDBCmd(parseCfg *parsecmdtypes.Config) *cobra.Command {
21+
cmd := &cobra.Command{
22+
Use: "migrate-db",
23+
Short: "Migrate the database schema",
24+
PersistentPreRunE: runPersistentPreRuns(parsecmdtypes.ReadConfigPreRunE(parseCfg)),
25+
}
26+
27+
cmd.AddCommand(
28+
&cobra.Command{
29+
Use: "up",
30+
Short: "migrate db up",
31+
RunE: func(cmd *cobra.Command, args []string) error {
32+
context, err := parsecmdtypes.GetParserContext(config.Cfg, parseCfg)
33+
if err != nil {
34+
return err
35+
}
36+
db := database.Cast(context.Database)
37+
return migrateUp(db.SQL.DB, context.Logger)
38+
},
39+
},
40+
)
41+
42+
cmd.AddCommand(
43+
&cobra.Command{
44+
Use: "down",
45+
Short: "migrate db down",
46+
RunE: func(cmd *cobra.Command, args []string) error {
47+
context, err := parsecmdtypes.GetParserContext(config.Cfg, parseCfg)
48+
if err != nil {
49+
return err
50+
}
51+
db := database.Cast(context.Database)
52+
return migrateDown(db.SQL.DB, context.Logger)
53+
},
54+
},
55+
)
56+
57+
return cmd
58+
}
59+
60+
func migrateUp(rawDB *sql.DB, log logging.Logger) error {
61+
applied, err := migrate.Exec(rawDB, "postgres", migrations, migrate.Up)
62+
if err != nil {
63+
return errors.Wrap(err, "failed to apply migrations")
64+
}
65+
log.Info("migrations applied", map[string]interface{}{
66+
"applied": applied,
67+
})
68+
return nil
69+
}
70+
71+
func migrateDown(rawDB *sql.DB, log logging.Logger) error {
72+
applied, err := migrate.Exec(rawDB, "postgres", migrations, migrate.Down)
73+
if err != nil {
74+
return errors.Wrap(err, "failed to apply migrations")
75+
}
76+
log.Info("migrations applied", map[string]interface{}{
77+
"applied": applied,
78+
})
79+
return nil
80+
}
81+
82+
func runPersistentPreRuns(preRun func(_ *cobra.Command, _ []string) error) func(_ *cobra.Command, _ []string) error {
83+
return func(cmd *cobra.Command, args []string) error {
84+
if root := cmd.Root(); root != nil {
85+
if root.PersistentPreRunE != nil {
86+
err := root.PersistentPreRunE(root, args)
87+
if err != nil {
88+
return err
89+
}
90+
}
91+
}
92+
93+
return preRun(cmd, args)
94+
}
95+
}

config.yaml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
actions:
2+
port: 8000
3+
chain:
4+
bech32_prefix: bridge
5+
modules:
6+
- modules
7+
- messages
8+
- auth
9+
- bank
10+
- consensus
11+
- feegrant
12+
- gov
13+
- mint
14+
- slashing
15+
- staking
16+
- distribution
17+
- actions
18+
- upgrade
19+
- nft
20+
- accumulator
21+
- bridge
22+
database:
23+
host: scan-pg
24+
max_idle_connections: 10
25+
max_open_connections: 20
26+
name: scan
27+
partition_batch: 1000
28+
partition_size: 100000
29+
password: scan
30+
port: 5432
31+
url: postgres://postgres:postgres@localhost:5432/juno?sslmode=disable
32+
user: scan
33+
logging:
34+
format: text
35+
level: debug
36+
node:
37+
config:
38+
grpc:
39+
address: http://localhost:9090
40+
insecure: true
41+
rpc:
42+
address: http://localhost:26657
43+
client_name: juno
44+
max_connections: 10
45+
type: remote
46+
parsing:
47+
average_block_time: 5s
48+
genesis_file_path: genesis.json
49+
listen_new_blocks: true
50+
parse_genesis: false
51+
parse_old_blocks: false
52+
start_height: 1
53+
workers: 1

database/accumulator.go

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package database
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
sdk "github.com/cosmos/cosmos-sdk/types"
7+
dbtypes "github.com/forbole/bdjuno/v4/database/types"
8+
"github.com/forbole/bdjuno/v4/types"
9+
"github.com/lib/pq"
10+
)
11+
12+
// SaveAdmin allows to save new Admin
13+
func (db *Db) SaveAdmin(address string, vestingCount, lastVestingTime, vestingPeriod int64, rewardPerPeriod sdk.Coin, denom string) error {
14+
query := `
15+
INSERT INTO admins_vesting(address, vesting_period, reward_per_period, last_vesting_time, vesting_counter, denom)
16+
VALUES ($1, $2, $3, $4, $5, $6)
17+
ON CONFLICT (address) DO UPDATE
18+
SET vesting_counter = excluded.vesting_counter,
19+
last_vesting_time = excluded.last_vesting_time
20+
WHERE admins_vesting.address <= excluded.address
21+
`
22+
_, err := db.SQL.Exec(query, address, vestingPeriod, pq.Array(dbtypes.NewDbCoins(sdk.NewCoins(rewardPerPeriod))), lastVestingTime, vestingCount, denom)
23+
if err != nil {
24+
return fmt.Errorf("error while storing admin vesting info: %s", err)
25+
}
26+
27+
return nil
28+
}
29+
30+
// -------------------------------------------------------------------------------------------------------------------
31+
32+
// SaveAccumulatorParams allows to store the given params inside the database
33+
func (db *Db) SaveAccumulatorParams(params *types.AccumulatorParams) error {
34+
paramsBz, err := json.Marshal(&params.Params)
35+
if err != nil {
36+
return fmt.Errorf("error while marshaling accumulator params: %s", err)
37+
}
38+
39+
stmt := `
40+
INSERT INTO accumulator_params (params, height)
41+
VALUES ($1, $2)
42+
ON CONFLICT (one_row_id) DO UPDATE
43+
SET params = excluded.params,
44+
height = excluded.height
45+
WHERE accumulator_params.height <= excluded.height
46+
`
47+
48+
_, err = db.SQL.Exec(stmt, string(paramsBz), params.Height)
49+
if err != nil {
50+
return fmt.Errorf("error while storing accumulator params: %s", err)
51+
}
52+
53+
return nil
54+
}
55+
56+
// GetAdmins returns all the admins that are currently stored inside the database.
57+
func (db *Db) GetAdmins() ([]dbtypes.AdminVestingRow, error) {
58+
var rows []dbtypes.AdminVestingRow
59+
err := db.Sqlx.Select(&rows, `SELECT * FROM admins_vesting WHERE to_timestamp(last_vesting_time) + INTERVAL '1 second' * last_vesting_time < NOW();`)
60+
return rows, err
61+
}

0 commit comments

Comments
 (0)