forked from cerc-io/laconicd-deprecated
Implements eth_getProof (#122)
* Implemented eth_getProof and cleaned logs query types * Rename ethereum logs query type
This commit is contained in:
+24
-4
@@ -25,6 +25,7 @@ const (
|
||||
QueryTxLogs = "txLogs"
|
||||
QueryLogsBloom = "logsBloom"
|
||||
QueryLogs = "logs"
|
||||
QueryAccount = "account"
|
||||
)
|
||||
|
||||
// NewQuerier is the module level router for state queries
|
||||
@@ -50,7 +51,9 @@ func NewQuerier(keeper Keeper) sdk.Querier {
|
||||
case QueryLogsBloom:
|
||||
return queryBlockLogsBloom(ctx, path, keeper)
|
||||
case QueryLogs:
|
||||
return queryLogs(ctx, path, keeper)
|
||||
return queryLogs(ctx, keeper)
|
||||
case QueryAccount:
|
||||
return queryAccount(ctx, path, keeper)
|
||||
default:
|
||||
return nil, sdk.ErrUnknownRequest("unknown query endpoint")
|
||||
}
|
||||
@@ -162,7 +165,7 @@ func queryTxLogs(ctx sdk.Context, path []string, keeper Keeper) ([]byte, sdk.Err
|
||||
txHash := ethcmn.HexToHash(path[1])
|
||||
logs := keeper.GetLogs(ctx, txHash)
|
||||
|
||||
bRes := types.QueryTxLogs{Logs: logs}
|
||||
bRes := types.QueryETHLogs{Logs: logs}
|
||||
res, err := codec.MarshalJSONIndent(keeper.cdc, bRes)
|
||||
if err != nil {
|
||||
panic("could not marshal result to JSON: " + err.Error())
|
||||
@@ -171,10 +174,27 @@ func queryTxLogs(ctx sdk.Context, path []string, keeper Keeper) ([]byte, sdk.Err
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func queryLogs(ctx sdk.Context, path []string, keeper Keeper) ([]byte, sdk.Error) {
|
||||
func queryLogs(ctx sdk.Context, keeper Keeper) ([]byte, sdk.Error) {
|
||||
logs := keeper.Logs(ctx)
|
||||
|
||||
l, err := codec.MarshalJSONIndent(keeper.cdc, logs)
|
||||
lRes := types.QueryETHLogs{Logs: logs}
|
||||
l, err := codec.MarshalJSONIndent(keeper.cdc, lRes)
|
||||
if err != nil {
|
||||
panic("could not marshal result to JSON: " + err.Error())
|
||||
}
|
||||
return l, nil
|
||||
}
|
||||
|
||||
func queryAccount(ctx sdk.Context, path []string, keeper Keeper) ([]byte, sdk.Error) {
|
||||
addr := ethcmn.HexToAddress(path[1])
|
||||
so := keeper.GetOrNewStateObject(ctx, addr)
|
||||
|
||||
lRes := types.QueryAccount{
|
||||
Balance: utils.MarshalBigInt(so.Balance()),
|
||||
CodeHash: so.CodeHash(),
|
||||
Nonce: so.Nonce(),
|
||||
}
|
||||
l, err := codec.MarshalJSONIndent(keeper.cdc, lRes)
|
||||
if err != nil {
|
||||
panic("could not marshal result to JSON: " + err.Error())
|
||||
}
|
||||
|
||||
+10
-3
@@ -60,12 +60,12 @@ func (q QueryResNonce) String() string {
|
||||
return string(q.Nonce)
|
||||
}
|
||||
|
||||
// QueryTxLogs is response type for tx logs query
|
||||
type QueryTxLogs struct {
|
||||
// QueryETHLogs is response type for tx logs query
|
||||
type QueryETHLogs struct {
|
||||
Logs []*ethtypes.Log `json:"logs"`
|
||||
}
|
||||
|
||||
func (q QueryTxLogs) String() string {
|
||||
func (q QueryETHLogs) String() string {
|
||||
return string(fmt.Sprintf("%+v", q.Logs))
|
||||
}
|
||||
|
||||
@@ -77,3 +77,10 @@ type QueryBloomFilter struct {
|
||||
func (q QueryBloomFilter) String() string {
|
||||
return string(q.Bloom.Bytes())
|
||||
}
|
||||
|
||||
// QueryAccount is response type for querying Ethereum state objects
|
||||
type QueryAccount struct {
|
||||
Balance string `json:"balance"`
|
||||
CodeHash []byte `json:"codeHash"`
|
||||
Nonce uint64 `json:"nonce"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user