Skip to content

Commit

Permalink
feat(rpc): add get_balance/2
Browse files Browse the repository at this point in the history
  • Loading branch information
Awea committed Jun 11, 2024
1 parent dfe64d9 commit 8437323
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/rpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ defmodule Tezex.Rpc do
post(rpc, "/injection/operation", payload)
end

@spec get_balance(t(), nonempty_binary()) ::
{:ok, pos_integer()} | {:error, Finch.Error.t()} | {:error, Jason.DecodeError.t()}
def get_balance(%Rpc{} = rpc, address) do
case get(rpc, "/blocks/head/context/contracts/#{address}/balance") do
{:ok, balance} -> {:ok, String.to_integer(balance)}
e -> e
end
end

@spec get(Tezex.Rpc.t(), nonempty_binary()) ::
{:ok, any()} | {:error, Finch.Error.t()} | {:error, Jason.DecodeError.t()}
defp get(%Rpc{} = rpc, path) do
Expand Down

0 comments on commit 8437323

Please sign in to comment.