signer.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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) Hash(tx *types.Transaction) common.Hash {
  46. panic("can't sign with senderFromServer")
  47. }
  48. func (s *senderFromServer) SignatureValues(tx *types.Transaction, sig []byte) (R, S, V *big.Int, err error) {
  49. panic("can't sign with senderFromServer")
  50. }