Fix prints and use batches also for send operation

This commit is contained in:
msutton 2022-07-16 22:27:20 +03:00
parent ee5dacc72e
commit e2cb414301
2 changed files with 13 additions and 8 deletions

View File

@ -42,6 +42,15 @@ func broadcast(conf *broadcastConfig) error {
return err return err
} }
err = broadcastInBatches(ctx, daemonClient, transactions)
if err != nil {
return err
}
return nil
}
func broadcastInBatches(ctx context.Context, daemonClient pb.KaspawalletdClient, transactions [][]byte) error {
const batch = 50 const batch = 50
position := 0 position := 0
@ -57,8 +66,10 @@ func broadcast(conf *broadcastConfig) error {
if err != nil { if err != nil {
return err return err
} }
if position == 0 { if position == 0 && position+batch >= len(transactions) {
fmt.Println("Transactions were sent successfully") fmt.Println("Transactions were sent successfully")
} else {
fmt.Println("Transaction batch was sent successfully")
} }
fmt.Println("Transaction ID(s): ") fmt.Println("Transaction ID(s): ")
for _, txID := range response.TxIDs { for _, txID := range response.TxIDs {
@ -66,6 +77,5 @@ func broadcast(conf *broadcastConfig) error {
} }
position += batch position += batch
} }
return nil return nil
} }

View File

@ -64,15 +64,10 @@ func send(conf *sendConfig) error {
fmt.Printf("Broadcasting %d transactions\n", len(signedTransactions)) fmt.Printf("Broadcasting %d transactions\n", len(signedTransactions))
} }
response, err := daemonClient.Broadcast(ctx, &pb.BroadcastRequest{Transactions: signedTransactions}) err = broadcastInBatches(ctx, daemonClient, signedTransactions)
if err != nil { if err != nil {
return err return err
} }
fmt.Println("Transactions were sent successfully")
fmt.Println("Transaction ID(s): ")
for _, txID := range response.TxIDs {
fmt.Printf("\t%s\n", txID)
}
return nil return nil
} }