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

Baseserver send #203

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ merkleeyes.db
build
shunit2
docs/guide/*.sh

keys/
25 changes: 17 additions & 8 deletions client/commands/proofs/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package proofs

import (
"fmt"
"io"
"os"

"github.com/pkg/errors"
"github.com/spf13/viper"
Expand Down Expand Up @@ -111,15 +113,22 @@ type proof struct {
Data interface{} `json:"data"`
}

// OutputProof prints the proof to stdout
// reuse this for printing proofs and we should enhance this for text/json,
// better presentation of height
func OutputProof(info interface{}, height uint64) error {
wrap := proof{height, info}
res, err := data.ToJSON(wrap)
// FoutputProof writes the output of wrapping height and info
// in the form {"data": <the_data>, "height": <the_height>}
// to the provider io.Writer
func FoutputProof(w io.Writer, v interface{}, height uint64) error {
wrap := &proof{height, v}
blob, err := data.ToJSON(wrap)
if err != nil {
return err
}
fmt.Println(string(res))
return nil
_, err = fmt.Fprintf(w, "%s\n", blob)
return err
}

// OutputProof prints the proof to stdout
// reuse this for printing proofs and we should enhance this for text/json,
// better presentation of height
func OutputProof(data interface{}, height uint64) error {
return FoutputProof(os.Stdout, data, height)
}
22 changes: 12 additions & 10 deletions client/commands/txs/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,27 @@ func GetSignerAct() (res basecoin.Actor) {
// eg. if you already set the middleware layers in your code, or want to
// output in another format.
func DoTx(tx basecoin.Tx) (err error) {
tx, err = Middleware.Wrap(tx)
bres, err := CommitTx(tx)
if err != nil {
return err
}

err = SignTx(tx)
if err != nil {
return err
if bres == nil {
return nil // successful prep, nothing left to do
}
return OutputTx(bres) // print response of the post
}

bres, err := PrepareOrPostTx(tx)
func CommitTx(tx basecoin.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
tx, err := Middleware.Wrap(tx)
if err != nil {
return err
return nil, err
}
if bres == nil {
return nil // successful prep, nothing left to do

if err := SignTx(tx); err != nil {
return nil, err
}
return OutputTx(bres) // print response of the post

return PrepareOrPostTx(tx)
}

// SignTx will validate the tx, and signs it if it is wrapping a Signable.
Expand Down
47 changes: 47 additions & 0 deletions client/rest/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package rest

import (
"fmt"
"log"
"net/http"

"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/spf13/viper"

coinrest "github.com/tendermint/basecoin/modules/coin/rest"
)

var ServeCmd = &cobra.Command{
Use: "serve",
Short: "Serve the light REST client for tendermint",
Long: "Access basecoin via REST",
RunE: serve,
}

const envPortFlag = "port"

func init() {
_ = ServeCmd.PersistentFlags().Int(envPortFlag, 8998, "the port to run the server on")
}

const defaultAlgo = "ed25519"

func serve(cmd *cobra.Command, args []string) error {
port := viper.GetInt(envPortFlag)
keysManager := DefaultKeysManager()
router := mux.NewRouter()
ctx := Context{
Keys: New(keysManager, defaultAlgo),
}
if err := ctx.RegisterHandlers(router); err != nil {
return err
}
if err := coinrest.RegisterHandlers(router); err != nil {
return err
}

addr := fmt.Sprintf(":%d", port)
log.Printf("Serving on %q", addr)
return http.ListenAndServe(addr, router)
}
Loading