2020-07-06 10:03:45 -07:00
|
|
|
package tx
|
|
|
|
|
|
|
|
import (
|
2020-08-03 12:47:25 -07:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
|
2020-07-06 10:03:45 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/signing"
|
|
|
|
)
|
|
|
|
|
2020-08-03 12:47:25 -07:00
|
|
|
// DefaultSignModes are the default sign modes enabled for protobuf transactions.
|
|
|
|
var DefaultSignModes = []signingtypes.SignMode{
|
|
|
|
signingtypes.SignMode_SIGN_MODE_DIRECT,
|
2021-03-25 07:53:22 -07:00
|
|
|
signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, //nolint:staticcheck
|
2020-08-03 12:47:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// makeSignModeHandler returns the default protobuf SignModeHandler supporting
|
2020-07-06 10:03:45 -07:00
|
|
|
// SIGN_MODE_DIRECT and SIGN_MODE_LEGACY_AMINO_JSON.
|
2020-08-03 12:47:25 -07:00
|
|
|
func makeSignModeHandler(modes []signingtypes.SignMode) signing.SignModeHandler {
|
|
|
|
if len(modes) < 1 {
|
|
|
|
panic(fmt.Errorf("no sign modes enabled"))
|
|
|
|
}
|
|
|
|
|
|
|
|
handlers := make([]signing.SignModeHandler, len(modes))
|
|
|
|
|
|
|
|
for i, mode := range modes {
|
|
|
|
switch mode {
|
|
|
|
case signingtypes.SignMode_SIGN_MODE_DIRECT:
|
|
|
|
handlers[i] = signModeDirectHandler{}
|
2021-03-25 07:53:22 -07:00
|
|
|
case signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: //nolint:staticcheck
|
2020-08-03 12:47:25 -07:00
|
|
|
handlers[i] = signModeLegacyAminoJSONHandler{}
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("unsupported sign mode %+v", mode))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-06 10:03:45 -07:00
|
|
|
return signing.NewSignModeHandlerMap(
|
2020-08-03 12:47:25 -07:00
|
|
|
modes[0],
|
|
|
|
handlers,
|
2020-07-06 10:03:45 -07:00
|
|
|
)
|
|
|
|
}
|