github.com/core-coin/go-core/v2@v2.1.9/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/v2/common" 24 "github.com/core-coin/go-core/v2/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 networkID int 34 } 35 36 var errNotCached = errors.New("sender not cached") 37 38 func setSenderFromServer(tx *types.Transaction, addr common.Address, block common.Hash, networkID int) { 39 // Use types.Sender for side-effect to store our signer into the cache. 40 types.Sender(&senderFromServer{addr, block, networkID}, tx) 41 } 42 43 func (s *senderFromServer) Equal(other types.Signer) bool { 44 os, ok := other.(*senderFromServer) 45 return ok && os.blockhash == s.blockhash 46 } 47 48 func (s *senderFromServer) Sender(tx *types.Transaction) (common.Address, error) { 49 if s.blockhash == (common.Hash{}) { 50 return common.Address{}, errNotCached 51 } 52 if int(tx.NetworkID()) != int(s.networkID) { 53 return common.Address{}, types.ErrInvalidNetworkId 54 } 55 return s.addr, nil 56 } 57 58 func (s *senderFromServer) NetworkID() int { 59 return s.networkID 60 } 61 62 func (s *senderFromServer) Hash(tx *types.Transaction) common.Hash { 63 panic("can't sign with senderFromServer") 64 } 65 func (s *senderFromServer) SignatureValues(tx *types.Transaction, sig []byte) (R, S, V *big.Int, err error) { 66 panic("can't sign with senderFromServer") 67 }