singer.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package dgn
  2. import (
  3. "errors"
  4. "github.com/ethereum/go-ethereum/common"
  5. "github.com/ethereum/go-ethereum/core/types"
  6. "math/big"
  7. )
  8. // senderFromServer is a types.Signer that remembers the sender address returned by the RPC
  9. // server. It is stored in the transaction's sender address cache to avoid an additional
  10. // request in TransactionSender.
  11. type senderFromServer struct {
  12. addr common.Address
  13. blockhash common.Hash
  14. }
  15. var errNotCached = errors.New("sender not cached")
  16. func setSenderFromServer(tx *types.Transaction, addr common.Address, block common.Hash) {
  17. // Use types.Sender for side-effect to store our signer into the cache.
  18. types.Sender(&senderFromServer{addr, block}, tx)
  19. }
  20. func (s *senderFromServer) Equal(other types.Signer) bool {
  21. os, ok := other.(*senderFromServer)
  22. return ok && os.blockhash == s.blockhash
  23. }
  24. func (s *senderFromServer) ChainID() *big.Int {
  25. return big.NewInt(1)
  26. }
  27. func (s *senderFromServer) Sender(tx *types.Transaction) (common.Address, error) {
  28. if s.blockhash == (common.Hash{}) {
  29. return common.Address{}, errNotCached
  30. }
  31. return s.addr, nil
  32. }
  33. func (s *senderFromServer) Hash(tx *types.Transaction) common.Hash {
  34. panic("can't sign with senderFromServer")
  35. }
  36. func (s *senderFromServer) SignatureValues(tx *types.Transaction, sig []byte) (R, S, V *big.Int, err error) {
  37. panic("can't sign with senderFromServer")
  38. }