Skip to content

Commit c1b2e1b

Browse files
committed
json response
1 parent ace03ec commit c1b2e1b

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

ethereum/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func toBlockNumArg(number *big.Int) string {
207207
}
208208

209209
// Transaction returns the transaction response of the Transaction identified
210-
// by *RosettaTypes.TransactionIdentifier hash or index
210+
// by *RosettaTypes.TransactionIdentifier hash
211211
func (ec *Client) Transaction(
212212
ctx context.Context,
213213
blockIdentifier *RosettaTypes.BlockIdentifier,
@@ -284,7 +284,7 @@ func (ec *Client) Transaction(
284284
}
285285
return tx, nil
286286
}
287-
return nil, errors.New("unimplemented")
287+
return nil, errors.New("transaction hash is required")
288288
}
289289

290290
// Block returns a populated block at the *RosettaTypes.PartialBlockIdentifier.

ethereum/client_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,20 @@ func TestBlock_Index(t *testing.T) {
13921392
mockGraphQL.AssertExpectations(t)
13931393
}
13941394

1395+
func jsonifyTransaction(b *RosettaTypes.Transaction) (*RosettaTypes.Transaction, error) {
1396+
bytes, err := json.Marshal(b)
1397+
if err != nil {
1398+
return nil, err
1399+
}
1400+
1401+
var tx RosettaTypes.Transaction
1402+
if err := json.Unmarshal(bytes, &tx); err != nil {
1403+
return nil, err
1404+
}
1405+
1406+
return &tx, nil
1407+
}
1408+
13951409
func jsonifyBlock(b *RosettaTypes.Block) (*RosettaTypes.Block, error) {
13961410
bytes, err := json.Marshal(b)
13971411
if err != nil {
@@ -1529,9 +1543,12 @@ func TestTransaction_Hash(t *testing.T) {
15291543
Hash: "0x9cc8e6a09ae9cbdb7da77515110a8e343a945df4269c53842dd26969d32c6cc4",
15301544
},
15311545
)
1532-
assert.Equal(t, correct.Transaction, resp)
15331546
assert.NoError(t, err)
15341547

1548+
jsonResp, err := jsonifyTransaction(resp)
1549+
assert.NoError(t, err)
1550+
assert.Equal(t, correct.Transaction, jsonResp)
1551+
15351552
mockJSONRPC.AssertExpectations(t)
15361553
mockGraphQL.AssertExpectations(t)
15371554
}

0 commit comments

Comments
 (0)