Skip to content

Commit

Permalink
added SilentEncode method to pubkeyconverter
Browse files Browse the repository at this point in the history
  • Loading branch information
schimih committed Dec 7, 2022
1 parent 83af631 commit 3467f36
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion core/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type PubkeyConverter interface {
Len() int
Decode(humanReadable string) ([]byte, error)
Encode(pkBytes []byte) (string, error)
QuietEncode(pkBytes []byte, log Logger) string
SilentEncode(pkBytes []byte, log Logger) string
EncodeSlice(pkBytesSlice [][]byte) ([]string, error)
IsInterfaceNil() bool
}
Expand Down
10 changes: 5 additions & 5 deletions core/pubkeyConverter/bech32PubkeyConverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func (bpc *bech32PubkeyConverter) Encode(pkBytes []byte) (string, error) {
return converted, nil
}

// QuietEncode converts the provided bytes in a bech32 form without returning any error
func (bpc *bech32PubkeyConverter) QuietEncode(pkBytes []byte, log core.Logger) string {
// SilentEncode converts the provided bytes in a bech32 form without returning any error
func (bpc *bech32PubkeyConverter) SilentEncode(pkBytes []byte, log core.Logger) string {
if len(pkBytes) != bpc.len {
log.Debug("bech32PubkeyConverter.Encode PubKeyBytesLength",
log.Warn("bech32PubkeyConverter.SilentEncode PubKeyBytesLength",
"hex buff", hex.EncodeToString(pkBytes),
"error", ErrWrongSize,
"stack trace", string(debug.Stack()))
Expand All @@ -112,7 +112,7 @@ func (bpc *bech32PubkeyConverter) QuietEncode(pkBytes []byte, log core.Logger) s
//since the errors generated here are usually because of a bad config, they will be treated here
conv, err := bech32.ConvertBits(pkBytes, bech32Config.fromBits, bech32Config.toBits, bech32Config.pad)
if err != nil {
log.Warn("bech32PubkeyConverter.Encode ConvertBits",
log.Warn("bech32PubkeyConverter.SilentEncode ConvertBits",
"hex buff", hex.EncodeToString(pkBytes),
"error", ErrWrongSize,
"stack trace", string(debug.Stack()))
Expand All @@ -121,7 +121,7 @@ func (bpc *bech32PubkeyConverter) QuietEncode(pkBytes []byte, log core.Logger) s

converted, err := bech32.Encode(bpc.prefix, conv)
if err != nil {
log.Warn("bech32PubkeyConverter.Encode Encode",
log.Warn("bech32PubkeyConverter.SilentEncode Encode",
"hex buff", hex.EncodeToString(conv),
"error", ErrWrongSize,
"stack trace", string(debug.Stack()))
Expand Down
2 changes: 1 addition & 1 deletion core/pubkeyConverter/bech32PubkeyConverter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestBech32PubkeyConverter_EncodeSliceShouldWork(t *testing.T) {
addressLen := 32
sliceLen := 2

bpc, _ := pubkeyConverter.NewBech32PubkeyConverter(addressLen, "erd")
bpc, _ := pubkeyConverter.NewBech32PubkeyConverter(addressLen, core.DefaultAddressPrefix)

decodedSlice := make([][]byte, 0)

Expand Down
4 changes: 2 additions & 2 deletions core/pubkeyConverter/hexPubkeyConverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func (ppc *hexPubkeyConverter) EncodeSlice(pkBytesSlice [][]byte) ([]string, err
return encodedSlice, nil
}

// QuietEncode converts the provided bytes in a form that this converter can decode. In this case it will encode to hex
func (ppc *hexPubkeyConverter) QuietEncode(pkBytes []byte, log core.Logger) string {
// SilentEncode converts the provided bytes in a form that this converter can decode. In this case it will encode to hex
func (ppc *hexPubkeyConverter) SilentEncode(pkBytes []byte, log core.Logger) string {
return hex.EncodeToString(pkBytes)
}

Expand Down
16 changes: 8 additions & 8 deletions data/mock/pubkeyConverterStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import "github.com/ElrondNetwork/elrond-go-core/core"

// PubkeyConverterStub -
type PubkeyConverterStub struct {
LenCalled func() int
DecodeCalled func(humanReadable string) ([]byte, error)
EncodeCalled func(pkBytes []byte) (string, error)
EncodeSliceCalled func(pkBytesSlice [][]byte) ([]string, error)
QuietEncodeCalled func(pkBytes []byte, log core.Logger) string
LenCalled func() int
DecodeCalled func(humanReadable string) ([]byte, error)
EncodeCalled func(pkBytes []byte) (string, error)
EncodeSliceCalled func(pkBytesSlice [][]byte) ([]string, error)
SilentEncodeCalled func(pkBytes []byte, log core.Logger) string
}

// Len -
Expand Down Expand Up @@ -47,10 +47,10 @@ func (pcs *PubkeyConverterStub) EncodeSlice(pkBytesSlice [][]byte) ([]string, er
return make([]string, 0), nil
}

// QuietEncode -
func (pcs *PubkeyConverterStub) QuietEncode(pkBytes []byte, log core.Logger) string {
// SilentEncode -
func (pcs *PubkeyConverterStub) SilentEncode(pkBytes []byte, log core.Logger) string {
if pcs.EncodeCalled != nil {
return pcs.QuietEncodeCalled(pkBytes, log)
return pcs.SilentEncodeCalled(pkBytes, log)
}

return ""
Expand Down

0 comments on commit 3467f36

Please sign in to comment.