Skip to content

Commit

Permalink
updated wasm message handler
Browse files Browse the repository at this point in the history
  • Loading branch information
MonikaCat committed Feb 1, 2024
1 parent a78044e commit 3fe684e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions database/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ func (db *Db) SaveWasmExecuteContract(wasmExecuteContract types.WasmExecuteContr
return db.SaveWasmExecuteContracts([]types.WasmExecuteContract{wasmExecuteContract})
}

func (db *Db) CheckIfContractExistsInDB(contractAddresss string) bool {
var rows []*dbtypes.WasmContractRow
err := db.SQL.Select(&rows, `SELECT * FROM wasm_contract WHERE contract_address = $1`, contractAddresss)
if err != nil {
return false
}

if len(rows) == 0 {
return false
}

return true
}

// SaveWasmContracts allows to store the wasm contract slice
func (db *Db) SaveWasmExecuteContracts(executeContracts []types.WasmExecuteContract) error {
paramsNumber := 7
Expand Down
8 changes: 8 additions & 0 deletions modules/wasm/handle_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ func (m *Module) HandleMsgExecuteContract(index int, tx *juno.Tx, msg *wasmtypes
return fmt.Errorf("error while saving contract address inside the involved addresses in message table: %s", err)
}

contractExists := m.db.CheckIfContractExistsInDB(msg.Contract)
if !contractExists {
err = m.ParseContractDetails(msg.Contract, tx.Height)
if err != nil {
return fmt.Errorf("error while saving contract details in db: %s", err)
}
}

return m.db.SaveWasmExecuteContract(
types.NewWasmExecuteContract(
msg.Sender, msg.Contract, msg.Msg, msg.Funds,
Expand Down

0 comments on commit 3fe684e

Please sign in to comment.