Skip to content

build(deps): bump github.com/lib/pq from 1.10.6 to 1.10.7 #6

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

Open
wants to merge 3 commits into
base: chains/nyx/mainnet
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea/
build/
pgdata

# Configuration
*.toml
Expand Down
4 changes: 2 additions & 2 deletions cmd/bdjuno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/forbole/bdjuno/v3/database"
"github.com/forbole/bdjuno/v3/modules"

cmdxapp "github.com/comdex-official/comdex/app"
wasmapp "github.com/CosmWasm/wasmd/app"
gaiaapp "github.com/cosmos/gaia/v6/app"
)

Expand Down Expand Up @@ -57,7 +57,7 @@ func main() {
func getBasicManagers() []module.BasicManager {
return []module.BasicManager{
gaiaapp.ModuleBasics,
cmdxapp.ModuleBasics,
wasmapp.ModuleBasics,
}
}

Expand Down
163 changes: 163 additions & 0 deletions database/nym_mixnet_v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package database

import (
"encoding/json"
"fmt"
dbtypes "github.com/forbole/bdjuno/v3/database/types"
"github.com/lib/pq"
"github.com/shopspring/decimal"

cosmosTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/forbole/bdjuno/v3/types"
juno "github.com/forbole/juno/v3/types"
)

// EnsureExistsNymMixnetV1Mixnode ensures a mixnode is in the store
func (db *Db) EnsureExistsNymMixnetV1Mixnode(mixnode types.MixnodeV1) error {
stmt := `
INSERT INTO nyx_nym_mixnet_v1_mixnode(identity_key, is_bonded, last_mixnet_status)
VALUES ($1, $2, $3)
ON CONFLICT DO NOTHING
`
_, err := db.Sql.Exec(stmt,
mixnode.IdentityKey, mixnode.IsBonded, mixnode.LastMixnetStatus.String(),
)
if err != nil {
return fmt.Errorf("error while ensuring Nym mixnode exists: %s", err)
}

return nil
}

// SaveNymMixnetV1Mixnode allows to create or update a mixnode
func (db *Db) SaveNymMixnetV1Mixnode(mixnode types.MixnodeV1) error {
stmt := `
INSERT INTO nyx_nym_mixnet_v1_mixnode(identity_key, is_bonded, last_mixnet_status)
VALUES ($1, $2, $3)
ON CONFLICT (identity_key) DO UPDATE
SET identity_key = excluded.identity_key,
is_bonded = excluded.is_bonded,
last_mixnet_status = excluded.last_mixnet_status
`
_, err := db.Sql.Exec(stmt,
mixnode.IdentityKey, mixnode.IsBonded, mixnode.LastMixnetStatus.String(),
)
if err != nil {
return fmt.Errorf("error while saving Nym mixnode: %s", err)
}

return nil
}

// SaveNymMixnetV1Gateway allows to store the wasm params
func (db *Db) SaveNymMixnetV1Gateway(gateway types.GatewayV1) error {
stmt := `
INSERT INTO nyx_nym_mixnet_v1_gateway(identity_key, is_bonded)
VALUES ($1, $2)
ON CONFLICT (identity_key) DO UPDATE
SET identity_key = excluded.identity_key,
is_bonded = excluded.is_bonded,
`
_, err := db.Sql.Exec(stmt,
gateway.IdentityKey, gateway.IsBonded,
)
if err != nil {
return fmt.Errorf("error while saving Nym gateway: %s", err)
}

return nil
}

// SaveNymMixnetV1MixnodeEvent allows to store the wasm contract events
func (db *Db) SaveNymMixnetV1MixnodeEvent(eventKind string, actor string, proxy *string, identityKey string, amount *cosmosTypes.Coins, dataType string, dataJson string, executeContract types.WasmExecuteContract, tx *juno.Tx) error {
stmt := `
INSERT INTO nyx_nym_mixnet_v1_mixnode_events
(event_kind, actor, sender, proxy, identity_key, amount, fee, contract_address, event_type, attributes, executed_at, height, hash)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)`

var dbAmount interface{}
if amount != nil {
dbAmount = pq.Array(dbtypes.NewDbCoins(*amount))
}
fee := pq.Array(dbtypes.NewDbCoins(tx.GetFee()))

_, err := db.Sql.Exec(stmt,
eventKind, actor,
executeContract.Sender,
proxy,
identityKey,
dbAmount, fee,
executeContract.ContractAddress, dataType, dataJson,
executeContract.ExecutedAt, executeContract.Height, tx.TxHash)
if err != nil {
return fmt.Errorf("error while saving wasm execute contracts: %s", err)
}

return nil
}

// HasNymMixnetV1MixnodeRewardingEvent checks if a rewarding event has been saved
func (db *Db) HasNymMixnetV1MixnodeRewardingEvent(identityKey string, tx *juno.Tx) (bool, error) {
stmt := `
SELECT COUNT(height) FROM nyx_nym_mixnet_v1_mixnode_reward WHERE identity_key = $1 AND height = $2 AND hash = $3
`
var count int
err := db.Sql.QueryRow(stmt, identityKey, tx.Height, tx.TxHash).Scan(&count)

return count > 0, err
}

// SaveNymMixnetV1MixnodeRewardingEvent allows to store the mixnode rewarding events
func (db *Db) SaveNymMixnetV1MixnodeRewardingEvent(identityKey string, totalNodeReward cosmosTypes.Coins, totalDelegations cosmosTypes.Coins, operatorReward cosmosTypes.Coins, unitDelegatorReward decimal.Decimal, apy float64, stakingSupply cosmosTypes.Coins, profitMarginPercentage int, event cosmosTypes.StringEvent, executeContract types.WasmExecuteContract, tx *juno.Tx) error {
stmt := `
INSERT INTO nyx_nym_mixnet_v1_mixnode_reward
(sender, identity_key, total_node_reward, total_delegations, operator_reward, unit_delegator_reward, apy, staking_supply, profit_margin_percentage, contract_address, event_type, attributes, executed_at, height, hash)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
ON CONFLICT DO NOTHING`

var attr = make(map[string]interface{}) // could be `map[string]string` however leaving to handle objects as values
for _, entry := range event.Attributes {
attr[entry.Key] = entry.Value
}
bytes, _ := json.Marshal(attr)

dbTotalNodeReward := pq.Array(dbtypes.NewDbCoins(totalNodeReward))
dbTotalDelegations := pq.Array(dbtypes.NewDbCoins(totalDelegations))
dbOperatorReward := pq.Array(dbtypes.NewDbCoins(operatorReward))
dbStakingSupply := pq.Array(dbtypes.NewDbCoins(stakingSupply))

_, err := db.Sql.Exec(stmt,
executeContract.Sender,
identityKey,
dbTotalNodeReward,
dbTotalDelegations,
dbOperatorReward,
unitDelegatorReward.IntPart(),
apy,
dbStakingSupply,
profitMarginPercentage,
executeContract.ContractAddress, event.Type, string(bytes),
executeContract.ExecutedAt, executeContract.Height, tx.TxHash)
if err != nil {
return fmt.Errorf("error while saving wasm execute contracts: %s", err)
}

return nil
}

// SaveNymMixnetV1MixnodeStatus allows to store when the mixnet rewarded set changes
func (db *Db) SaveNymMixnetV1MixnodeStatus(identityKey string, status string, routingScore int, executeContract types.WasmExecuteContract, tx *juno.Tx) error {
stmt := `
INSERT INTO nyx_nym_mixnet_v1_mixnode_status
(mixnet_status, routing_score, identity_key, executed_at, height, hash )
VALUES ($1, $2, $3, $4, $5, $6)`

_, err := db.Sql.Exec(stmt,
status, routingScore, identityKey,
executeContract.ExecutedAt, executeContract.Height, tx.TxHash)
if err != nil {
return fmt.Errorf("error while saving wasm execute contracts: %s", err)
}

return nil
}
113 changes: 113 additions & 0 deletions database/nym_mixnet_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package database

import (
"encoding/json"
"fmt"
cosmosTypes "github.com/cosmos/cosmos-sdk/types"
dbtypes "github.com/forbole/bdjuno/v3/database/types"
"github.com/forbole/bdjuno/v3/types"
juno "github.com/forbole/juno/v3/types"
"github.com/lib/pq"
"github.com/shopspring/decimal"
)

// EnsureExistsNymMixnetV2Mixnode ensures a mixnode is in the store
func (db *Db) EnsureExistsNymMixnetV2Mixnode(mixnode types.MixnodeV2) error {
stmt := `
INSERT INTO nyx_nym_mixnet_v2_mixnode(mix_id, identity_key, is_bonded, last_mixnet_status)
VALUES ($1, $2, $3, $4)
ON CONFLICT DO NOTHING
`
_, err := db.Sql.Exec(stmt,
mixnode.MixId, mixnode.IdentityKey, mixnode.IsBonded, mixnode.LastMixnetStatus.String(),
)
if err != nil {
return fmt.Errorf("error while ensuring Nym mixnode exists: %s", err)
}

return nil
}

// SaveNymMixnetV2Mixnode allows to create or update a mixnode
func (db *Db) SaveNymMixnetV2Mixnode(mixnode types.MixnodeV2) error {
stmt := `
INSERT INTO nyx_nym_mixnet_v2_mixnode(mix_id, identity_key, is_bonded, last_mixnet_status)
VALUES ($1, $2, $3, $4)
ON CONFLICT (identity_key) DO UPDATE
SET mix_id = excluded.mix_id,
identity_key = excluded.identity_key,
is_bonded = excluded.is_bonded,
last_mixnet_status = excluded.last_mixnet_status
`
_, err := db.Sql.Exec(stmt,
mixnode.MixId, mixnode.IdentityKey, mixnode.IsBonded, mixnode.LastMixnetStatus.String(),
)
if err != nil {
return fmt.Errorf("error while saving Nym mixnode: %s", err)
}

return nil
}

// HasNymMixnetV2MixnodeRewardingEvent checks if a rewarding event has been saved
func (db *Db) HasNymMixnetV2MixnodeRewardingEvent(mixId uint32, tx *juno.Tx) (bool, error) {
stmt := `
SELECT COUNT(height) FROM nyx_nym_mixnet_v2_mixnode_reward WHERE mix_id = $1 AND height = $2 AND hash = $3
`
var count int
err := db.Sql.QueryRow(stmt, mixId, tx.Height, tx.TxHash).Scan(&count)

return count > 0, err
}

// SaveNymMixnetV2MixnodeRewardingEvent allows to store the mixnode rewarding events
func (db *Db) SaveNymMixnetV2MixnodeRewardingEvent(mixId uint32, operatorReward cosmosTypes.Coins, delegatesReward cosmosTypes.Coins, priorDelegates cosmosTypes.Coins, priorUnitDelegation decimal.Decimal, apy float64, event cosmosTypes.StringEvent, executeContract types.WasmExecuteContract, tx *juno.Tx) error {
stmt := `
INSERT INTO nyx_nym_mixnet_v2_mixnode_reward
(sender, mix_id, operator_reward, delegates_reward, prior_delegates, prior_unit_delegation, apy, contract_address, event_type, attributes, executed_at, height, hash)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
ON CONFLICT DO NOTHING`

var attr = make(map[string]interface{}) // could be `map[string]string` however leaving to handle objects as values
for _, entry := range event.Attributes {
attr[entry.Key] = entry.Value
}
bytes, _ := json.Marshal(attr)

dbOperatorReward := pq.Array(dbtypes.NewDbCoins(operatorReward))
dbDelegatesReward := pq.Array(dbtypes.NewDbCoins(delegatesReward))
dbPriorDelegates := pq.Array(dbtypes.NewDbCoins(priorDelegates))

_, err := db.Sql.Exec(stmt,
executeContract.Sender,
mixId,
dbOperatorReward,
dbDelegatesReward,
dbPriorDelegates,
priorUnitDelegation.IntPart(),
apy,
executeContract.ContractAddress, event.Type, string(bytes),
executeContract.ExecutedAt, executeContract.Height, tx.TxHash)
if err != nil {
return fmt.Errorf("error while saving wasm execute contracts: %s", err)
}

return nil
}

// SaveNymMixnetV2MixnodeStatus allows to store when the mixnet rewarded set changes
func (db *Db) SaveNymMixnetV2MixnodeStatus(mixId uint32, status string, routingScore int64, executeContract types.WasmExecuteContract, tx *juno.Tx) error {
stmt := `
INSERT INTO nyx_nym_mixnet_v2_mixnode_status
(mixnet_status, routing_score, mix_id, executed_at, height, hash )
VALUES ($1, $2, $3, $4, $5, $6)`

_, err := db.Sql.Exec(stmt,
status, routingScore, mixId,
executeContract.ExecutedAt, executeContract.Height, tx.TxHash)
if err != nil {
return fmt.Errorf("error while saving wasm execute contracts: %s", err)
}

return nil
}
3 changes: 2 additions & 1 deletion database/schema/12-wasm.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ CREATE TABLE wasm_execute_contract
funds COIN[] NOT NULL DEFAULT '{}',
data TEXT NULL,
executed_at TIMESTAMP NOT NULL,
height BIGINT NOT NULL
height BIGINT NOT NULL,
hash TEXT NOT NULL
);
CREATE INDEX execute_contract_height_index ON wasm_execute_contract (height);

13 changes: 13 additions & 0 deletions database/schema/13-wasm-events.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CREATE TABLE wasm_execute_contract_event
(
sender TEXT NOT NULL,
contract_address TEXT NOT NULL REFERENCES wasm_contract (contract_address),
event_type TEXT NULL,
attributes JSONB NOT NULL DEFAULT '{}'::JSONB,
executed_at TIMESTAMP NOT NULL,
height BIGINT NOT NULL REFERENCES block (height),
hash TEXT NOT NULL
);
CREATE INDEX wasm_execute_contract_event_height_index ON wasm_execute_contract_event (height);
CREATE INDEX wasm_execute_contract_event_hash_index ON wasm_execute_contract_event (hash);
CREATE INDEX wasm_execute_contract_event_event_type_index ON wasm_execute_contract_event (event_type);
23 changes: 23 additions & 0 deletions database/schema/14-nyx-nym-mixnet.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE TABLE nyx_nym_mixnet_v1_gateway
(
identity_key TEXT UNIQUE PRIMARY KEY,
is_bonded BOOLEAN NOT NULL
);

CREATE TABLE nyx_nym_mixnet_v1_gateway_events
(
-- values: bond, unbond
event_kind TEXT NOT NULL,
sender TEXT NOT NULL,
proxy TEXT NULL,
identity_key TEXT NOT NULL REFERENCES nyx_nym_mixnet_v1_gateway (identity_key),
amount COIN NULL,
fee COIN NULL,
contract_address TEXT NOT NULL REFERENCES wasm_contract (contract_address),
event_type TEXT NULL,
attributes JSONB NOT NULL DEFAULT '{}'::JSONB,
executed_at TIMESTAMP NOT NULL,
height BIGINT NOT NULL REFERENCES block (height),
hash TEXT NOT NULL
);
CREATE INDEX nyx_nym_mixnet_v1_gateway_events_height_index ON nyx_nym_mixnet_v1_gateway_events (height);
Loading