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

feat: eth receipt command #44

Merged
merged 1 commit into from
Aug 31, 2024
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
17 changes: 9 additions & 8 deletions cmd/playground/query/evmos/ethCode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"fmt"
"os"

"github.com/hanchon/hanchond/playground/evmos"
"github.com/hanchon/hanchond/lib/requester"
"github.com/hanchon/hanchond/playground/cosmosdaemon"
"github.com/hanchon/hanchond/playground/sql"
"github.com/spf13/cobra"
)
Expand All @@ -16,19 +17,19 @@ var ethCodeCmd = &cobra.Command{
Short: "Get the smartcontract registered eth code",
Run: func(cmd *cobra.Command, args []string) {
queries := sql.InitDBFromCmd(cmd)
nodeID, err := cmd.Flags().GetString("node")
if err != nil {
fmt.Println("node not set")
os.Exit(1)
}

height, err := cmd.Flags().GetString("height")
if err != nil {
fmt.Println("error getting the request height:", err.Error())
os.Exit(1)
}

e := evmos.NewEvmosFromDB(queries, nodeID)
client := e.NewRequester()
endpoint, err := cosmosdaemon.GetWeb3Endpoint(queries, cmd)
if err != nil {
fmt.Printf("error generting web3 endpoint: %s\n", err.Error())
os.Exit(1)
}
client := requester.NewClient().WithUnsecureWeb3Endpoint(endpoint)

code, err := client.EthCode(args[0], height)
if err != nil {
Expand Down
47 changes: 47 additions & 0 deletions cmd/playground/query/evmos/ethReceipt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package evmos

import (
"encoding/json"
"fmt"
"os"

"github.com/hanchon/hanchond/lib/requester"
"github.com/hanchon/hanchond/playground/cosmosdaemon"
"github.com/hanchon/hanchond/playground/sql"
"github.com/spf13/cobra"
)

// ethReceiptCmd represents the ethReceipt command
var ethReceiptCmd = &cobra.Command{
Use: "eth-receipt [tx_hash]",
Args: cobra.ExactArgs(1),
Short: "Get the receipt for the given tx hash",
Run: func(cmd *cobra.Command, args []string) {
queries := sql.InitDBFromCmd(cmd)

endpoint, err := cosmosdaemon.GetWeb3Endpoint(queries, cmd)
if err != nil {
fmt.Printf("error generting web3 endpoint: %s\n", err.Error())
os.Exit(1)
}
client := requester.NewClient().WithUnsecureWeb3Endpoint(endpoint)

receipt, err := client.GetTransactionReceipt(args[0])
if err != nil {
fmt.Println("could not get the ethReceipt:", err.Error())
os.Exit(1)
}

val, err := json.Marshal(receipt.Result)
if err != nil {
fmt.Println("could not process the ethReceipt:", err.Error())
os.Exit(1)
}

fmt.Println(string(val))
},
}

func init() {
EvmosCmd.AddCommand(ethReceiptCmd)
}
7 changes: 6 additions & 1 deletion cmd/playground/query/evmos/evmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import (
// EvmosCmd represents the evmos command
var EvmosCmd = &cobra.Command{
Use: "evmos",
Short: "evmos unique queries ",
Short: "evmos unique queries",
Run: func(cmd *cobra.Command, _ []string) {
filesmanager.SetHomeFolderFromCobraFlags(cmd)
_ = cmd.Help()
os.Exit(0)
},
}

func init() {
EvmosCmd.PersistentFlags().String("url", "", "Set the url path if using external provider")
EvmosCmd.PersistentFlags().Bool("mainnet", false, "Set as true if the query for Evmos mainnet. This flag takes overwrite all the other provider related flags.")
}
2 changes: 1 addition & 1 deletion docs/pages/hanchond/playground/queries/erc20/balance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ The `height` flag is available to query archive data, it defaults to `latest`

The flag `url` can be used to change the URL provider.

The flag `mainnet` can be used to query Evmos mainnet data. (This flag overwrites the `node` and `url` flag with the default Mainnet URL)
The flag `mainnet` can be used to query Evmos Mainnet data. (This flag overwrites the `node` and `url` flag with the default Mainnet URL)
:::
6 changes: 6 additions & 0 deletions docs/pages/hanchond/playground/queries/evmos/ethCode.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ hanchond playground query evmos eth-code 0xc0ac82342eacc3e5d38744660f7a57f465568
"result": "0x6080604052348015600f57600080fd5b506004361060285760003560e01c80631627905514602d575b600080fd5b605060048036036020811015604157600080fd5b50356001600160a01b03166064565b604080519115158252519081900360200190f35b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470818114801590609757508115155b94935050505056fea264697066735822122030375d12bcd1c1173c9972f2bab6ba2db059fae1a35020cc0d1115194a8b445464736f6c634300060c0033"
}
```

:::info
The flag `url` can be used to change the URL provider.

The flag `mainnet` can be used to query Evmos Mainnet data. (This flag overwrites the `node` and `url` flag with the default Mainnet URL)
:::
44 changes: 44 additions & 0 deletions docs/pages/hanchond/playground/queries/evmos/ethReceipt.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Eth Receipt

The command `eth-receipt` returns the receipt of an Ethereum transaction.

```sh
hanchond playground query evmos eth-receipt 0x2a1d79fa17b252cf96fdb031bd3d3000770f64a6d9711b5871321fbdb0062434 | jq .
{
"blockHash": "0x107a5e5c14a1f7d6ab016a1e41ac20e292a0fd6fd010ca901888233067b79571",
"blockNumber": "0x35a",
"contractAddress": "",
"cumulativeGasUsed": "0x68c4",
"from": "0xf45ebe00d47a941776faa42c5bc819166a75775c",
"gasUsed": "0x68c4",
"logs": [
{
"address": "0x13abd22cb7d1636a92c997bab22b99c7e9c85083",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x000000000000000000000000f45ebe00d47a941776faa42c5bc819166a75775c",
"0x000000000000000000000000f45ebe00d47a941776faa42c5bc819166a75775c"
],
"data": "0x0000000000000000000000000000000000000000000000000000000000000001",
"blockNumber": "0x35a",
"transactionHash": "0x2a1d79fa17b252cf96fdb031bd3d3000770f64a6d9711b5871321fbdb0062434",
"transactionIndex": "0x0",
"blockHash": "0x107a5e5c14a1f7d6ab016a1e41ac20e292a0fd6fd010ca901888233067b79571",
"logIndex": "0x0",
"removed": false
}
],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000008000000000000000000000000000000000000000000000000000000000000004000000800000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004400",
"status": "0x1",
"to": "0x13abd22cb7d1636a92c997bab22b99c7e9c85083",
"transactionHash": "0x2a1d79fa17b252cf96fdb031bd3d3000770f64a6d9711b5871321fbdb0062434",
"transactionIndex": "0x0",
"type": "0x0"
}
```

:::info
The flag `url` can be used to change the URL provider.

The flag `mainnet` can be used to query Evmos Mainnet data. (This flag overwrites the `node` and `url` flag with the default Mainnet URL)
:::
4 changes: 4 additions & 0 deletions vocs.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ export default defineConfig({
text: "Smart-Contract Bytecode",
link: "/hanchond/playground/queries/evmos/ethCode",
},
{
text: "Eth Transaction Receipt",
link: "/hanchond/playground/queries/evmos/ethReceipt",
},
],
},
],
Expand Down
Loading