Skip to content

Commit

Permalink
Add failed broadcast transactions on send error`
Browse files Browse the repository at this point in the history
  • Loading branch information
someone235 committed Sep 18, 2024
1 parent 89c932d commit af93d5f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion cmd/kaspawallet/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/client"
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/server"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func broadcast(conf *broadcastConfig) error {
transactionsHex = strings.TrimSpace(string(transactionHexBytes))
}

transactions, err := decodeTransactionsFromHex(transactionsHex)
transactions, err := server.DecodeTransactionsFromHex(transactionsHex)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/kaspawallet/broadcast_replacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/client"
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/server"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func broadcastReplacement(conf *broadcastConfig) error {
transactionsHex = strings.TrimSpace(string(transactionHexBytes))
}

transactions, err := decodeTransactionsFromHex(transactionsHex)
transactions, err := server.DecodeTransactionsFromHex(transactionsHex)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/kaspawallet/bump_fee_unsigned.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/client"
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/server"
)

func bumpFeeUnsigned(conf *bumpFeeUnsignedConfig) error {
Expand Down Expand Up @@ -51,7 +52,7 @@ func bumpFeeUnsigned(conf *bumpFeeUnsignedConfig) error {
}

fmt.Fprintln(os.Stderr, "Created unsigned transaction")
fmt.Println(encodeTransactionsToHex(response.Transactions))
fmt.Println(server.EncodeTransactionsToHex(response.Transactions))

return nil
}
3 changes: 2 additions & 1 deletion cmd/kaspawallet/create_unsigned_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/client"
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/server"
"github.com/kaspanet/kaspad/cmd/kaspawallet/utils"
)

Expand Down Expand Up @@ -59,7 +60,7 @@ func createUnsignedTransaction(conf *createUnsignedTransactionConfig) error {
}

fmt.Fprintln(os.Stderr, "Created unsigned transaction")
fmt.Println(encodeTransactionsToHex(response.UnsignedTransactions))
fmt.Println(server.EncodeTransactionsToHex(response.UnsignedTransactions))

return nil
}
3 changes: 2 additions & 1 deletion cmd/kaspawallet/daemon/server/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/pb"
"github.com/pkg/errors"
)

func (s *server) Send(_ context.Context, request *pb.SendRequest) (*pb.SendResponse, error) {
Expand All @@ -24,7 +25,7 @@ func (s *server) Send(_ context.Context, request *pb.SendRequest) (*pb.SendRespo

txIDs, err := s.broadcast(signedTransactions, false)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "error broadcasting transactions %s", EncodeTransactionsToHex(signedTransactions))
}

return &pb.SendResponse{TxIDs: txIDs, SignedTransactions: signedTransactions}, nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"encoding/hex"
Expand All @@ -9,15 +9,15 @@ import (
// We use a separator that is not in the hex alphabet, but which will not split selection with a double click
const hexTransactionsSeparator = "_"

func encodeTransactionsToHex(transactions [][]byte) string {
func EncodeTransactionsToHex(transactions [][]byte) string {
transactionsInHex := make([]string, len(transactions))
for i, transaction := range transactions {
transactionsInHex[i] = hex.EncodeToString(transaction)
}
return strings.Join(transactionsInHex, hexTransactionsSeparator)
}

func decodeTransactionsFromHex(transactionsHex string) ([][]byte, error) {
func DecodeTransactionsFromHex(transactionsHex string) ([][]byte, error) {
splitTransactionsHexes := strings.Split(transactionsHex, hexTransactionsSeparator)
transactions := make([][]byte, len(splitTransactionsHexes))

Expand Down
2 changes: 1 addition & 1 deletion cmd/kaspawallet/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func parse(conf *parseConfig) error {
transactionHex = strings.TrimSpace(string(transactionHexBytes))
}

transactions, err := decodeTransactionsFromHex(transactionHex)
transactions, err := server.DecodeTransactionsFromHex(transactionHex)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/kaspawallet/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"strings"

"github.com/kaspanet/kaspad/cmd/kaspawallet/daemon/server"
"github.com/kaspanet/kaspad/cmd/kaspawallet/keys"
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet"
"github.com/pkg/errors"
Expand Down Expand Up @@ -40,7 +41,7 @@ func sign(conf *signConfig) error {
}
transactionsHex = strings.TrimSpace(string(transactionHexBytes))
}
partiallySignedTransactions, err := decodeTransactionsFromHex(transactionsHex)
partiallySignedTransactions, err := server.DecodeTransactionsFromHex(transactionsHex)
if err != nil {
return err
}
Expand Down Expand Up @@ -72,6 +73,6 @@ func sign(conf *signConfig) error {
fmt.Fprintln(os.Stderr, "Successfully signed transaction")
}

fmt.Println(encodeTransactionsToHex(updatedPartiallySignedTransactions))
fmt.Println(server.EncodeTransactionsToHex(updatedPartiallySignedTransactions))
return nil
}

0 comments on commit af93d5f

Please sign in to comment.