(ctx context.Context, method string, args ...interface{})
| 88 | } |
| 89 | |
| 90 | func (c *Client) getBlock(ctx context.Context, method string, args ...interface{}) (*types.Block, error) { |
| 91 | var raw json.RawMessage |
| 92 | err := c.c.CallContext(ctx, &raw, method, args...) |
| 93 | if err != nil { |
| 94 | return nil, err |
| 95 | } else if len(raw) == 0 { |
| 96 | return nil, cpchain.NotFound |
| 97 | } |
| 98 | // Decode header and transactions. |
| 99 | var head *types.Header |
| 100 | var body rpcBlock |
| 101 | if err := json.Unmarshal(raw, &head); err != nil { |
| 102 | return nil, err |
| 103 | } |
| 104 | if err := json.Unmarshal(raw, &body); err != nil { |
| 105 | return nil, err |
| 106 | } |
| 107 | // Quick-verify transaction and uncle lists. This mostly helps with debugging the server. |
| 108 | if head.TxsRoot == types.EmptyRootHash && len(body.Transactions) > 0 { |
| 109 | return nil, fmt.Errorf("server returned non-empty transaction list but block header indicates no transactions") |
| 110 | } |
| 111 | if head.TxsRoot != types.EmptyRootHash && len(body.Transactions) == 0 { |
| 112 | return nil, fmt.Errorf("server returned empty transaction list but block header indicates transactions") |
| 113 | } |
| 114 | |
| 115 | // Fill the sender cache of transactions in the block. |
| 116 | txs := make([]*types.Transaction, len(body.Transactions)) |
| 117 | for i, tx := range body.Transactions { |
| 118 | if tx.From != nil { |
| 119 | setSenderFromServer(tx.tx, *tx.From, body.Hash) |
| 120 | } |
| 121 | txs[i] = tx.tx |
| 122 | } |
| 123 | return types.NewBlockWithHeader(head).WithBody(txs), nil |
| 124 | } |
| 125 | |
| 126 | // HeaderByHash returns the block header with the given hash. |
| 127 | func (c *Client) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { |
no test coverage detected