-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: eth_call command to query view functions (#29)
* feat: contracts eth_call to view functions * fixes * docs * fix: build issues * chore: remove unused code * update erc20 abi
- Loading branch information
Showing
17 changed files
with
548 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
[ | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "name", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "_spender", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "approve", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "totalSupply", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "_from", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_to", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "transferFrom", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "decimals", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "uint8" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"name": "_owner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "balanceOf", | ||
"outputs": [ | ||
{ | ||
"name": "balance", | ||
"type": "uint256" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [], | ||
"name": "symbol", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": false, | ||
"inputs": [ | ||
{ | ||
"name": "_to", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "transfer", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"constant": true, | ||
"inputs": [ | ||
{ | ||
"name": "_owner", | ||
"type": "address" | ||
}, | ||
{ | ||
"name": "_spender", | ||
"type": "address" | ||
} | ||
], | ||
"name": "allowance", | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"payable": false, | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"payable": true, | ||
"stateMutability": "payable", | ||
"type": "fallback" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"name": "owner", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"name": "spender", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Approval", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"name": "from", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"name": "to", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Transfer", | ||
"type": "event" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package solidity | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/hanchon/hanchond/lib/requester" | ||
"github.com/hanchon/hanchond/lib/smartcontract" | ||
"github.com/hanchon/hanchond/playground/cosmosdaemon" | ||
"github.com/hanchon/hanchond/playground/filesmanager" | ||
"github.com/hanchon/hanchond/playground/sql" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var params []string | ||
|
||
// callContractViewCmd represents the callContractView command | ||
var callContractViewCmd = &cobra.Command{ | ||
Use: "call-contract-view [contract] [abi_path] [method]", | ||
Args: cobra.ExactArgs(3), | ||
Short: "Call a contract view with eth_call", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
queries := sql.InitDBFromCmd(cmd) | ||
|
||
height, err := cmd.Flags().GetString("height") | ||
if err != nil { | ||
fmt.Println("could not read height value:", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
contract := strings.TrimSpace(args[0]) | ||
abiPath := strings.TrimSpace(args[1]) | ||
method := strings.TrimSpace(args[2]) | ||
|
||
abiBytes, err := filesmanager.ReadFile(abiPath) | ||
if err != nil { | ||
fmt.Printf("error reading the abi file:%s\n", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
endpoint, err := cosmosdaemon.GetWeb3Endpoint(queries, cmd) | ||
if err != nil { | ||
fmt.Printf("error generting web3 endpoint: %s\n", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
callArgs, err := smartcontract.StringsToABIArguments(params) | ||
if err != nil { | ||
fmt.Printf("error converting arguments: %s\n", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
client := requester.NewClient().WithUnsecureWeb3Endpoint(endpoint) | ||
|
||
callData, err := smartcontract.ABIPack(abiBytes, method, callArgs...) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
resp, err := client.EthCall(contract, callData, height) | ||
if err != nil { | ||
fmt.Println("error on eth call", err.Error()) | ||
os.Exit(1) | ||
} | ||
fmt.Println(string(resp)) | ||
os.Exit(0) | ||
}, | ||
} | ||
|
||
func init() { | ||
SolidityCmd.AddCommand(callContractViewCmd) | ||
callContractViewCmd.Flags().String("height", "latest", "Query at the given height.") | ||
callContractViewCmd.Flags().StringSliceVarP(¶ms, "params", "p", []string{}, "A list of params. If the param is an address, prefix with `a:0x123...`") | ||
} |
Oops, something went wrong.