github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/ethclient/signer.go (about)

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