Skip to content

Commit

Permalink
Merge pull request #1 from rarimo/feature/update-1.0.8
Browse files Browse the repository at this point in the history
Prepare bdjuno for reindexing and  rarimo-core v1.1.0 update
  • Loading branch information
napalmpapalam authored Nov 27, 2023
2 parents 165aea1 + e111245 commit d713a05
Show file tree
Hide file tree
Showing 29 changed files with 739 additions and 259 deletions.
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Changelog

All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning].

## [Unreleased]
### Added
- `MsgCreateIdentityGISTTransferOp`, `MsgCreateIdentityStateTransferOp` messages handling
- `tx` and `height` columns for the `confirmation` and `vote` tables
- `identity_gist_transfer` and `identity_state_transfer` tables to store new identity transfer types
- Hasura migrations
- `contract_update` entity relation to the `network`
- `fee_token_management` entity relation to the `network`
- `identity_default_transfer` entity relation to the `network`
- `oracle` entity relation to the `network`
- `confirmation` entity relation to the `transaction` and `block`
- `vote` entity relation to the `transaction` and `block`
- `multisig_proposal_vote` entity relation to the `block`
- `operation` entity relation to the `identity_gist_transfer` and `identity_state_transfer`

### Changed
- `rarimo-core` dependency updated to `v1.1.0`
- `tokenmanager_params` table replaced with `network` table

## [v1.0.3] - 2023-11-03
### Added
- MsgExec support for modules `auth`, `distribution`, `feegrant`, `gov`, `staking`

## [v1.0.2] - 2023-10-24
### Under the hood changes
- Migrated from GitLab to GitHub

### Under the hood changes

- Initiated project

[Unreleased]: https://github.com/rarimo/bdjuno/compare/v1.0.3...HEAD
[v1.0.3]: https://github.com/rarimo/bdjuno/compare/v1.0.2...v1.0.3
[v1.0.2]: https://github.com/rarimo/bdjuno/releases/tag/v1.0.2
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM golang:1.20-alpine as buildbase

WORKDIR /go/src/github.com/rarimo/bdjuno
RUN apk add build-base
COPY vendor .
COPY . .
ENV GO111MODULE="on"
ENV CGO_ENABLED=1
Expand Down
85 changes: 77 additions & 8 deletions database/rarimocore.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (db *Db) SaveIdentityDefaultTransfers(transfers []types.IdentityDefaultTran
var params []interface{}

for i, transfer := range transfers {
vi := i * 17
vi := i * 14
query += fmt.Sprintf(
"($%d, $%d, $%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, vi+13, vi+14,
Expand Down Expand Up @@ -383,6 +383,73 @@ func (db *Db) SaveIdentityDefaultTransfers(transfers []types.IdentityDefaultTran
return nil
}

func (db *Db) SaveIdentityGISTTransfers(transfers []types.IdentityGISTTransfer) (err error) {
if len(transfers) == 0 {
return nil
}

query := `INSERT INTO identity_gist_transfer (operation_index, contract, chain, gisthash, gistcreated_at_timestamp, gistcreated_at_block, replaced_gist_hash) VALUES`
var params []interface{}

for i, transfer := range transfers {
vi := i * 7
query += fmt.Sprintf("($%d, $%d, $%d, $%d, $%d, $%d, $%d),", vi+1, vi+2, vi+3, vi+4, vi+5, vi+6, vi+7)

params = append(params,
transfer.OperationIndex,
transfer.Contract,
transfer.Chain,
transfer.GISTHash,
transfer.GISTCreatedAtTimestamp,
transfer.GISTCreatedAtBlock,
transfer.ReplacedGISTHash,
)
}

query = strings.TrimSuffix(query, ",") // Remove trailing ","
query += " ON CONFLICT DO NOTHING"
_, err = db.SQL.Exec(query, params...)
if err != nil {
return fmt.Errorf("error while storing identity gist transfers: %s", err)
}

return nil
}

func (db *Db) SaveIdentityStateTransfers(transfers []types.IdentityStateTransfer) (err error) {
if len(transfers) == 0 {
return nil
}

query := `INSERT INTO identity_state_transfer (operation_index, contract, chain, id, state_hash, state_created_at_timestamp, state_created_at_block, replaced_state_hash) VALUES`
var params []interface{}

for i, transfer := range transfers {
vi := i * 8
query += fmt.Sprintf("($%d, $%d, $%d, $%d, $%d, $%d, $%d, $%d),", vi+1, vi+2, vi+3, vi+4, vi+5, vi+6, vi+7, vi+8)

params = append(params,
transfer.OperationIndex,
transfer.Contract,
transfer.Chain,
transfer.Id,
transfer.StateHash,
transfer.StateCreatedAtTimestamp,
transfer.StateCreatedAtBlock,
transfer.ReplacedStateHash,
)
}

query = strings.TrimSuffix(query, ",") // Remove trailing ","
query += " ON CONFLICT DO NOTHING"
_, err = db.SQL.Exec(query, params...)
if err != nil {
return fmt.Errorf("error while storing identity state transfers: %s", err)
}

return nil
}

func (db *Db) UpdateChangeParties(changeParties types.ChangeParties) (err error) {
query := `UPDATE change_parties SET parties = $1, new_public_key = $2, signature = $3 WHERE operation_index = $4`
_, err = db.SQL.Exec(query,
Expand All @@ -403,18 +470,20 @@ func (db *Db) SaveConfirmations(confirmations []types.Confirmation) (err error)
return nil
}

confirmationsQuery := `INSERT INTO confirmation (root, indexes, signature_ecdsa, creator) VALUES`
confirmationsQuery := `INSERT INTO confirmation (root, indexes, signature_ecdsa, creator, tx, height) VALUES`
var confirmationsParams []interface{}

for i, confirmation := range confirmations {
vi := i * 4
confirmationsQuery += fmt.Sprintf("($%d, $%d, $%d, $%d),", vi+1, vi+2, vi+3, vi+4)
vi := i * 6
confirmationsQuery += fmt.Sprintf("($%d, $%d, $%d, $%d, $%d, $%d),", vi+1, vi+2, vi+3, vi+4, vi+5, vi+6)

confirmationsParams = append(confirmationsParams,
confirmation.Root,
pq.StringArray(confirmation.Indexes),
confirmation.SignatureECDSA,
confirmation.Creator,
confirmation.Tx,
confirmation.Height,
)
}

Expand All @@ -433,13 +502,13 @@ func (db *Db) SaveRarimoCoreVotes(votes []types.RarimoCoreVote) (err error) {
return nil
}

query := `INSERT INTO vote (operation, validator, vote) VALUES `
query := `INSERT INTO vote (operation, validator, vote, tx, height) VALUES `
var queryParams []interface{}

for i, vote := range votes {
vi := i * 3
query += fmt.Sprintf("($%d, $%d, $%d),", vi+1, vi+2, vi+3)
queryParams = append(queryParams, vote.Operation, vote.Validator, vote.Vote)
vi := i * 5
query += fmt.Sprintf("($%d, $%d, $%d, $%d, $%d),", vi+1, vi+2, vi+3, vi+4, vi+5)
queryParams = append(queryParams, vote.Operation, vote.Validator, vote.Vote, vote.Tx, vote.Height)
}

query = strings.TrimSuffix(query, ",") // Remove trailing ","
Expand Down
21 changes: 9 additions & 12 deletions database/schema/12-tokenmanager.sql
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
-- +migrate Up
CREATE TABLE tokenmanager_params
CREATE TABLE network
(
one_row_id BOOLEAN NOT NULL DEFAULT TRUE PRIMARY KEY,
params JSONB NOT NULL,
height BIGINT NOT NULL,
CHECK (one_row_id)
name TEXT NOT NULL PRIMARY KEY,
type INT NOT NULL,
params JSONB NOT NULL
);
CREATE INDEX tokenmanager_params_height_index ON tokenmanager_params (height);

CREATE TABLE collection
(
index TEXT UNIQUE NOT NULL PRIMARY KEY,
meta JSONB NOT NULL,
data JSONB NOT NULL
index TEXT UNIQUE NOT NULL PRIMARY KEY,
meta JSONB NOT NULL,
data JSONB NOT NULL
);


CREATE TABLE collection_data
(
index_key TEXT NOT NULL PRIMARY KEY,
index_key TEXT NOT NULL PRIMARY KEY,
index JSONB NOT NULL,
collection TEXT REFERENCES collection (index),
token_type INT NOT NULL,
Expand Down Expand Up @@ -52,4 +49,4 @@ DROP TABLE on_chain_item;
DROP TABLE item;
DROP TABLE collection_data;
DROP TABLE collection;
DROP TABLE tokenmanager_params;
DROP TABLE network;
65 changes: 47 additions & 18 deletions database/schema/13-rarimocore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ CREATE TABLE confirmation
root TEXT NOT NULL PRIMARY KEY,
indexes TEXT[] NOT NULL,
signature_ecdsa TEXT NOT NULL,
creator TEXT NOT NULL REFERENCES account (address)
creator TEXT NOT NULL REFERENCES account (address),
height BIGINT NOT NULL,
tx TEXT
);

CREATE TABLE vote
(
operation TEXT NOT NULL PRIMARY KEY REFERENCES operation (index),
validator TEXT NOT NULL REFERENCES account (address),
vote INT NOT NULL
operation TEXT NOT NULL PRIMARY KEY REFERENCES operation (index),
validator TEXT NOT NULL REFERENCES account (address),
vote INT NOT NULL,
height BIGINT NOT NULL,
tx TEXT
);

CREATE TABLE contract_upgrade
Expand Down Expand Up @@ -92,23 +96,48 @@ CREATE TABLE fee_token_management

CREATE TABLE identity_default_transfer
(
operation_index TEXT NOT NULL PRIMARY KEY REFERENCES operation (index),
contract TEXT NOT NULL,
chain TEXT NOT NULL,
gisthash TEXT NOT NULL,
id TEXT NOT NULL,
state_hash TEXT NOT NULL,
state_created_at_timestamp TEXT NOT NULL,
state_created_at_block TEXT NOT NULL,
state_replaced_by TEXT NOT NULL,
gistreplaced_by TEXT NOT NULL,
gistcreated_at_timestamp TEXT NOT NULL,
gistcreated_at_block TEXT NOT NULL,
replaced_state_hash TEXT NOT NULL,
replaced_gist_hash TEXT NOT NULL
operation_index TEXT NOT NULL PRIMARY KEY REFERENCES operation (index),
contract TEXT NOT NULL,
chain TEXT NOT NULL,
gisthash TEXT NOT NULL,
id TEXT NOT NULL,
state_hash TEXT NOT NULL,
state_created_at_timestamp TEXT NOT NULL,
state_created_at_block TEXT NOT NULL,
state_replaced_by TEXT NOT NULL,
gistreplaced_by TEXT NOT NULL,
gistcreated_at_timestamp TEXT NOT NULL,
gistcreated_at_block TEXT NOT NULL,
replaced_state_hash TEXT NOT NULL,
replaced_gist_hash TEXT NOT NULL
);

CREATE TABLE identity_gist_transfer
(
operation_index TEXT NOT NULL PRIMARY KEY REFERENCES operation (index),
contract TEXT NOT NULL,
chain TEXT NOT NULL,
gisthash TEXT NOT NULL,
gistcreated_at_timestamp TEXT NOT NULL,
gistcreated_at_block TEXT NOT NULL,
replaced_gist_hash TEXT NOT NULL
);

CREATE TABLE identity_state_transfer
(
operation_index TEXT NOT NULL PRIMARY KEY REFERENCES operation (index),
contract TEXT NOT NULL,
chain TEXT NOT NULL,
id TEXT NOT NULL,
state_hash TEXT NOT NULL,
state_created_at_timestamp TEXT NOT NULL,
state_created_at_block TEXT NOT NULL,
replaced_state_hash TEXT NOT NULL
);

-- +migrate Down
DROP TABLE identity_state_transfer;
DROP TABLE identity_gist_transfer;
DROP TABLE identity_default_transfer;
DROP TABLE fee_token_management;
DROP TABLE contract_upgrade;
Expand Down
50 changes: 32 additions & 18 deletions database/tokenmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,42 @@ import (
"strings"
)

// SaveTokenManagerParams saves the given x/tokenmanager parameters inside the database
func (db *Db) SaveTokenManagerParams(params *types.TokenManagerParams) (err error) {
paramsBz, err := json.Marshal(params.Params)
if err != nil {
return fmt.Errorf("error while marshaling tokenmanager params: %s", err)
// SaveNetworks saves the given x/tokenmanager network parameters inside the database
func (db *Db) SaveNetworks(networks []types.Network) (err error) {
if len(networks) == 0 {
return nil
}

stmt := `
INSERT INTO tokenmanager_params(params, height)
VALUES ($1, $2)
ON CONFLICT (one_row_id) DO UPDATE
SET params = excluded.params,
height = excluded.height
WHERE tokenmanager_params.height <= excluded.height
stmt := `INSERT INTO network (name, type, params) VALUES`
var params []interface{}

for i, network := range networks {
// Prepare the network query
vi := i * 3
stmt += fmt.Sprintf("($%d, $%d, $%d),", vi+1, vi+2, vi+3)

paramsBz, err := json.Marshal(network.Params)
if err != nil {
return fmt.Errorf("error while marshaling network params: %s", err)
}

params = append(
params,
network.Name,
network.Type,
string(paramsBz),
)
}

stmt = strings.TrimSuffix(stmt, ",") // Remove trailing ","
stmt += ` ON CONFLICT (name) DO UPDATE
SET params = excluded.params
WHERE network.name = excluded.name
`
_, err = db.SQL.Exec(
stmt,
string(paramsBz),
params.Height,
)

_, err = db.SQL.Exec(stmt, params...)
if err != nil {
return fmt.Errorf("error while storing tokenmanager params: %s", err)
return fmt.Errorf("error while storing networks: %s", err)
}

return nil
Expand Down
Loading

0 comments on commit d713a05

Please sign in to comment.