@@ -587,8 +587,8 @@ func (b *batch) addSweep(ctx context.Context, sweep *sweep) (bool, error) {
587587 // Ensure that all the sweeps in the batch use presigned mode.
588588 for _ , s := range b .sweeps {
589589 if ! s .presigned {
590- b .log (). Infof ("failed to add sweep %x to the " +
591- "batch, because the batch has " +
590+ b .Infof ("failed to add presigned sweep %x to " +
591+ "the batch, because the batch has " +
592592 "non-presigned sweep %x" ,
593593 sweep .swapHash [:6 ], s .swapHash [:6 ])
594594
@@ -598,7 +598,7 @@ func (b *batch) addSweep(ctx context.Context, sweep *sweep) (bool, error) {
598598
599599 if len (b .sweeps ) != 0 {
600600 if err := b .presign (ctx , sweep ); err != nil {
601- b .log (). Infof ("failed to add sweep %x to the " +
601+ b .Infof ("failed to add sweep %x to the " +
602602 "batch, because failed to presign new " +
603603 "version of batch tx: %v" ,
604604 sweep .swapHash [:6 ], err )
@@ -618,9 +618,9 @@ func (b *batch) addSweep(ctx context.Context, sweep *sweep) (bool, error) {
618618 // Ensure that all the sweeps in the batch don't use presigned.
619619 for _ , s := range b .sweeps {
620620 if s .presigned {
621- b .log (). Infof ("failed to add sweep %x to the " +
622- "batch, because the batch has " +
623- "presigned sweep %x" ,
621+ b .Infof ("failed to add a non-presigned sweep " +
622+ "%x to the batch, because the batch " +
623+ "has presigned sweep %x" ,
624624 sweep .swapHash [:6 ], s .swapHash [:6 ])
625625
626626 return false , nil
@@ -927,19 +927,35 @@ func (b *batch) isUrgent(skipBefore time.Time) bool {
927927
928928// isPresigned returns if the batch uses presigned mode. Currently presigned and
929929// non-presigned sweeps never appear in the same batch. Fails if the batch is
930- // empty.
930+ // empty or contains both presigned and regular sweeps .
931931func (b * batch ) isPresigned () (bool , error ) {
932- if len (b .sweeps ) == 0 {
933- return false , fmt .Errorf ("the batch is empty" )
934- }
932+ var (
933+ hasPresigned bool
934+ hasRegular bool
935+ )
935936
936937 for _ , sweep := range b .sweeps {
937938 if sweep .presigned {
938- return true , nil
939+ hasPresigned = true
940+ } else {
941+ hasRegular = true
939942 }
940943 }
941944
942- return false , nil
945+ switch {
946+ case hasPresigned && ! hasRegular :
947+ return true , nil
948+
949+ case ! hasPresigned && hasRegular :
950+ return false , nil
951+
952+ case hasPresigned && hasRegular :
953+ return false , fmt .Errorf ("the batch has both presigned and " +
954+ "non-presigned sweeps" )
955+
956+ default :
957+ return false , fmt .Errorf ("the batch is empty" )
958+ }
943959}
944960
945961// publish creates and publishes the latest batch transaction to the network.
0 commit comments