Skip to content

Commit 2b4a5f2

Browse files
slumber1122fjl
authored andcommitted
internal/ethapi: remove code duplication around tx sending (#15158)
1 parent d6a6180 commit 2b4a5f2

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

internal/ethapi/api.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,10 @@ func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
10811081
}
10821082
if tx.To() == nil {
10831083
signer := types.MakeSigner(b.ChainConfig(), b.CurrentBlock().Number())
1084-
from, _ := types.Sender(signer, tx)
1084+
from, err := types.Sender(signer, tx)
1085+
if err != nil {
1086+
return common.Hash{}, err
1087+
}
10851088
addr := crypto.CreateAddress(from, tx.Nonce())
10861089
log.Info("Submitted contract creation", "fullhash", tx.Hash().Hex(), "contract", addr.Hex())
10871090
} else {
@@ -1129,29 +1132,12 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
11291132

11301133
// SendRawTransaction will add the signed transaction to the transaction pool.
11311134
// The sender is responsible for signing the transaction and using the correct nonce.
1132-
func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (string, error) {
1135+
func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error) {
11331136
tx := new(types.Transaction)
11341137
if err := rlp.DecodeBytes(encodedTx, tx); err != nil {
1135-
return "", err
1136-
}
1137-
1138-
if err := s.b.SendTx(ctx, tx); err != nil {
1139-
return "", err
1140-
}
1141-
1142-
signer := types.MakeSigner(s.b.ChainConfig(), s.b.CurrentBlock().Number())
1143-
if tx.To() == nil {
1144-
from, err := types.Sender(signer, tx)
1145-
if err != nil {
1146-
return "", err
1147-
}
1148-
addr := crypto.CreateAddress(from, tx.Nonce())
1149-
log.Info("Submitted contract creation", "fullhash", tx.Hash().Hex(), "contract", addr.Hex())
1150-
} else {
1151-
log.Info("Submitted transaction", "fullhash", tx.Hash().Hex(), "recipient", tx.To())
1138+
return common.Hash{}, err
11521139
}
1153-
1154-
return tx.Hash().Hex(), nil
1140+
return submitTransaction(ctx, s.b, tx)
11551141
}
11561142

11571143
// Sign calculates an ECDSA signature for:

0 commit comments

Comments
 (0)