Skip to content

Commit e1b3d43

Browse files
author
William Sanches
committed
Add doc to FetchedBeneficiaries
1 parent 512511a commit e1b3d43

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity/fetched_beneficiaries.ex

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,64 @@ defmodule EthereumJSONRPC.Parity.FetchedBeneficiaries do
66
import EthereumJSONRPC, only: [quantity_to_integer: 1]
77

88
@doc """
9-
Converts `responses` to `t/0`.
9+
Converts `responses` to `EthereumJSONRPC.FetchedBeneficiaries.t()`.
10+
11+
responses - List with trace_block responses
12+
id_to_params - Maps request id to query params
13+
14+
## Examples
15+
iex> EthereumJSONRPC.Parity.FetchedBeneficiaries.from_responses(
16+
...> [
17+
...> %{
18+
...> id: 0,
19+
...> result: [
20+
...> %{
21+
...> "action" => %{"author" => "0x1", "rewardType" => "external", "value" => "0x0"},
22+
...> "blockHash" => "0xFFF",
23+
...> "blockNumber" => 12,
24+
...> "result" => nil,
25+
...> "subtraces" => 0,
26+
...> "traceAddress" => [],
27+
...> "transactionHash" => nil,
28+
...> "transactionPosition" => nil,
29+
...> "type" => "reward"
30+
...> },
31+
...> %{
32+
...> "action" => %{"author" => "0x2", "rewardType" => "external", "value" => "0x0"},
33+
...> "blockHash" => "0x52a8d2185282506ce681364d2aa0c085ba45fdeb5d6c0ddec1131617a71ee2ca",
34+
...> "blockHash" => "0xFFF",
35+
...> "blockNumber" => 12,
36+
...> "result" => nil,
37+
...> "subtraces" => 0,
38+
...> "traceAddress" => [],
39+
...> "transactionHash" => nil,
40+
...> "transactionPosition" => nil,
41+
...> "type" => "reward"
42+
...> }
43+
...> ]
44+
...> }
45+
...> ],
46+
...> %{0 => %{block_quantity: "0xC"}}
47+
...> )
48+
%EthereumJSONRPC.FetchedBeneficiaries{
49+
errors: [],
50+
params_set: #MapSet<[
51+
%{
52+
address_hash: "0x1",
53+
address_type: :validator,
54+
block_hash: "0xFFF",
55+
block_number: 12,
56+
reward: "0x0"
57+
},
58+
%{
59+
address_hash: "0x2",
60+
address_type: :emission_funds,
61+
block_hash: "0xFFF",
62+
block_number: 12,
63+
reward: "0x0"
64+
}
65+
]>
66+
}
1067
"""
1168
def from_responses(responses, id_to_params) when is_list(responses) and is_map(id_to_params) do
1269
responses
@@ -102,6 +159,17 @@ defmodule EthereumJSONRPC.Parity.FetchedBeneficiaries do
102159
])
103160
end
104161

162+
# Beneficiary's address type will depend on the responses' action.rewardType,
163+
# which will vary depending on which network is being indexed
164+
#
165+
# On POA networks, rewardType will always be external and the type of the address being
166+
# rewarded will depend on its position.
167+
# First address will always be the validator's while the second will be the EmissionsFunds address
168+
#
169+
# On PoW networks, like Ethereum, the reward type will already specify the type for the
170+
# address being rewarded
171+
# The rewardType "block" will show the reward for the consensus block validator
172+
# The rewardType "uncle" will show reward for validating an uncle block
105173
defp get_address_type(reward_type, index) when reward_type == "external" and index == 0, do: :validator
106174
defp get_address_type(reward_type, index) when reward_type == "external" and index == 1, do: :emission_funds
107175
defp get_address_type(reward_type, _index) when reward_type == "block", do: :validator

0 commit comments

Comments
 (0)