Skip to content

Commit

Permalink
Merge pull request #14 from objkt-com/feat/rpc
Browse files Browse the repository at this point in the history
feat(rpc): add get_balance/2
  • Loading branch information
Awea authored Jun 11, 2024
2 parents cdaf44f + 8437323 commit 2362964
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()}
Expand Down

0 comments on commit 2362964

Please sign in to comment.