From 71ac9c720e328b63a5bdecb7fe05a23c9b72bccb Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Wed, 20 Sep 2023 10:49:37 +0300 Subject: [PATCH 1/7] update edit nft msg handler --- database/types/nft.go | 7 +++++++ modules/nft/handle_msg.go | 28 +++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 database/types/nft.go diff --git a/database/types/nft.go b/database/types/nft.go new file mode 100644 index 000000000..6aa3b474f --- /dev/null +++ b/database/types/nft.go @@ -0,0 +1,7 @@ +package types + +type EditNftQuery struct { + Name string `json:"name"` + Uri string `json:"uri"` + DataText string `json:"data_text"` +} diff --git a/modules/nft/handle_msg.go b/modules/nft/handle_msg.go index 756614159..02cdc0d19 100644 --- a/modules/nft/handle_msg.go +++ b/modules/nft/handle_msg.go @@ -8,6 +8,7 @@ import ( nftTypes "github.com/CudoVentures/cudos-node/x/nft/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/forbole/bdjuno/v4/database" + dbtypes "github.com/forbole/bdjuno/v4/database/types" utils "github.com/forbole/bdjuno/v4/utils" juno "github.com/forbole/juno/v5/types" "github.com/rs/zerolog/log" @@ -88,9 +89,34 @@ func (m *Module) handleMsgMintNFT(index int, tx *juno.Tx, msg *nftTypes.MsgMintN func (m *Module) handleMsgEditNFT(msg *nftTypes.MsgEditNFT) error { log.Debug().Str("module", "nft").Str("denomId", msg.DenomId).Str("tokenId", msg.Id).Msg("handling message edit nft") + nftID := msg.Id + denomID := msg.DenomId dataJSON, dataText := utils.GetData(msg.Data) + newNftData := dbtypes.EditNftQuery{ + Name: msg.Name, + Uri: msg.URI, + DataText: msg.Data, + } + + var currentNftData dbtypes.EditNftQuery + err := m.db.SQL.Select(¤tNftData, `SELECT name, uri, data_text FROM nft_nft WHERE id = $1 AND denom_id =$2`, nftID, denomID) + if err != nil { + return err + } + + if newNftData.Name == nftTypes.DoNotModify || newNftData.Name == currentNftData.Name { + newNftData.Name = currentNftData.Name + } + + if newNftData.Uri == nftTypes.DoNotModify || newNftData.Uri == currentNftData.Uri { + newNftData.Uri = currentNftData.Uri + } + + if newNftData.DataText == nftTypes.DoNotModify || newNftData.DataText == currentNftData.DataText { + dataJSON, dataText = utils.GetData(currentNftData.DataText) + } - return m.db.UpdateNFT(msg.Id, msg.DenomId, msg.Name, msg.URI, utils.SanitizeUTF8(dataJSON), dataText) + return m.db.UpdateNFT(nftID, denomID, newNftData.Name, newNftData.Uri, utils.SanitizeUTF8(dataJSON), dataText) } func (m *Module) handleMsgTransferNFT(tx *juno.Tx, msg *nftTypes.MsgTransferNft) error { From 7771f987bf082af5cb0ddb94d4b353262f58ad36 Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Wed, 20 Sep 2023 10:59:05 +0300 Subject: [PATCH 2/7] fix: Lint errors --- database/types/nft.go | 2 +- modules/nft/handle_msg.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/database/types/nft.go b/database/types/nft.go index 6aa3b474f..9f04d2834 100644 --- a/database/types/nft.go +++ b/database/types/nft.go @@ -2,6 +2,6 @@ package types type EditNftQuery struct { Name string `json:"name"` - Uri string `json:"uri"` + URI string `json:"uri"` DataText string `json:"data_text"` } diff --git a/modules/nft/handle_msg.go b/modules/nft/handle_msg.go index 02cdc0d19..fed1ce41e 100644 --- a/modules/nft/handle_msg.go +++ b/modules/nft/handle_msg.go @@ -94,7 +94,7 @@ func (m *Module) handleMsgEditNFT(msg *nftTypes.MsgEditNFT) error { dataJSON, dataText := utils.GetData(msg.Data) newNftData := dbtypes.EditNftQuery{ Name: msg.Name, - Uri: msg.URI, + URI: msg.URI, DataText: msg.Data, } @@ -108,15 +108,15 @@ func (m *Module) handleMsgEditNFT(msg *nftTypes.MsgEditNFT) error { newNftData.Name = currentNftData.Name } - if newNftData.Uri == nftTypes.DoNotModify || newNftData.Uri == currentNftData.Uri { - newNftData.Uri = currentNftData.Uri + if newNftData.URI == nftTypes.DoNotModify || newNftData.URI == currentNftData.URI { + newNftData.URI = currentNftData.URI } if newNftData.DataText == nftTypes.DoNotModify || newNftData.DataText == currentNftData.DataText { dataJSON, dataText = utils.GetData(currentNftData.DataText) } - return m.db.UpdateNFT(nftID, denomID, newNftData.Name, newNftData.Uri, utils.SanitizeUTF8(dataJSON), dataText) + return m.db.UpdateNFT(nftID, denomID, newNftData.Name, newNftData.URI, utils.SanitizeUTF8(dataJSON), dataText) } func (m *Module) handleMsgTransferNFT(tx *juno.Tx, msg *nftTypes.MsgTransferNft) error { From 9a549a36884dfeb7f26f656cee064ff4e1ec5c1c Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Wed, 20 Sep 2023 11:44:34 +0300 Subject: [PATCH 3/7] update: edit nft msg handler --- database/types/nft.go | 1 + modules/nft/handle_msg.go | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/database/types/nft.go b/database/types/nft.go index 9f04d2834..57c29def7 100644 --- a/database/types/nft.go +++ b/database/types/nft.go @@ -4,4 +4,5 @@ type EditNftQuery struct { Name string `json:"name"` URI string `json:"uri"` DataText string `json:"data_text"` + DataJSON string `json:"data_json"` } diff --git a/modules/nft/handle_msg.go b/modules/nft/handle_msg.go index fed1ce41e..ff0dce514 100644 --- a/modules/nft/handle_msg.go +++ b/modules/nft/handle_msg.go @@ -87,36 +87,40 @@ func (m *Module) handleMsgMintNFT(index int, tx *juno.Tx, msg *nftTypes.MsgMintN } func (m *Module) handleMsgEditNFT(msg *nftTypes.MsgEditNFT) error { - log.Debug().Str("module", "nft").Str("denomId", msg.DenomId).Str("tokenId", msg.Id).Msg("handling message edit nft") - nftID := msg.Id denomID := msg.DenomId - dataJSON, dataText := utils.GetData(msg.Data) + log.Debug().Str("module", "nft").Str("denomId", denomID).Str("tokenId", nftID).Msg("handling message edit nft") + + // Parse newly proposed changes + newDataJSON, newDataText := utils.GetData(msg.Data) newNftData := dbtypes.EditNftQuery{ Name: msg.Name, URI: msg.URI, - DataText: msg.Data, + DataText: newDataText, + DataJSON: newDataJSON, } + // Getting previous DB records var currentNftData dbtypes.EditNftQuery - err := m.db.SQL.Select(¤tNftData, `SELECT name, uri, data_text FROM nft_nft WHERE id = $1 AND denom_id =$2`, nftID, denomID) + err := m.db.SQL.Select(¤tNftData, `SELECT name, uri, data_text, data_json FROM nft_nft WHERE id = $1 AND denom_id = $2`, nftID, denomID) if err != nil { return err } - if newNftData.Name == nftTypes.DoNotModify || newNftData.Name == currentNftData.Name { + if newNftData.Name == nftTypes.DoNotModify { newNftData.Name = currentNftData.Name } - if newNftData.URI == nftTypes.DoNotModify || newNftData.URI == currentNftData.URI { + if newNftData.URI == nftTypes.DoNotModify { newNftData.URI = currentNftData.URI } - if newNftData.DataText == nftTypes.DoNotModify || newNftData.DataText == currentNftData.DataText { - dataJSON, dataText = utils.GetData(currentNftData.DataText) + if msg.Data == nftTypes.DoNotModify { + newNftData.DataText = currentNftData.DataText + newNftData.DataJSON = currentNftData.DataJSON } - return m.db.UpdateNFT(nftID, denomID, newNftData.Name, newNftData.URI, utils.SanitizeUTF8(dataJSON), dataText) + return m.db.UpdateNFT(nftID, denomID, newNftData.Name, newNftData.URI, newNftData.DataJSON, newNftData.DataText) } func (m *Module) handleMsgTransferNFT(tx *juno.Tx, msg *nftTypes.MsgTransferNft) error { From 9cfa93b83082dbaa7086b70608673c5ecfa60fa2 Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Wed, 20 Sep 2023 12:09:10 +0300 Subject: [PATCH 4/7] update: edit nft msg handler --- modules/nft/handle_msg.go | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/modules/nft/handle_msg.go b/modules/nft/handle_msg.go index ff0dce514..46ad2fcaa 100644 --- a/modules/nft/handle_msg.go +++ b/modules/nft/handle_msg.go @@ -91,36 +91,27 @@ func (m *Module) handleMsgEditNFT(msg *nftTypes.MsgEditNFT) error { denomID := msg.DenomId log.Debug().Str("module", "nft").Str("denomId", denomID).Str("tokenId", nftID).Msg("handling message edit nft") - // Parse newly proposed changes - newDataJSON, newDataText := utils.GetData(msg.Data) - newNftData := dbtypes.EditNftQuery{ - Name: msg.Name, - URI: msg.URI, - DataText: newDataText, - DataJSON: newDataJSON, - } - - // Getting previous DB records - var currentNftData dbtypes.EditNftQuery - err := m.db.SQL.Select(¤tNftData, `SELECT name, uri, data_text, data_json FROM nft_nft WHERE id = $1 AND denom_id = $2`, nftID, denomID) + var nftData dbtypes.EditNftQuery + err := m.db.SQL.Select(&nftData, `SELECT name, uri, data_text, data_json FROM nft_nft WHERE id = $1 AND denom_id = $2`, nftID, denomID) if err != nil { return err } - if newNftData.Name == nftTypes.DoNotModify { - newNftData.Name = currentNftData.Name + if msg.Data != nftTypes.DoNotModify { + dataJSON, dataText := utils.GetData(msg.Data) + nftData.DataJSON = dataJSON + nftData.DataText = dataText } - if newNftData.URI == nftTypes.DoNotModify { - newNftData.URI = currentNftData.URI + if msg.URI != nftTypes.DoNotModify { + nftData.URI = msg.URI } - if msg.Data == nftTypes.DoNotModify { - newNftData.DataText = currentNftData.DataText - newNftData.DataJSON = currentNftData.DataJSON + if msg.Name != nftTypes.DoNotModify { + nftData.Name = msg.Name } - return m.db.UpdateNFT(nftID, denomID, newNftData.Name, newNftData.URI, newNftData.DataJSON, newNftData.DataText) + return m.db.UpdateNFT(nftID, denomID, nftData.Name, nftData.URI, nftData.DataJSON, nftData.DataText) } func (m *Module) handleMsgTransferNFT(tx *juno.Tx, msg *nftTypes.MsgTransferNft) error { From ee6de232ec70193b39d164e0544c1c9b121b5bf8 Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Wed, 20 Sep 2023 13:57:25 +0300 Subject: [PATCH 5/7] update: simplify and separate concerns of edit nft --- database/nft.go | 14 +++++++++++++- database/types/nft.go | 20 +++++++++++++++----- modules/nft/handle_msg.go | 20 +++++++++----------- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/database/nft.go b/database/nft.go index f2d71436b..d10c5a8e5 100644 --- a/database/nft.go +++ b/database/nft.go @@ -1,6 +1,9 @@ package database -import "github.com/forbole/bdjuno/v4/database/utils" +import ( + dbtypes "github.com/forbole/bdjuno/v4/database/types" + "github.com/forbole/bdjuno/v4/database/utils" +) func (db *Db) SaveDenom(txHash, denomID, name, schema, symbol, owner, contractAddressSigner, traits, minter, description, dataText, dataJSON string) error { _, err := db.SQL.Exec(`INSERT INTO nft_denom (transaction_hash, id, name, schema, symbol, owner, contract_address_signer, @@ -42,3 +45,12 @@ func (tx *DbTx) UpdateNFTHistory(txHash string, tokenID uint64, denomID, from, t txHash, tokenID, denomID, from, to, timestamp, utils.FormatUniqID(tokenID, denomID)) return err } + +func (db *Db) GetNftFromDB(nftID, denomID string) (dbtypes.NftFromDB, error) { + var nft dbtypes.NftFromDB + err := db.Sqlx.Select(&nft, `SELECT * FROM nft_nft WHERE id = $1 AND denom_id = $2`, nftID, denomID) + if err != nil { + return nft, err + } + return nft, nil +} diff --git a/database/types/nft.go b/database/types/nft.go index 57c29def7..68f29a173 100644 --- a/database/types/nft.go +++ b/database/types/nft.go @@ -1,8 +1,18 @@ package types -type EditNftQuery struct { - Name string `json:"name"` - URI string `json:"uri"` - DataText string `json:"data_text"` - DataJSON string `json:"data_json"` +import "database/sql" + +type NftFromDB struct { + TransactionHash string `json:"transaction_hash"` + ID uint64 `json:"id"` + DenomID string `json:"denom_id"` + Name string `json:"name"` + URI string `json:"uri"` + DataJSON string `json:"data_json"` + DataText string `json:"data_text"` + Owner string `json:"owner"` + Sender string `json:"sender"` + ContractAddressSigner string `json:"contract_address_signer"` + Burned bool `json:"burned"` + UniqID sql.NullInt64 `json:"uniq_id"` } diff --git a/modules/nft/handle_msg.go b/modules/nft/handle_msg.go index 46ad2fcaa..f3d17ff85 100644 --- a/modules/nft/handle_msg.go +++ b/modules/nft/handle_msg.go @@ -8,7 +8,6 @@ import ( nftTypes "github.com/CudoVentures/cudos-node/x/nft/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/forbole/bdjuno/v4/database" - dbtypes "github.com/forbole/bdjuno/v4/database/types" utils "github.com/forbole/bdjuno/v4/utils" juno "github.com/forbole/juno/v5/types" "github.com/rs/zerolog/log" @@ -91,27 +90,26 @@ func (m *Module) handleMsgEditNFT(msg *nftTypes.MsgEditNFT) error { denomID := msg.DenomId log.Debug().Str("module", "nft").Str("denomId", denomID).Str("tokenId", nftID).Msg("handling message edit nft") - var nftData dbtypes.EditNftQuery - err := m.db.SQL.Select(&nftData, `SELECT name, uri, data_text, data_json FROM nft_nft WHERE id = $1 AND denom_id = $2`, nftID, denomID) + nft, err := m.db.GetNftFromDB(nftID, denomID) if err != nil { return err } - if msg.Data != nftTypes.DoNotModify { + if nftTypes.Modified(msg.Data) { dataJSON, dataText := utils.GetData(msg.Data) - nftData.DataJSON = dataJSON - nftData.DataText = dataText + nft.DataJSON = dataJSON + nft.DataText = dataText } - if msg.URI != nftTypes.DoNotModify { - nftData.URI = msg.URI + if nftTypes.Modified(msg.URI) { + nft.URI = msg.URI } - if msg.Name != nftTypes.DoNotModify { - nftData.Name = msg.Name + if nftTypes.Modified(msg.Name) { + nft.Name = msg.Name } - return m.db.UpdateNFT(nftID, denomID, nftData.Name, nftData.URI, nftData.DataJSON, nftData.DataText) + return m.db.UpdateNFT(nftID, denomID, nft.Name, nft.URI, nft.DataJSON, nft.DataText) } func (m *Module) handleMsgTransferNFT(tx *juno.Tx, msg *nftTypes.MsgTransferNft) error { From 89ca9dfc9ea5564dccfe925be5a4169bf70ec8a5 Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Wed, 20 Sep 2023 15:00:38 +0300 Subject: [PATCH 6/7] update: DB NFT query change - Select to QueryRow --- database/nft.go | 18 ++++++++++++++++-- database/types/nft.go | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/database/nft.go b/database/nft.go index d10c5a8e5..2a21a3620 100644 --- a/database/nft.go +++ b/database/nft.go @@ -48,9 +48,23 @@ func (tx *DbTx) UpdateNFTHistory(txHash string, tokenID uint64, denomID, from, t func (db *Db) GetNftFromDB(nftID, denomID string) (dbtypes.NftFromDB, error) { var nft dbtypes.NftFromDB - err := db.Sqlx.Select(&nft, `SELECT * FROM nft_nft WHERE id = $1 AND denom_id = $2`, nftID, denomID) + err := db.Sqlx.QueryRow(`SELECT * FROM nft_nft WHERE id = $1 AND denom_id = $2`, nftID, denomID).Scan( + &nft.TransactionHash, + &nft.ID, + &nft.DenomID, + &nft.Name, + &nft.URI, + &nft.DataJSON, + &nft.DataText, + &nft.Owner, + &nft.Sender, + &nft.ContractAddressSigner, + &nft.Burned, + &nft.UniqID, + &nft.PartionID, + ) if err != nil { - return nft, err + return dbtypes.NftFromDB{}, err } return nft, nil } diff --git a/database/types/nft.go b/database/types/nft.go index 68f29a173..3bb9fc8de 100644 --- a/database/types/nft.go +++ b/database/types/nft.go @@ -14,5 +14,6 @@ type NftFromDB struct { Sender string `json:"sender"` ContractAddressSigner string `json:"contract_address_signer"` Burned bool `json:"burned"` - UniqID sql.NullInt64 `json:"uniq_id"` + UniqID string `json:"uniq_id"` + PartionID sql.NullInt64 `json:"partition_id"` } From 10d913a94527a6dbe0bd0346d5a69a7cd3877355 Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Wed, 20 Sep 2023 15:04:00 +0300 Subject: [PATCH 7/7] add: test config --- .../bdjuno/config.yaml | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 sample_configs/integration-tests-config/bdjuno/config.yaml diff --git a/sample_configs/integration-tests-config/bdjuno/config.yaml b/sample_configs/integration-tests-config/bdjuno/config.yaml new file mode 100755 index 000000000..873f77227 --- /dev/null +++ b/sample_configs/integration-tests-config/bdjuno/config.yaml @@ -0,0 +1,75 @@ +chain: + bech32_prefix: cudos + modules: + - modules + - messages + - auth + - bank + - consensus + - gov + - slashing + - staking + - pricefeed + - distribution + - cosmwasm + - gravity + - cudomint + - nft + - marketplace + - group +node: + type: remote + config: + rpc: + client_name: cudos-network + address: http://localhost:26657 + max_connections: 20 + grpc: + address: http://localhost:9090 + insecure: true +parsing: + workers: 1 + listen_new_blocks: true + parse_old_blocks: true + parse_genesis: true + start_height: 1 + fast_sync: false # when fast sync is set to true, ignores all previous block + genesis_file_path: /tmp/cudos-test-data/config/genesis.json +database: + url: postgres://postgres:12345@localhost:6666/bdjuno_test_db?sslmode=disable&search_path=public + name: bdjuno_test_db + host: localhost + port: 6666 + user: postgres + password: 12345 + schema: public + max_open_connections: 10 + max_idle_connections: 10 + partition_size: 100000 + partition_batch: 1000 +logging: + level: debug + format: text +telemetry: + port: 5000 +pricefeed: + tokens: + - name: Cudos + units: + - denom: cudos + exponent: 0 + price_id: cudos +distribution: + rewards_frequency: 1000 +workers: + - name: fix_blocks_worker + interval: 60m + - name: migrate_nfts_worker + interval: 1m + - name: blocks_monitoring_worker + interval: 30s +cudomint: + stats_service_url: http://127.0.0.1:3001 +crypto-compare: + crypto_compare_prod_api_key: "" + crypto_compare_free_api_key: ""