fixed global flags

This commit is contained in:
Jae Kwon
2015-04-15 23:41:13 -07:00
parent df1d46d04d
commit adccd8f878
2 changed files with 123 additions and 36 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
acm "github.com/tendermint/tendermint/account"
"github.com/tendermint/tendermint/binary"
btypes "github.com/tendermint/tendermint/cmd/barak/types"
@ -8,13 +9,33 @@ import (
"github.com/tendermint/tendermint/rpc"
)
// Convenience function for a single validator.
func ListProcesses(privKey acm.PrivKey, remote string) (btypes.ResponseListProcesses, error) {
command := btypes.CommandListProcesses{}
nonce := GetNonce(remote)
func RunProcess(privKey acm.PrivKey, remote string, command btypes.CommandRunProcess) (response btypes.ResponseRunProcess, err error) {
nonce, err := GetNonce(remote)
if err != nil {
return response, err
}
commandBytes, signature := SignCommand(privKey, nonce+1, command)
response := btypes.ResponseListProcesses{}
_, err := RunAuthCommand(remote, commandBytes, []acm.Signature{signature}, &response)
_, err = RunAuthCommand(remote, commandBytes, []acm.Signature{signature}, &response)
return response, err
}
func StopProcess(privKey acm.PrivKey, remote string, command btypes.CommandStopProcess) (response btypes.ResponseStopProcess, err error) {
nonce, err := GetNonce(remote)
if err != nil {
return response, err
}
commandBytes, signature := SignCommand(privKey, nonce+1, command)
_, err = RunAuthCommand(remote, commandBytes, []acm.Signature{signature}, &response)
return response, err
}
func ListProcesses(privKey acm.PrivKey, remote string, command btypes.CommandListProcesses) (response btypes.ResponseListProcesses, err error) {
nonce, err := GetNonce(remote)
if err != nil {
return response, err
}
commandBytes, signature := SignCommand(privKey, nonce+1, command)
_, err = RunAuthCommand(remote, commandBytes, []acm.Signature{signature}, &response)
return response, err
}
@ -22,14 +43,14 @@ func ListProcesses(privKey acm.PrivKey, remote string) (btypes.ResponseListProce
// Utility method to get nonce from the remote.
// The next command should include the returned nonce+1 as nonce.
func GetNonce(remote string) uint64 {
func GetNonce(remote string) (uint64, error) {
var err error
response := btypes.ResponseStatus{}
_, err = rpc.Call(remote, "status", Arr(), &response)
if err != nil {
Exit(Fmt("Error fetching nonce from remote %v: %v", remote, err))
return 0, fmt.Errorf("Error fetching nonce from remote %v:\n %v", remote, err)
}
return response.Nonce
return response.Nonce, nil
}
// Each developer runs this