github.com/klaytn/klaytn@v1.12.1/client/signer.go (about) 1 // Modifications Copyright 2018 The klaytn Authors 2 // Copyright 2017 The go-ethereum Authors 3 // This file is part of go-ethereum. 4 // 5 // go-ethereum is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // go-ethereum is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 // This file is derived from ethclient/signer.go (2018/06/04). 19 // Modified and improved for the klaytn development. 20 21 package client 22 23 import ( 24 "crypto/ecdsa" 25 "errors" 26 "math/big" 27 28 "github.com/klaytn/klaytn/blockchain/types" 29 "github.com/klaytn/klaytn/common" 30 ) 31 32 // senderFromServer is a types.Signer that remembers the sender address returned by the RPC 33 // server. It is stored in the transaction's sender address cache to avoid an additional 34 // request in TransactionSender. 35 type senderFromServer struct { 36 addr common.Address 37 blockhash common.Hash 38 } 39 40 var errNotCached = errors.New("sender not cached") 41 42 func setSenderFromServer(tx *types.Transaction, addr common.Address, block common.Hash) { 43 // Use types.Sender for side-effect to store our signer into the cache. 44 types.Sender(&senderFromServer{addr, block}, tx) 45 } 46 47 func (s *senderFromServer) Equal(other types.Signer) bool { 48 os, ok := other.(*senderFromServer) 49 return ok && os.blockhash == s.blockhash 50 } 51 52 func (s *senderFromServer) Sender(tx *types.Transaction) (common.Address, error) { 53 if s.blockhash == (common.Hash{}) { 54 return common.Address{}, errNotCached 55 } 56 return s.addr, nil 57 } 58 59 func (s *senderFromServer) ChainID() *big.Int { 60 // TODO-Klaytn: need to check this routine is never called or not. 61 // `senderFromServer` is only used in klay_client.go. 62 panic("ChainID should not be called!") 63 } 64 65 func (s *senderFromServer) SenderPubkey(tx *types.Transaction) ([]*ecdsa.PublicKey, error) { 66 // TODO-Klaytn: need to check this routine is never called or not. 67 // `senderFromServer` is only used in klay_client.go. 68 panic("SenderPubkey should not be called!") 69 } 70 71 func (s *senderFromServer) SenderFeePayer(tx *types.Transaction) ([]*ecdsa.PublicKey, error) { 72 // TODO-Klaytn: need to check this routine is never called or not. 73 // `senderFromServer` is only used in klay_client.go. 74 panic("SenderFeePayer should not be called!") 75 } 76 77 func (s *senderFromServer) Hash(tx *types.Transaction) common.Hash { 78 // TODO-Klaytn: need to check this routine is never called or not. 79 // `senderFromServer` is only used in klay_client.go. 80 panic("can't sign with senderFromServer") 81 } 82 83 func (s *senderFromServer) HashFeePayer(tx *types.Transaction) (common.Hash, error) { 84 // TODO-Klaytn: need to check this routine is never called or not. 85 // `senderFromServer` is only used in klay_client.go. 86 panic("can't sign with senderFromServer") 87 } 88 89 func (s *senderFromServer) SignatureValues(tx *types.Transaction, sig []byte) (R, S, V *big.Int, err error) { 90 // TODO-Klaytn: need to check this routine is never called or not. 91 // `senderFromServer` is only used in klay_client.go. 92 panic("can't sign with senderFromServer") 93 }