Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion account.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (slice AccountMetaSlice) Len() int {

func (slice AccountMetaSlice) SplitFrom(index int) (AccountMetaSlice, AccountMetaSlice) {
if index < 0 {
panic("negative index")
return AccountMetaSlice{}, slice
}
if index == 0 {
return AccountMetaSlice{}, slice
Expand Down
9 changes: 5 additions & 4 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ func TestSplitFrom(t *testing.T) {
require.Len(t, part1, 5)
require.Len(t, part2, 0)
}
require.Panics(t,
func() {
slice.SplitFrom(-1)
})
{
part1, part2 := slice.SplitFrom(-1)
require.Len(t, part1, 0)
require.Len(t, part2, 5)
}
}
5 changes: 3 additions & 2 deletions diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,22 @@ func reflectValueCanIsNil(value reflect.Value) bool {
}
}

func Diff(left any, right any, opts ...Option) {
func Diff(left any, right any, opts ...Option) error {
options := options{}
for _, opt := range opts {
opt.apply(&options)
}

if options.onEvent == nil {
panic("the option diff.OnEvent(...) must always be defined")
return fmt.Errorf("the option diff.OnEvent(...) must always be defined")
}

reporter := &diffReporter{notify: options.onEvent}
cmp.Equal(left, right, append(
[]cmp.Option{cmp.Reporter(reporter)},
options.cmpOptions...,
)...)
return nil
}

type diffReporter struct {
Expand Down
4 changes: 2 additions & 2 deletions diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ func TestDiff_EventMatch(t *testing.T) {
// only single event but starts to act weirdly when there > 1, like the Event's Path is all wrong. It's
// better to try to avoid it when possible.
func accumulateDiff(left, right any) (out []Event) {
Diff(left, right, OnEvent(func(event Event) {
_ = Diff(left, right, OnEvent(func(event Event) {
out = append(out, event)
}))
return
}

func accumulateDiffStrings(left, right any) (out []string) {
Diff(left, right, OnEvent(func(event Event) {
_ = Diff(left, right, OnEvent(func(event Event) {
out = append(out, eventToString(&event))
}))
return
Expand Down
10 changes: 7 additions & 3 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,22 @@ func (k PrivateKey) Sign(payload []byte) (Signature, error) {
return signature, err
}

func (k PrivateKey) PublicKey() PublicKey {
func (k PrivateKey) PublicKeyOrErr() (PublicKey, error) {
if err := k.Validate(); err != nil {
panic(err)
return PublicKey{}, err
}

p := voied25519.PrivateKey(k)
pub := p.Public().(voied25519.PublicKey)

var publicKey PublicKey
copy(publicKey[:], pub)
return publicKey, nil
}

return publicKey
func (k PrivateKey) PublicKey() PublicKey {
pub, _ := k.PublicKeyOrErr()
return pub
}

// PK is a convenience alias for PublicKey
Expand Down
2 changes: 1 addition & 1 deletion transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func (tx *Transaction) String() string {
buf := new(bytes.Buffer)
_, err := tx.EncodeTree(text.NewTreeEncoder(buf, ""))
if err != nil {
panic(err)
return fmt.Sprintf("<transaction encoding error: %s>", err)
}
return buf.String()
}
Expand Down