Skip to content

Commit

Permalink
store wasm contract address inside involved_accounts_addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
MonikaCat committed Sep 27, 2023
1 parent a446edf commit 5744a6a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
14 changes: 13 additions & 1 deletion database/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,16 @@ sender = $1, admin = $2 WHERE contract_address = $2 `
return fmt.Errorf("error while updating wsm contract admin: %s", err)
}
return nil
}
}

func (db *Db) UpdateMsgInvolvedAccountsAddresses(contractAddress string, txHash string) error {

stmt := `UPDATE message SET
involved_accounts_addresses = ARRAY_APPEND(involved_accounts_addresses, $1) WHERE transaction_hash = $2 `

_, err := db.SQL.Exec(stmt, contractAddress, txHash)
if err != nil {
return fmt.Errorf("error while updating wasm contract message: %s", err)
}
return nil
}
35 changes: 30 additions & 5 deletions modules/wasm/handle_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func (m *Module) HandleMsg(index int, msg sdk.Msg, tx *juno.Tx) error {
return fmt.Errorf("error while handling MsgMigrateContract: %s", err)
}
case *wasmtypes.MsgUpdateAdmin:
err := m.HandleMsgUpdateAdmin(cosmosMsg)
err := m.HandleMsgUpdateAdmin(cosmosMsg, tx)
if err != nil {
return fmt.Errorf("error while handling MsgUpdateAdmin: %s", err)
}
case *wasmtypes.MsgClearAdmin:
err := m.HandleMsgClearAdmin(cosmosMsg)
err := m.HandleMsgClearAdmin(cosmosMsg, tx)
if err != nil {
return fmt.Errorf("error while handling MsgClearAdmin: %s", err)
}
Expand Down Expand Up @@ -96,6 +96,11 @@ func (m *Module) HandleMsgInstantiateContract(index int, tx *juno.Tx, msg *wasmt
return fmt.Errorf("error while searching for AttributeKeyContractAddr: %s", err)
}

err = m.db.UpdateMsgInvolvedAccountsAddresses(contractAddress, tx.TxHash)
if err != nil {
return fmt.Errorf("error while saving contract address inside involved accounts addresses: %s", err)
}

// Get result data
resultData, err := tx.FindAttributeByKey(event, wasmtypes.AttributeKeyResultDataHex)
if err != nil {
Expand Down Expand Up @@ -168,6 +173,11 @@ func (m *Module) HandleMsgExecuteContract(index int, tx *juno.Tx, msg *wasmtypes
return fmt.Errorf("error while parsing time: %s", err)
}

err = m.db.UpdateMsgInvolvedAccountsAddresses(msg.Contract, tx.TxHash)
if err != nil {
return fmt.Errorf("error while saving contract address inside the involved addresses in message table: %s", err)
}

return m.db.SaveWasmExecuteContract(
types.NewWasmExecuteContract(
msg.Sender, msg.Contract, msg.Msg, msg.Funds,
Expand Down Expand Up @@ -195,17 +205,32 @@ func (m *Module) HandleMsgMigrateContract(index int, tx *juno.Tx, msg *wasmtypes
return fmt.Errorf("error while decoding result data: %s", err)
}

err = m.db.UpdateMsgInvolvedAccountsAddresses(msg.Contract, tx.TxHash)
if err != nil {
return fmt.Errorf("error while saving contract address inside the involved addresses in message table: %s", err)
}

return m.db.UpdateContractWithMsgMigrateContract(msg.Sender, msg.Contract, msg.CodeID, msg.Msg, string(resultDataBz))
}

// HandleMsgUpdateAdmin allows to properly handle a MsgUpdateAdmin
// Update Admin Event updates the contract admin who can migrate the wasm contract
func (m *Module) HandleMsgUpdateAdmin(msg *wasmtypes.MsgUpdateAdmin) error {
func (m *Module) HandleMsgUpdateAdmin(msg *wasmtypes.MsgUpdateAdmin, tx *juno.Tx) error {
err := m.db.UpdateMsgInvolvedAccountsAddresses(msg.Contract, tx.TxHash)
if err != nil {
return fmt.Errorf("error while saving contract address inside the involved addresses in message table: %s", err)
}

return m.db.UpdateContractAdmin(msg.Sender, msg.Contract, msg.NewAdmin)
}

// HandleMsgClearAdmin allows to properly handle a MsgClearAdmin
// Clear Admin Event clears the admin which make the contract no longer migratable
func (m *Module) HandleMsgClearAdmin(msg *wasmtypes.MsgClearAdmin) error {
func (m *Module) HandleMsgClearAdmin(msg *wasmtypes.MsgClearAdmin, tx *juno.Tx) error {
err := m.db.UpdateMsgInvolvedAccountsAddresses(msg.Contract, tx.TxHash)
if err != nil {
return fmt.Errorf("error while saving contract address inside the involved addresses in message table: %s", err)
}

return m.db.UpdateContractAdmin(msg.Sender, msg.Contract, "")
}
}

0 comments on commit 5744a6a

Please sign in to comment.