mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-27 03:31:42 +00:00
refactored debora/barak. about to add cli for debora
This commit is contained in:
53
cmd/debora/commands.go
Normal file
53
cmd/debora/commands.go
Normal file
@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
"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)
|
||||
commandBytes, signature := SignCommand(privKey, nonce+1, command)
|
||||
response := btypes.ResponseListProcesses{}
|
||||
_, err := RunAuthCommand(remote, commandBytes, []acm.Signature{signature}, &response)
|
||||
return response, err
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Utility method to get nonce from the remote.
|
||||
// The next command should include the returned nonce+1 as nonce.
|
||||
func GetNonce(remote string) uint64 {
|
||||
var err error
|
||||
response := btypes.ResponseStatus{}
|
||||
_, err = rpc.Call(remote, "status", Arr(), &response)
|
||||
if err != nil {
|
||||
panic(Fmt("Error fetching nonce from remote %v: %v", remote, err))
|
||||
}
|
||||
return response.Nonce
|
||||
}
|
||||
|
||||
// Each developer runs this
|
||||
func SignCommand(privKey acm.PrivKey, nonce uint64, command btypes.Command) ([]byte, acm.Signature) {
|
||||
noncedCommand := btypes.NoncedCommand{
|
||||
Nonce: nonce,
|
||||
Command: command,
|
||||
}
|
||||
commandJSONBytes := binary.JSONBytes(noncedCommand)
|
||||
signature := privKey.Sign(commandJSONBytes)
|
||||
return commandJSONBytes, signature
|
||||
}
|
||||
|
||||
// Somebody aggregates the signatures and calls this.
|
||||
func RunAuthCommand(remote string, commandJSONBytes []byte, signatures []acm.Signature, dest interface{}) (interface{}, error) {
|
||||
authCommand := btypes.AuthCommand{
|
||||
CommandJSONStr: string(commandJSONBytes),
|
||||
Signatures: signatures,
|
||||
}
|
||||
return rpc.Call(remote, "run", Arr(authCommand), dest)
|
||||
}
|
@ -2,19 +2,18 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
"github.com/tendermint/tendermint/rpc"
|
||||
// ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
|
||||
acm "github.com/tendermint/tendermint/account"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// XXX Need to get PrivAccount somehow to sign the request.
|
||||
// XXX Actually, more like, how do I even sign these?
|
||||
// XXX Let's just sign it janky for now and modify later.
|
||||
|
||||
response := []btypes.ResponseListProcesses{}
|
||||
response2, err := rpc.Call("http://127.0.0.1:8082", "list_processes", Arr(), &response)
|
||||
fmt.Printf("%v\n", response)
|
||||
fmt.Printf("%v (error: %v)\n", response2, err)
|
||||
var remote string = "http://127.0.0.1:8082"
|
||||
var err error
|
||||
var privKey acm.PrivKey
|
||||
binary.ReadJSON(&privKey, []byte(`
|
||||
[1,"PRIVKEYBYTES"]
|
||||
`), &err)
|
||||
response, err := ListProcesses(privKey, remote)
|
||||
fmt.Printf("%v (error: %v)\n", response, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user