@@ -81,6 +81,8 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
8181 err := ec .c .CallContext (ctx , & raw , method , args ... )
8282 if err != nil {
8383 return nil , err
84+ } else if len (raw ) == 0 {
85+ return nil , ethereum .NotFound
8486 }
8587 // Decode header and transactions.
8688 var head * types.Header
@@ -135,6 +137,9 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
135137func (ec * Client ) HeaderByHash (ctx context.Context , hash common.Hash ) (* types.Header , error ) {
136138 var head * types.Header
137139 err := ec .c .CallContext (ctx , & head , "eth_getBlockByHash" , hash , false )
140+ if err == nil && head == nil {
141+ err = ethereum .NotFound
142+ }
138143 return head , err
139144}
140145
@@ -143,19 +148,31 @@ func (ec *Client) HeaderByHash(ctx context.Context, hash common.Hash) (*types.He
143148func (ec * Client ) HeaderByNumber (ctx context.Context , number * big.Int ) (* types.Header , error ) {
144149 var head * types.Header
145150 err := ec .c .CallContext (ctx , & head , "eth_getBlockByNumber" , toBlockNumArg (number ), false )
151+ if err == nil && head == nil {
152+ err = ethereum .NotFound
153+ }
146154 return head , err
147155}
148156
149157// TransactionByHash returns the transaction with the given hash.
150- func (ec * Client ) TransactionByHash (ctx context.Context , hash common.Hash ) (* types.Transaction , error ) {
151- var tx * types. Transaction
152- err : = ec .c .CallContext (ctx , & tx , "eth_getTransactionByHash" , hash )
153- if err = = nil {
154- if _ , r , _ := tx . RawSignatureValues (); r == nil {
155- return nil , fmt . Errorf ( "server returned transaction without signature" )
156- }
158+ func (ec * Client ) TransactionByHash (ctx context.Context , hash common.Hash ) (tx * types.Transaction , isPending bool , err error ) {
159+ var raw json. RawMessage
160+ err = ec .c .CallContext (ctx , & raw , "eth_getTransactionByHash" , hash )
161+ if err ! = nil {
162+ return nil , false , err
163+ } else if len ( raw ) == 0 {
164+ return nil , false , ethereum . NotFound
157165 }
158- return tx , err
166+ if err := json .Unmarshal (raw , tx ); err != nil {
167+ return nil , false , err
168+ } else if _ , r , _ := tx .RawSignatureValues (); r == nil {
169+ return nil , false , fmt .Errorf ("server returned transaction without signature" )
170+ }
171+ var block struct { BlockHash * common.Hash }
172+ if err := json .Unmarshal (raw , & block ); err != nil {
173+ return nil , false , err
174+ }
175+ return tx , block .BlockHash == nil , nil
159176}
160177
161178// TransactionCount returns the total number of transactions in the given block.
@@ -170,11 +187,9 @@ func (ec *Client) TransactionInBlock(ctx context.Context, blockHash common.Hash,
170187 var tx * types.Transaction
171188 err := ec .c .CallContext (ctx , & tx , "eth_getTransactionByBlockHashAndIndex" , blockHash , index )
172189 if err == nil {
173- var signer types.Signer = types.HomesteadSigner {}
174- if tx .Protected () {
175- signer = types .NewEIP155Signer (tx .ChainId ())
176- }
177- if _ , r , _ := types .SignatureValues (signer , tx ); r == nil {
190+ if tx == nil {
191+ return nil , ethereum .NotFound
192+ } else if _ , r , _ := tx .RawSignatureValues (); r == nil {
178193 return nil , fmt .Errorf ("server returned transaction without signature" )
179194 }
180195 }
@@ -186,8 +201,12 @@ func (ec *Client) TransactionInBlock(ctx context.Context, blockHash common.Hash,
186201func (ec * Client ) TransactionReceipt (ctx context.Context , txHash common.Hash ) (* types.Receipt , error ) {
187202 var r * types.Receipt
188203 err := ec .c .CallContext (ctx , & r , "eth_getTransactionReceipt" , txHash )
189- if err == nil && r != nil && len (r .PostState ) == 0 {
190- return nil , fmt .Errorf ("server returned receipt without post state" )
204+ if err == nil {
205+ if r == nil {
206+ return nil , ethereum .NotFound
207+ } else if len (r .PostState ) == 0 {
208+ return nil , fmt .Errorf ("server returned receipt without post state" )
209+ }
191210 }
192211 return r , err
193212}
0 commit comments