github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/ethclient/signer.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:39</date> 10 //</624342638811680768> 11 12 13 package ethclient 14 15 import ( 16 "errors" 17 "math/big" 18 19 "github.com/ethereum/go-ethereum/common" 20 "github.com/ethereum/go-ethereum/core/types" 21 ) 22 23 //senderFromserver是一个类型。签名者记住由RPC返回的发件人地址 24 //服务器。它存储在事务的发送方地址缓存中,以避免 25 //TransactionSender中的请求。 26 type senderFromServer struct { 27 addr common.Address 28 blockhash common.Hash 29 } 30 31 var errNotCached = errors.New("sender not cached") 32 33 func setSenderFromServer(tx *types.Transaction, addr common.Address, block common.Hash) { 34 //使用types.sender作为副作用将签名者存储到缓存中。 35 types.Sender(&senderFromServer{addr, block}, tx) 36 } 37 38 func (s *senderFromServer) Equal(other types.Signer) bool { 39 os, ok := other.(*senderFromServer) 40 return ok && os.blockhash == s.blockhash 41 } 42 43 func (s *senderFromServer) Sender(tx *types.Transaction) (common.Address, error) { 44 if s.blockhash == (common.Hash{}) { 45 return common.Address{}, errNotCached 46 } 47 return s.addr, nil 48 } 49 50 func (s *senderFromServer) Hash(tx *types.Transaction) common.Hash { 51 panic("can't sign with senderFromServer") 52 } 53 func (s *senderFromServer) SignatureValues(tx *types.Transaction, sig []byte) (R, S, V *big.Int, err error) { 54 panic("can't sign with senderFromServer") 55 } 56