Skip to content

Commit

Permalink
add: wasmd package and cosmwasm module
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaghettiOverload committed Aug 10, 2023
1 parent 1316910 commit 22f5c97
Show file tree
Hide file tree
Showing 11 changed files with 1,147 additions and 3 deletions.
83 changes: 83 additions & 0 deletions database/cosmwasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package database

import "github.com/forbole/bdjuno/v4/types"

func (db *Db) SaveMsgStoreCodeData(data *types.MsgStoreCodeData) error {
_, err := db.SQL.Exec(
`INSERT INTO cosmwasm_store (
transaction_hash, index, sender, instantiate_permission, result_code_id, success
) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (transaction_hash, index) DO UPDATE SET
sender = excluded.sender, instantiate_permission = excluded.instantiate_permission,
result_code_id = excluded.result_code_id, success = excluded.success`,
data.TxHash, data.Index, data.Sender, data.InstantiatePermission, data.ResultCodeID, data.Success,
)
return err
}

func (db *Db) SaveMsgInstantiateContractData(data *types.MsgInstantiateContractData) error {
_, err := db.SQL.Exec(
`INSERT INTO cosmwasm_instantiate (
transaction_hash, index, admin, funds, label, sender, code_id,
result_contract_address, success
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) ON CONFLICT (transaction_hash, index) DO UPDATE SET
admin = excluded.admin, funds = excluded.funds, label = excluded.label, sender = excluded.sender,
code_id = excluded.code_id, result_contract_address = excluded.result_contract_address, success = excluded.success`,
data.TxHash, data.Index, data.Admin, data.Funds, data.Label,
data.Sender, data.CodeID, data.ResultContractAddress, data.Success,
)
return err
}

func (db *Db) SaveMsgExecuteContractData(data *types.MsgExecuteContractData) error {
_, err := db.SQL.Exec(
`INSERT INTO cosmwasm_execute (
transaction_hash, index, method, arguments,
funds, sender, contract, success
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT (transaction_hash, index) DO UPDATE SET
method = excluded.method, arguments = excluded.arguments, funds = excluded.funds,
sender = excluded.sender, contract = excluded.contract, success = excluded.success`,
data.TxHash, data.Index, data.Method, data.Arguments,
data.Funds, data.Sender, data.Contract, data.Success,
)
return err
}

func (db *Db) SaveMsgMigrateContactData(data *types.MsgMigrateContractData) error {
_, err := db.SQL.Exec(
`INSERT INTO cosmwasm_migrate (
transaction_hash, index, contract, code_id,
arguments, sender, success
) VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT (transaction_hash, index) DO UPDATE SET
contract = excluded.contract, code_id = excluded.code_id, arguments = excluded.arguments,
sender = excluded.sender, success = excluded.success`,
data.TxHash, data.Index, data.Contract, data.CodeID,
data.Arguments, data.Sender, data.Success,
)
return err
}

func (db *Db) SaveMsgUpdateAdminData(data *types.MsgUpdateAdminData) error {
_, err := db.SQL.Exec(
`INSERT INTO cosmwasm_update_admin (
transaction_hash, index, contract, new_admin,
sender, success
) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (transaction_hash, index) DO UPDATE SET
contract = excluded.contract, new_admin = excluded.new_admin, sender = excluded.sender,
success = excluded.success`,
data.TxHash, data.Index, data.Contract, data.NewAdmin,
data.Sender, data.Success,
)
return err
}

func (db *Db) SaveMsgClearAdminData(data *types.MsgClearAdminData) error {
_, err := db.SQL.Exec(
`INSERT INTO cosmwasm_clear_admin (
transaction_hash, index, contract,
sender, success
) VALUES($1, $2, $3, $4, $5) ON CONFLICT (transaction_hash, index) DO UPDATE SET
contract = excluded.contract, sender = excluded.sender, success = excluded.success`,
data.TxHash, data.Index, data.Contract, data.Sender, data.Success,
)
return err
}
Loading

0 comments on commit 22f5c97

Please sign in to comment.