Skip to content

Commit 88f2a96

Browse files
committed
Set fullTx option in constructor
1 parent dba9b83 commit 88f2a96

3 files changed

Lines changed: 17 additions & 19 deletions

File tree

‎rpc/api.go‎

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
113113
return err
114114
}
115115

116-
block := NewBlockRes(api.xeth().EthBlockByHash(args.BlockHash))
116+
block := NewBlockRes(api.xeth().EthBlockByHash(args.BlockHash), false)
117117
*reply = common.ToHex(big.NewInt(int64(len(block.Transactions))).Bytes())
118118
case "eth_getBlockTransactionCountByNumber":
119119
args := new(GetBlockByNumberArgs)
120120
if err := json.Unmarshal(req.Params, &args); err != nil {
121121
return err
122122
}
123123

124-
block := NewBlockRes(api.xeth().EthBlockByNumber(args.BlockNumber))
124+
block := NewBlockRes(api.xeth().EthBlockByNumber(args.BlockNumber), false)
125125
*reply = common.ToHex(big.NewInt(int64(len(block.Transactions))).Bytes())
126126
case "eth_getUncleCountByBlockHash":
127127
args := new(GetBlockByHashArgs)
@@ -130,7 +130,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
130130
}
131131

132132
block := api.xeth().EthBlockByHash(args.BlockHash)
133-
br := NewBlockRes(block)
133+
br := NewBlockRes(block, false)
134134
*reply = common.ToHex(big.NewInt(int64(len(br.Uncles))).Bytes())
135135
case "eth_getUncleCountByBlockNumber":
136136
args := new(GetBlockByNumberArgs)
@@ -139,7 +139,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
139139
}
140140

141141
block := api.xeth().EthBlockByNumber(args.BlockNumber)
142-
br := NewBlockRes(block)
142+
br := NewBlockRes(block, false)
143143
*reply = common.ToHex(big.NewInt(int64(len(br.Uncles))).Bytes())
144144
case "eth_getData", "eth_getCode":
145145
args := new(GetDataArgs)
@@ -179,8 +179,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
179179
}
180180

181181
block := api.xeth().EthBlockByHash(args.BlockHash)
182-
br := NewBlockRes(block)
183-
br.fullTx = args.IncludeTxs
182+
br := NewBlockRes(block, true)
184183

185184
*reply = br
186185
case "eth_getBlockByNumber":
@@ -190,8 +189,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
190189
}
191190

192191
block := api.xeth().EthBlockByNumber(args.BlockNumber)
193-
br := NewBlockRes(block)
194-
br.fullTx = args.IncludeTxs
192+
br := NewBlockRes(block, true)
195193

196194
*reply = br
197195
case "eth_getTransactionByHash":
@@ -214,8 +212,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
214212
}
215213

216214
block := api.xeth().EthBlockByHash(args.Hash)
217-
br := NewBlockRes(block)
218-
br.fullTx = true
215+
br := NewBlockRes(block, true)
219216

220217
if args.Index >= int64(len(br.Transactions)) || args.Index < 0 {
221218
return NewValidationError("Index", "does not exist")
@@ -228,8 +225,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
228225
}
229226

230227
block := api.xeth().EthBlockByNumber(args.BlockNumber)
231-
v := NewBlockRes(block)
232-
v.fullTx = true
228+
v := NewBlockRes(block, true)
233229

234230
if args.Index >= int64(len(v.Transactions)) || args.Index < 0 {
235231
return NewValidationError("Index", "does not exist")
@@ -241,14 +237,14 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
241237
return err
242238
}
243239

244-
br := NewBlockRes(api.xeth().EthBlockByHash(args.Hash))
240+
br := NewBlockRes(api.xeth().EthBlockByHash(args.Hash), false)
245241

246242
if args.Index >= int64(len(br.Uncles)) || args.Index < 0 {
247243
return NewValidationError("Index", "does not exist")
248244
}
249245

250246
uhash := br.Uncles[args.Index]
251-
uncle := NewBlockRes(api.xeth().EthBlockByHash(uhash.String()))
247+
uncle := NewBlockRes(api.xeth().EthBlockByHash(uhash.String()), false)
252248

253249
*reply = uncle
254250
case "eth_getUncleByBlockNumberAndIndex":
@@ -258,15 +254,14 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
258254
}
259255

260256
block := api.xeth().EthBlockByNumber(args.BlockNumber)
261-
v := NewBlockRes(block)
262-
v.fullTx = true
257+
v := NewBlockRes(block, true)
263258

264259
if args.Index >= int64(len(v.Uncles)) || args.Index < 0 {
265260
return NewValidationError("Index", "does not exist")
266261
}
267262

268263
uhash := v.Uncles[args.Index]
269-
uncle := NewBlockRes(api.xeth().EthBlockByHash(uhash.String()))
264+
uncle := NewBlockRes(api.xeth().EthBlockByHash(uhash.String()), false)
270265

271266
*reply = uncle
272267
case "eth_getCompilers":

‎rpc/responses.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ type BlockRes struct {
2929
Uncles []*hexdata `json:"uncles"`
3030
}
3131

32-
func NewBlockRes(block *types.Block) *BlockRes {
32+
func NewBlockRes(block *types.Block, fullTx bool) *BlockRes {
33+
// TODO respect fullTx flag
34+
3335
if block == nil {
3436
return &BlockRes{}
3537
}
3638

3739
res := new(BlockRes)
40+
res.fullTx = fullTx
3841
res.BlockNumber = newHexNum(block.Number())
3942
res.BlockHash = newHexData(block.Hash())
4043
res.ParentHash = newHexData(block.ParentHash())

‎rpc/responses_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestNewBlockRes(t *testing.T) {
4949
"timestamp": reNum,
5050
}
5151

52-
v := NewBlockRes(block)
52+
v := NewBlockRes(block, false)
5353
j, _ := json.Marshal(v)
5454

5555
for k, re := range tests {

0 commit comments

Comments
 (0)