github.com/core-coin/go-core@v1.1.7/xcbclient/signer.go (about)

     1  // Copyright 2017 by the Authors
     2  // This file is part of the go-core library.
     3  //
     4  // The go-core 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-core 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-core library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package xcbclient
    18  
    19  import (
    20  	"errors"
    21  	"math/big"
    22  
    23  	"github.com/core-coin/go-core/common"
    24  	"github.com/core-coin/go-core/core/types"
    25  )
    26  
    27  // senderFromServer is a types.Signer that remembers the sender address returned by the RPC
    28  // server. It is stored in the transaction's sender address cache to avoid an additional
    29  // request in TransactionSender.
    30  type senderFromServer struct {
    31  	addr      common.Address
    32  	blockhash common.Hash
    33  }
    34  
    35  func (s *senderFromServer) NetworkID() int {
    36  	panic("can't sign with senderFromServer")
    37  }
    38  
    39  var errNotCached = errors.New("sender not cached")
    40  
    41  func setSenderFromServer(tx *types.Transaction, addr common.Address, block common.Hash) {
    42  	// Use types.Sender for side-effect to store our signer into the cache.
    43  	types.Sender(&senderFromServer{addr, block}, tx)
    44  }
    45  
    46  func (s *senderFromServer) Equal(other types.Signer) bool {
    47  	os, ok := other.(*senderFromServer)
    48  	return ok && os.blockhash == s.blockhash
    49  }
    50  
    51  func (s *senderFromServer) Sender(tx *types.Transaction) (common.Address, error) {
    52  	if s.blockhash == (common.Hash{}) {
    53  		return common.Address{}, errNotCached
    54  	}
    55  	return s.addr, nil
    56  }
    57  
    58  func (s *senderFromServer) Hash(tx *types.Transaction) common.Hash {
    59  	panic("can't sign with senderFromServer")
    60  }
    61  func (s *senderFromServer) SignatureValues(tx *types.Transaction, sig []byte) (R, S, V *big.Int, err error) {
    62  	panic("can't sign with senderFromServer")
    63  }