Skip to content

Commit

Permalink
services/friendbot: include txhash in logs (#4359)
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored Apr 29, 2022
1 parent d40d8fc commit bb2eca3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions services/friendbot/internal/minion.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (minion *Minion) Run(destAddress string, resultChan chan SubmitResult) {
}
return
}
txStr, err := minion.makeTx(destAddress)
txHash, txStr, err := minion.makeTx(destAddress)
if err != nil {
resultChan <- SubmitResult{
maybeTransactionSuccess: nil,
Expand All @@ -55,7 +55,7 @@ func (minion *Minion) Run(destAddress string, resultChan chan SubmitResult) {
succ, err := minion.SubmitTransaction(minion, minion.Horizon, txStr)
resultChan <- SubmitResult{
maybeTransactionSuccess: succ,
maybeErr: errors.Wrap(err, "submitting tx to minion"),
maybeErr: errors.Wrapf(err, "submitting tx to minion %x", txHash),
}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func (minion *Minion) checkHandleBadSequence(err *horizonclient.Error) {
minion.forceRefreshSequence = true
}

func (minion *Minion) makeTx(destAddress string) (string, error) {
func (minion *Minion) makeTx(destAddress string) ([32]byte, string, error) {
createAccountOp := txnbuild.CreateAccount{
Destination: destAddress,
SourceAccount: minion.BotAccount.GetAccountID(),
Expand All @@ -121,23 +121,28 @@ func (minion *Minion) makeTx(destAddress string) (string, error) {
},
)
if err != nil {
return "", errors.Wrap(err, "unable to build tx")
return [32]byte{}, "", errors.Wrap(err, "unable to build tx")
}

tx, err = tx.Sign(minion.Network, minion.Keypair, minion.BotKeypair)
if err != nil {
return "", errors.Wrap(err, "unable to sign tx")
return [32]byte{}, "", errors.Wrap(err, "unable to sign tx")
}

txe, err := tx.Base64()
if err != nil {
return "", errors.Wrap(err, "unable to serialize")
return [32]byte{}, "", errors.Wrap(err, "unable to serialize")
}

txh, err := tx.Hash(minion.Network)
if err != nil {
return [32]byte{}, "", errors.Wrap(err, "unable to hash")
}

// Increment the in-memory sequence number, since the tx will be submitted.
_, err = minion.Account.IncrementSequenceNumber()
if err != nil {
return "", errors.Wrap(err, "incrementing minion seq")
return [32]byte{}, "", errors.Wrap(err, "incrementing minion seq")
}
return txe, err
return txh, txe, err
}

0 comments on commit bb2eca3

Please sign in to comment.