signer.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2017 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package ethclient
  17. import (
  18. "errors"
  19. "math/big"
  20. "github.com/ethereum/go-ethereum/common"
  21. "github.com/ethereum/go-ethereum/core/types"
  22. )
  23. // senderFromServer is a types.Signer that remembers the sender address returned by the RPC
  24. // server. It is stored in the transaction's sender address cache to avoid an additional
  25. // request in TransactionSender.
  26. type senderFromServer struct {
  27. addr common.Address
  28. blockhash common.Hash
  29. }
  30. var errNotCached = errors.New("sender not cached")
  31. func setSenderFromServer(tx *types.Transaction, addr common.Address, block common.Hash) {
  32. // Use types.Sender for side-effect to store our signer into the cache.
  33. types.Sender(&senderFromServer{addr, block}, tx)
  34. }
  35. func (s *senderFromServer) Equal(other types.Signer) bool {
  36. os, ok := other.(*senderFromServer)
  37. return ok && os.blockhash == s.blockhash
  38. }
  39. func (s *senderFromServer) Sender(tx *types.Transaction) (common.Address, error) {
  40. if s.blockhash == (common.Hash{}) {
  41. return common.Address{}, errNotCached
  42. }
  43. return s.addr, nil
  44. }
  45. func (s *senderFromServer) ChainID() *big.Int {
  46. panic("can't sign with senderFromServer")
  47. }
  48. func (s *senderFromServer) Hash(tx *types.Transaction) common.Hash {
  49. panic("can't sign with senderFromServer")
  50. }
  51. func (s *senderFromServer) SignatureValues(tx *types.Transaction, sig []byte) (R, S, V *big.Int, err error) {
  52. panic("can't sign with senderFromServer")
  53. }