Encaptulate Get Passphrase Logic in Builder

This commit is contained in:
Yukai Tu
2018-03-24 23:14:18 -07:00
parent 2d45058352
commit 96d9c55172
6 changed files with 21 additions and 48 deletions
+13 -1
View File
@@ -124,7 +124,12 @@ func SignAndBuild(name, passphrase string, msg sdk.Msg, cdc *wire.Codec) ([]byte
}
// sign and build the transaction from the msg
func SignBuildBroadcast(name string, passphrase string, msg sdk.Msg, cdc *wire.Codec) (*ctypes.ResultBroadcastTxCommit, error) {
func SignBuildBroadcast(name string, msg sdk.Msg, cdc *wire.Codec) (*ctypes.ResultBroadcastTxCommit, error) {
passphrase, err := GetPassphraseFromStdin(name)
if err != nil {
return nil, err
}
txBytes, err := SignAndBuild(name, passphrase, msg, cdc)
if err != nil {
return nil, err
@@ -132,3 +137,10 @@ func SignBuildBroadcast(name string, passphrase string, msg sdk.Msg, cdc *wire.C
return BroadcastTx(txBytes)
}
// get passphrase from std input
func GetPassphraseFromStdin(name string) (pass string, err error) {
buf := client.BufferStdin()
prompt := fmt.Sprintf("Password to sign with '%s':", name)
return client.GetPassword(prompt, buf)
}