forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9494874
commit 65f27f2
Showing
12 changed files
with
123 additions
and
80 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
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,71 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/viper" | ||
|
||
rpcclient "github.com/tendermint/tendermint/rpc/client" | ||
ctypes "github.com/tendermint/tendermint/rpc/core/types" | ||
cmn "github.com/tendermint/tmlibs/common" | ||
) | ||
|
||
// GetNode prepares a simple rpc.Client from the flags | ||
func GetNode() (rpcclient.Client, error) { | ||
uri := viper.GetString(FlagNode) | ||
if uri == "" { | ||
return nil, errors.New("Must define node using --node") | ||
} | ||
return rpcclient.NewHTTP(uri, "/websocket"), nil | ||
} | ||
|
||
// Broadcast the transaction bytes to Tendermint | ||
func BroadcastTx(tx []byte) (*ctypes.ResultBroadcastTxCommit, error) { | ||
|
||
node, err := GetNode() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res, err := node.BroadcastTxCommit(tx) | ||
if err != nil { | ||
return res, err | ||
} | ||
|
||
if res.CheckTx.Code != uint32(0) { | ||
return res, errors.Errorf("CheckTx failed: (%d) %s", | ||
res.CheckTx.Code, | ||
res.CheckTx.Log) | ||
} | ||
if res.DeliverTx.Code != uint32(0) { | ||
return res, errors.Errorf("DeliverTx failed: (%d) %s", | ||
res.DeliverTx.Code, | ||
res.DeliverTx.Log) | ||
} | ||
return res, err | ||
} | ||
|
||
// Query from Tendermint with the provided key and storename | ||
func Query(key cmn.HexBytes, storeName string) (res []byte, err error) { | ||
|
||
path := fmt.Sprintf("/%s/key", storeName) | ||
node, err := GetNode() | ||
if err != nil { | ||
return res, err | ||
} | ||
|
||
opts := rpcclient.ABCIQueryOptions{ | ||
Height: viper.GetInt64(FlagHeight), | ||
Trusted: viper.GetBool(FlagTrustNode), | ||
} | ||
result, err := node.ABCIQueryWithOptions(path, key, opts) | ||
if err != nil { | ||
return res, err | ||
} | ||
resp := result.Response | ||
if resp.Code != uint32(0) { | ||
return res, errors.Errorf("Query failed: (%d) %s", resp.Code, resp.Log) | ||
} | ||
return resp.Value, nil | ||
} |
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 was deleted.
Oops, something went wrong.
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
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