Skip to content
Merged
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
22 changes: 18 additions & 4 deletions database/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (db *Db) SaveProposals(proposals []types.Proposal) error {

proposalsQuery := `
INSERT INTO proposal(
id, title, description, metadata, content, proposer_address, status,
id, title, description, metadata, content, proposal_type, proposer_address, status,
submit_time, deposit_end_time, voting_start_time, voting_end_time
) VALUES`
var proposalsParams []interface{}
Expand All @@ -112,16 +112,29 @@ INSERT INTO proposal(

// Prepare the proposal query
vi := i * 11
proposalsQuery += fmt.Sprintf("($%d,$%d,$%d,$%d,$%d,$%d,$%d,$%d,$%d,$%d,$%d),",
vi+1, vi+2, vi+3, vi+4, vi+5, vi+6, vi+7, vi+8, vi+9, vi+10, vi+11)

proposalsQuery += fmt.Sprintf("($%d,$%d,$%d,$%d,$%d,$%d,$%d,$%d,$%d,$%d,$%d,$%d),",
vi+1, vi+2, vi+3, vi+4, vi+5, vi+6, vi+7, vi+8, vi+9, vi+10, vi+11, vi+12)
var proposalType string
var jsonMessages []string

for _, msg := range proposal.Messages {
contentBz, err := db.cdc.MarshalJSON(msg)
if err != nil {
return fmt.Errorf("error while marshalling proposal msg: %s", err)
}
jsonMessages = append(jsonMessages, string(contentBz))

if proposalType == "" {
var msgMap map[string]interface{}
if err := json.Unmarshal(contentBz, &msgMap); err != nil {
return fmt.Errorf("error unmarshalling proposal msg for type extraction: %s", err)
}
if t, ok := msgMap["@type"].(string); ok {
proposalType = t
} else {
proposalType = ""
}
}
}

proposalsParams = append(proposalsParams,
Expand All @@ -130,6 +143,7 @@ INSERT INTO proposal(
proposal.Summary,
proposal.Metadata,
fmt.Sprintf("[%s]", strings.Join(jsonMessages, ",")),
proposalType,
proposal.Proposer,
proposal.Status,
proposal.SubmitTime,
Expand Down
3 changes: 3 additions & 0 deletions database/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func (suite *DbTestSuite) TestBigDipperDb_SaveProposals() {
"Proposal Description 1",
"Proposal Metadata 1",
"[{\"@type\": \"/cosmos.gov.v1.MsgUpdateParams\", \"params\": {\"quorum\": \"0.5\", \"threshold\": \"0.3\", \"min_deposit\": [{\"denom\": \"uatom\", \"amount\": \"1000\"}], \"voting_period\": \"0.000300s\", \"burn_vote_veto\": false, \"veto_threshold\": \"0.15\", \"burn_vote_quorum\": false, \"min_deposit_ratio\": \"\", \"max_deposit_period\": \"300s\", \"expedited_threshold\": \"\", \"proposal_cancel_dest\": \"\", \"expedited_min_deposit\": [], \"proposal_cancel_ratio\": \"\", \"expedited_voting_period\": null, \"min_initial_deposit_ratio\": \"0\", \"burn_proposal_deposit_prevote\": false}, \"authority\": \"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn\"}]",
"cosmos.gov.v1.MsgUpdateParams",
time.Date(2020, 1, 1, 00, 00, 00, 000, time.UTC),
time.Date(2020, 1, 1, 01, 00, 00, 000, time.UTC),
testutils.NewTimePointer(time.Date(2020, 1, 1, 02, 00, 00, 000, time.UTC)),
Expand All @@ -200,6 +201,7 @@ func (suite *DbTestSuite) TestBigDipperDb_SaveProposals() {
"Proposal Description 2",
"Proposal Metadata 2",
"[]",
"cosmos.gov.v1.MsgUpdateParams",
time.Date(2020, 1, 2, 00, 00, 00, 000, time.UTC),
time.Date(2020, 1, 2, 01, 00, 00, 000, time.UTC),
testutils.NewTimePointer(time.Date(2020, 1, 2, 02, 00, 00, 000, time.UTC)),
Expand Down Expand Up @@ -362,6 +364,7 @@ func (suite *DbTestSuite) TestBigDipperDb_UpdateProposal() {
"Description of proposal 1",
"Metadata of proposal 1",
"[{\"@type\": \"/cosmos.gov.v1.MsgUpdateParams\", \"params\": {\"quorum\": \"0.5\", \"threshold\": \"0.3\", \"min_deposit\": [{\"denom\": \"uatom\", \"amount\": \"1000\"}], \"voting_period\": \"0.000300s\", \"burn_vote_veto\": false, \"veto_threshold\": \"0.15\", \"burn_vote_quorum\": false, \"min_deposit_ratio\": \"\", \"max_deposit_period\": \"300s\", \"expedited_threshold\": \"\", \"proposal_cancel_dest\": \"\", \"expedited_min_deposit\": [], \"proposal_cancel_ratio\": \"\", \"expedited_voting_period\": null, \"min_initial_deposit_ratio\": \"0\", \"burn_proposal_deposit_prevote\": false}, \"authority\": \"cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn\"}]",
"cosmos.gov.v1.MsgUpdateParams",
proposal.SubmitTime,
proposal.DepositEndTime,
timestamp1,
Expand Down
3 changes: 1 addition & 2 deletions database/migrate/v5/migrationv5.sql
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ DROP COLUMN tally_params;

/* Drop columns from table proposal */
ALTER TABLE proposal
DROP COLUMN proposal_route,
DROP COLUMN proposal_type;
DROP COLUMN proposal_route;

/* Add column to table proposal */
ALTER TABLE proposal
Expand Down
4 changes: 4 additions & 0 deletions database/types/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ProposalRow struct {
Description string `db:"description"`
Metadata string `db:"metadata"`
Content string `db:"content"`
ProposalType string `db:"proposal_type"`
ProposalID uint64 `db:"id"`
SubmitTime time.Time `db:"submit_time"`
DepositEndTime time.Time `db:"deposit_end_time"`
Expand All @@ -36,6 +37,7 @@ func NewProposalRow(
description string,
metadata string,
content string,
proposalType string,
submitTime time.Time,
depositEndTime time.Time,
votingStartTime *time.Time,
Expand All @@ -49,6 +51,7 @@ func NewProposalRow(
Description: description,
Metadata: metadata,
Content: content,
ProposalType: proposalType,
Status: status,
SubmitTime: submitTime,
DepositEndTime: depositEndTime,
Expand All @@ -64,6 +67,7 @@ func (w ProposalRow) Equals(v ProposalRow) bool {
w.Description == v.Description &&
w.Metadata == v.Metadata &&
w.Content == v.Content &&
w.ProposalType == v.ProposalType &&
w.ProposalID == v.ProposalID &&
w.SubmitTime.Equal(v.SubmitTime) &&
w.DepositEndTime.Equal(v.DepositEndTime) &&
Expand Down
10 changes: 4 additions & 6 deletions modules/mint/handle_periodic_operations.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package mint

import (
"github.com/forbole/callisto/v4/modules/utils"

"github.com/go-co-op/gocron"
"github.com/rs/zerolog/log"
)

// RegisterPeriodicOperations implements modules.PeriodicOperationsModule
func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error {
// Disabled due to a bug in the Cosmos SDK protobuf.
/*func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error {
log.Debug().Str("module", "mint").Msg("setting up periodic tasks")

// Setup a cron job to run every midnight
if _, err := scheduler.Every(1).Day().At("00:00").Do(func() {
if _, err := scheduler.Every(1).Minute().Do(func() {
utils.WatchMethod(m.UpdateInflation)
}); err != nil {
return err
}

return nil
}
}*/

// updateInflation fetches from the REST APIs the latest value for the
// inflation, and saves it inside the database.
Expand Down
5 changes: 2 additions & 3 deletions modules/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
)

var (
_ modules.Module = &Module{}
_ modules.GenesisModule = &Module{}
_ modules.PeriodicOperationsModule = &Module{}
_ modules.Module = &Module{}
_ modules.GenesisModule = &Module{}
)

// Module represent database/mint module
Expand Down
Loading