Add sign and post helper functions

This commit is contained in:
Ethan Frey 2017-07-28 10:35:39 -04:00
parent 4245bb8a67
commit eae1883f3d
1 changed files with 29 additions and 0 deletions

29
client/rest/helpers.go Normal file
View File

@ -0,0 +1,29 @@
package rest
import (
keycmd "github.com/tendermint/go-crypto/cmd"
"github.com/tendermint/go-crypto/keys"
wire "github.com/tendermint/go-wire"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/basecoin"
"github.com/tendermint/basecoin/client/commands"
)
// PostTx is same as a tx
func PostTx(tx basecoin.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
packet := wire.BinaryBytes(tx)
// post the bytes
node := commands.GetNode()
return node.BroadcastTxCommit(packet)
}
// SignTx will modify the tx in-place, adding a signature if possible
func SignTx(name, pass string, tx basecoin.Tx) error {
if sign, ok := tx.Unwrap().(keys.Signable); ok {
manager := keycmd.GetKeyManager()
return manager.Sign(name, pass, sign)
}
return nil
}