Skip to content

Commit 0c2f982

Browse files
committed
add rpc_api.ex
1 parent 4659646 commit 0c2f982

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

ex/lib/api/rpc_api.ex

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
defmodule RPC.API do
2+
def get(path) do
3+
url = Application.fetch_env!(:ama, :rpc_url)
4+
{:ok, %{status_code: 200, body: body}} = :comsat_http.get(url <> path, %{},
5+
%{ssl_options: [{:server_name_indication, '#{URI.parse(url).host}'}, {:verify, :verify_none}]})
6+
JSX.decode!(body, labels: :attempt_atom)
7+
end
8+
9+
defmodule Wallet do
10+
def transfer(seed64, receiver, amount_float, symbol \\ "AMA") do
11+
tx_packed = API.Wallet.transfer(seed64, receiver, amount_float, symbol, false)
12+
RPC.API.get("/api/tx/submit/#{Base58.encode(tx_packed)}")
13+
end
14+
15+
def balance(pk, symbol \\ "AMA") do
16+
RPC.API.get("/api/wallet/balance/#{pk}/#{symbol}")
17+
end
18+
end
19+
20+
defmodule Chain do
21+
def tx(txid) do
22+
RPC.API.get("/api/chain/tx/#{txid}")
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)