diff options
author | slumber1122 <slumber1122@gmail.com> | 2017-09-25 16:38:42 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-09-25 16:38:42 +0800 |
commit | 2b4a5f2677fdf0d8a34a2d19fddc203b973dfe02 (patch) | |
tree | 9e59037f2489b5baf14695e336a2c7950666ce05 /internal/ethapi | |
parent | d6a6180366e613deaa5ce9c36e80bb0fac5430f6 (diff) | |
download | go-tangerine-2b4a5f2677fdf0d8a34a2d19fddc203b973dfe02.tar go-tangerine-2b4a5f2677fdf0d8a34a2d19fddc203b973dfe02.tar.gz go-tangerine-2b4a5f2677fdf0d8a34a2d19fddc203b973dfe02.tar.bz2 go-tangerine-2b4a5f2677fdf0d8a34a2d19fddc203b973dfe02.tar.lz go-tangerine-2b4a5f2677fdf0d8a34a2d19fddc203b973dfe02.tar.xz go-tangerine-2b4a5f2677fdf0d8a34a2d19fddc203b973dfe02.tar.zst go-tangerine-2b4a5f2677fdf0d8a34a2d19fddc203b973dfe02.zip |
internal/ethapi: remove code duplication around tx sending (#15158)
Diffstat (limited to 'internal/ethapi')
-rw-r--r-- | internal/ethapi/api.go | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 6eb37e684..8d1a6f746 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1081,7 +1081,10 @@ func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c } if tx.To() == nil { signer := types.MakeSigner(b.ChainConfig(), b.CurrentBlock().Number()) - from, _ := types.Sender(signer, tx) + from, err := types.Sender(signer, tx) + if err != nil { + return common.Hash{}, err + } addr := crypto.CreateAddress(from, tx.Nonce()) log.Info("Submitted contract creation", "fullhash", tx.Hash().Hex(), "contract", addr.Hex()) } else { @@ -1129,29 +1132,12 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen // SendRawTransaction will add the signed transaction to the transaction pool. // The sender is responsible for signing the transaction and using the correct nonce. -func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (string, error) { +func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error) { tx := new(types.Transaction) if err := rlp.DecodeBytes(encodedTx, tx); err != nil { - return "", err - } - - if err := s.b.SendTx(ctx, tx); err != nil { - return "", err - } - - signer := types.MakeSigner(s.b.ChainConfig(), s.b.CurrentBlock().Number()) - if tx.To() == nil { - from, err := types.Sender(signer, tx) - if err != nil { - return "", err - } - addr := crypto.CreateAddress(from, tx.Nonce()) - log.Info("Submitted contract creation", "fullhash", tx.Hash().Hex(), "contract", addr.Hex()) - } else { - log.Info("Submitted transaction", "fullhash", tx.Hash().Hex(), "recipient", tx.To()) + return common.Hash{}, err } - - return tx.Hash().Hex(), nil + return submitTransaction(ctx, s.b, tx) } // Sign calculates an ECDSA signature for: |