-
Notifications
You must be signed in to change notification settings - Fork 14
/
json_rpc.ex
33 lines (24 loc) · 935 Bytes
/
json_rpc.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
defmodule Ethers.Signer.JsonRPC do
@moduledoc """
Signer capable of signing transactions with a JSON RPC server
capable of `eth_signTransaction` and `eth_accounts` RPC functions.
## Signer Options
- `:rpc_module`: The RPC Module to use. (Optional, Defaults to `Ethereumex.HttpClient`)
- `:url`: The RPC URL to use. (Optional)
** All other options will be passed to the RPC module `request/3` function in
the third argument **
"""
@behaviour Ethers.Signer
alias Ethers.Transaction
@impl true
def sign_transaction(%Transaction{} = tx, opts) do
tx_map = Transaction.to_map(tx)
{rpc_module, opts} = Keyword.pop(opts, :rpc_module, Ethereumex.HttpClient)
rpc_module.request("eth_signTransaction", [tx_map], opts)
end
@impl true
def accounts(opts) do
{rpc_module, opts} = Keyword.pop(opts, :rpc_module, Ethereumex.HttpClient)
rpc_module.request("eth_accounts", [], opts)
end
end