Skip to content
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

fix: update edit nft msg handler #103

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
28 changes: 27 additions & 1 deletion database/nft.go
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -42,3 +45,26 @@ 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.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 dbtypes.NftFromDB{}, err
}
return nft, nil
}
19 changes: 19 additions & 0 deletions database/types/nft.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package types

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 string `json:"uniq_id"`
PartionID sql.NullInt64 `json:"partition_id"`
}
25 changes: 22 additions & 3 deletions modules/nft/handle_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,30 @@ 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
log.Debug().Str("module", "nft").Str("denomId", denomID).Str("tokenId", nftID).Msg("handling message edit nft")

dataJSON, dataText := utils.GetData(msg.Data)
nft, err := m.db.GetNftFromDB(nftID, denomID)
if err != nil {
return err
}

if nftTypes.Modified(msg.Data) {
dataJSON, dataText := utils.GetData(msg.Data)
nft.DataJSON = dataJSON
nft.DataText = dataText
}

if nftTypes.Modified(msg.URI) {
nft.URI = msg.URI
}

if nftTypes.Modified(msg.Name) {
nft.Name = msg.Name
}

return m.db.UpdateNFT(msg.Id, msg.DenomId, msg.Name, msg.URI, utils.SanitizeUTF8(dataJSON), 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 {
Expand Down
75 changes: 75 additions & 0 deletions sample_configs/integration-tests-config/bdjuno/config.yaml
Original file line number Diff line number Diff line change
@@ -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: ""