@@ -81,6 +81,8 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
81
81
err := ec .c .CallContext (ctx , & raw , method , args ... )
82
82
if err != nil {
83
83
return nil , err
84
+ } else if len (raw ) == 0 {
85
+ return nil , ethereum .NotFound
84
86
}
85
87
// Decode header and transactions.
86
88
var head * types.Header
@@ -135,6 +137,9 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
135
137
func (ec * Client ) HeaderByHash (ctx context.Context , hash common.Hash ) (* types.Header , error ) {
136
138
var head * types.Header
137
139
err := ec .c .CallContext (ctx , & head , "eth_getBlockByHash" , hash , false )
140
+ if err == nil && head == nil {
141
+ err = ethereum .NotFound
142
+ }
138
143
return head , err
139
144
}
140
145
@@ -143,19 +148,31 @@ func (ec *Client) HeaderByHash(ctx context.Context, hash common.Hash) (*types.He
143
148
func (ec * Client ) HeaderByNumber (ctx context.Context , number * big.Int ) (* types.Header , error ) {
144
149
var head * types.Header
145
150
err := ec .c .CallContext (ctx , & head , "eth_getBlockByNumber" , toBlockNumArg (number ), false )
151
+ if err == nil && head == nil {
152
+ err = ethereum .NotFound
153
+ }
146
154
return head , err
147
155
}
148
156
149
157
// 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
157
165
}
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
159
176
}
160
177
161
178
// 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,
170
187
var tx * types.Transaction
171
188
err := ec .c .CallContext (ctx , & tx , "eth_getTransactionByBlockHashAndIndex" , blockHash , index )
172
189
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 {
178
193
return nil , fmt .Errorf ("server returned transaction without signature" )
179
194
}
180
195
}
@@ -186,8 +201,12 @@ func (ec *Client) TransactionInBlock(ctx context.Context, blockHash common.Hash,
186
201
func (ec * Client ) TransactionReceipt (ctx context.Context , txHash common.Hash ) (* types.Receipt , error ) {
187
202
var r * types.Receipt
188
203
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
+ }
191
210
}
192
211
return r , err
193
212
}
0 commit comments