-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from hyle-team/feature/nft-module
Feature/nft module
- Loading branch information
Showing
8,278 changed files
with
2,434 additions
and
2,288,227 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
.idea/ | ||
build/ | ||
build/ | ||
|
||
config.local.yaml | ||
# Coverage | ||
coverage.* | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package migrate_db | ||
|
||
import ( | ||
"database/sql" | ||
"github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/forbole/bdjuno/v4/database" | ||
parsecmdtypes "github.com/forbole/juno/v4/cmd/parse/types" | ||
"github.com/forbole/juno/v4/logging" | ||
"github.com/forbole/juno/v4/types/config" | ||
migrate "github.com/rubenv/sql-migrate" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var migrations = &migrate.EmbedFileSystemMigrationSource{ | ||
FileSystem: database.Migrations, | ||
Root: "schema", | ||
} | ||
|
||
func NewMigrateDBCmd(parseCfg *parsecmdtypes.Config) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "migrate-db", | ||
Short: "Migrate the database schema", | ||
PersistentPreRunE: runPersistentPreRuns(parsecmdtypes.ReadConfigPreRunE(parseCfg)), | ||
} | ||
|
||
cmd.AddCommand( | ||
&cobra.Command{ | ||
Use: "up", | ||
Short: "migrate db up", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
context, err := parsecmdtypes.GetParserContext(config.Cfg, parseCfg) | ||
if err != nil { | ||
return err | ||
} | ||
db := database.Cast(context.Database) | ||
return migrateUp(db.SQL.DB, context.Logger) | ||
}, | ||
}, | ||
) | ||
|
||
cmd.AddCommand( | ||
&cobra.Command{ | ||
Use: "down", | ||
Short: "migrate db down", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
context, err := parsecmdtypes.GetParserContext(config.Cfg, parseCfg) | ||
if err != nil { | ||
return err | ||
} | ||
db := database.Cast(context.Database) | ||
return migrateDown(db.SQL.DB, context.Logger) | ||
}, | ||
}, | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
func migrateUp(rawDB *sql.DB, log logging.Logger) error { | ||
applied, err := migrate.Exec(rawDB, "postgres", migrations, migrate.Up) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to apply migrations") | ||
} | ||
log.Info("migrations applied", map[string]interface{}{ | ||
"applied": applied, | ||
}) | ||
return nil | ||
} | ||
|
||
func migrateDown(rawDB *sql.DB, log logging.Logger) error { | ||
applied, err := migrate.Exec(rawDB, "postgres", migrations, migrate.Down) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to apply migrations") | ||
} | ||
log.Info("migrations applied", map[string]interface{}{ | ||
"applied": applied, | ||
}) | ||
return nil | ||
} | ||
|
||
func runPersistentPreRuns(preRun func(_ *cobra.Command, _ []string) error) func(_ *cobra.Command, _ []string) error { | ||
return func(cmd *cobra.Command, args []string) error { | ||
if root := cmd.Root(); root != nil { | ||
if root.PersistentPreRunE != nil { | ||
err := root.PersistentPreRunE(root, args) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return preRun(cmd, args) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
actions: | ||
port: 8000 | ||
chain: | ||
bech32_prefix: bridge | ||
modules: | ||
- modules | ||
- messages | ||
- auth | ||
- bank | ||
- consensus | ||
- feegrant | ||
- gov | ||
- mint | ||
- slashing | ||
- staking | ||
- distribution | ||
- actions | ||
- upgrade | ||
- nft | ||
- accumulator | ||
- bridge | ||
database: | ||
host: scan-pg | ||
max_idle_connections: 10 | ||
max_open_connections: 20 | ||
name: scan | ||
partition_batch: 1000 | ||
partition_size: 100000 | ||
password: scan | ||
port: 5432 | ||
url: postgres://postgres:postgres@localhost:5432/juno?sslmode=disable | ||
user: scan | ||
logging: | ||
format: text | ||
level: debug | ||
node: | ||
config: | ||
grpc: | ||
address: http://localhost:9090 | ||
insecure: true | ||
rpc: | ||
address: http://localhost:26657 | ||
client_name: juno | ||
max_connections: 10 | ||
type: remote | ||
parsing: | ||
average_block_time: 5s | ||
genesis_file_path: genesis.json | ||
listen_new_blocks: true | ||
parse_genesis: false | ||
parse_old_blocks: false | ||
start_height: 1 | ||
workers: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package database | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
dbtypes "github.com/forbole/bdjuno/v4/database/types" | ||
"github.com/forbole/bdjuno/v4/types" | ||
"github.com/lib/pq" | ||
) | ||
|
||
// SaveAdmin allows to save new Admin | ||
func (db *Db) SaveAdmin(address string, vestingCount, lastVestingTime, vestingPeriod int64, rewardPerPeriod sdk.Coin, denom string) error { | ||
query := ` | ||
INSERT INTO admins_vesting(address, vesting_period, reward_per_period, last_vesting_time, vesting_counter, denom) | ||
VALUES ($1, $2, $3, $4, $5, $6) | ||
ON CONFLICT (address) DO UPDATE | ||
SET vesting_counter = excluded.vesting_counter, | ||
last_vesting_time = excluded.last_vesting_time | ||
WHERE admins_vesting.address <= excluded.address | ||
` | ||
_, err := db.SQL.Exec(query, address, vestingPeriod, pq.Array(dbtypes.NewDbCoins(sdk.NewCoins(rewardPerPeriod))), lastVestingTime, vestingCount, denom) | ||
if err != nil { | ||
return fmt.Errorf("error while storing admin vesting info: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------------- | ||
|
||
// SaveAccumulatorParams allows to store the given params inside the database | ||
func (db *Db) SaveAccumulatorParams(params *types.AccumulatorParams) error { | ||
paramsBz, err := json.Marshal(¶ms.Params) | ||
if err != nil { | ||
return fmt.Errorf("error while marshaling accumulator params: %s", err) | ||
} | ||
|
||
stmt := ` | ||
INSERT INTO accumulator_params (params, height) | ||
VALUES ($1, $2) | ||
ON CONFLICT (one_row_id) DO UPDATE | ||
SET params = excluded.params, | ||
height = excluded.height | ||
WHERE accumulator_params.height <= excluded.height | ||
` | ||
|
||
_, err = db.SQL.Exec(stmt, string(paramsBz), params.Height) | ||
if err != nil { | ||
return fmt.Errorf("error while storing accumulator params: %s", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// GetAdmins returns all the admins that are currently stored inside the database. | ||
func (db *Db) GetAdmins() ([]dbtypes.AdminVestingRow, error) { | ||
var rows []dbtypes.AdminVestingRow | ||
err := db.Sqlx.Select(&rows, `SELECT * FROM admins_vesting WHERE to_timestamp(last_vesting_time) + INTERVAL '1 second' * last_vesting_time < NOW();`) | ||
return rows, err | ||
} |
Oops, something went wrong.