@@ -2,68 +2,84 @@ defmodule EOSRPC.Wallet do
22 @ moduledoc """
33 EOSRPC Wallet Wrapper for Elixir
44
5- Based on: https://eosio.github.io/eos/group__eosiorpc.html#walletrpc
5+ Based on source code, since there is no documentation for this
6+ https://github.com/EOSIO/eos/blob/master/plugins/wallet_api_plugin/wallet_api_plugin.cpp
67 """
78
9+ use Tesla
10+
811 import EOSRPC
912
13+ plug ( Tesla.Middleware.JSON )
14+ plug ( EOSRPC.Middleware.Error )
15+
1016 @ doc """
1117 List all wallets
1218 """
13- def list , do: "/list_wallets" |> url ( ) |> get_request ( )
19+ def list , do: "/list_wallets" |> url ( ) |> get ( )
20+ def list! , do: unwrap_or_raise ( list ( ) )
1421
1522 @ doc """
1623 Lock all wallets
1724 """
18- def lock_all , do: "/lock_all" |> url ( ) |> get_request ( )
25+ def lock_all , do: "/lock_all" |> url ( ) |> get ( )
26+ def lock_all! , do: unwrap_or_raise ( lock_all ( ) )
1927
2028 @ doc """
2129 List all public keys across all wallets
2230 """
23- def get_public_keys , do: "/get_public_keys" |> url ( ) |> get_request ( )
31+ def get_public_keys , do: "/get_public_keys" |> url ( ) |> get ( )
32+ def get_public_keys! , do: unwrap_or_raise ( get_public_keys ( ) )
2433
2534 @ doc """
2635 List all key pairs across all wallets
2736 """
28- def list_keys , do: "/list_keys" |> url ( ) |> get_request ( )
37+ def list_keys , do: "/list_keys" |> url ( ) |> get ( )
38+ def list_keys! , do: unwrap_or_raise ( list_keys ( ) )
2939
3040 @ doc """
3141 Create a new wallet with the given name
3242 """
33- def create ( name ) , do: "/create" |> url ( ) |> post_request ( name , true )
43+ def create ( name ) , do: "/create" |> url ( ) |> post ( name , true )
44+ def create! ( name ) , do: unwrap_or_raise ( create ( name ) )
3445
3546 @ doc """
3647 Open an existing wallet of the given name
3748 """
38- def open ( name ) , do: "/open" |> url ( ) |> post_request ( name , true )
49+ def open ( name ) , do: "/open" |> url ( ) |> post ( name , true )
50+ def open! ( name ) , do: unwrap_or_raise ( open ( name ) )
3951
4052 @ doc """
4153 Lock a wallet of the given name
4254 """
43- def lock ( name ) , do: "/lock" |> url ( ) |> post_request ( name , true )
55+ def lock ( name ) , do: "/lock" |> url ( ) |> post ( name , true )
56+ def lock! ( name ) , do: unwrap_or_raise ( lock ( name ) )
4457
4558 @ doc """
4659 Unlock a wallet with the given name and password
4760 """
4861 def unlock ( name , password ) do
4962 "/unlock"
5063 |> url ( )
51- |> post_request ( [ name , password ] )
64+ |> post ( [ name , password ] )
5265 end
66+ def unlock! ( name , password ) , do: unwrap_or_raise ( unlock ( name , password ) )
5367
5468 @ doc """
5569 Import a private key to the wallet of the given name
5670 """
5771 def import_key ( name , key ) do
5872 "/import_key"
5973 |> url ( )
60- |> post_request ( [ name , key ] )
74+ |> post ( [ name , key ] )
6175 end
76+ def import_key! ( name , key ) , do: unwrap_or_raise ( import_key ( name , key ) )
6277
6378 @ doc """
6479 Set wallet auto lock timeout (in seconds)
6580 """
66- def set_timeout ( timeout_secs ) , do: "/set_timeout" |> url ( ) |> post_request ( timeout_secs )
81+ def set_timeout ( seconds ) , do: "/set_timeout" |> url ( ) |> post ( seconds )
82+ def set_timeout! ( seconds ) , do: unwrap_or_raise ( set_timeout ( seconds ) )
6783
6884 @ doc """
6985 Sign transaction given an array of transaction, require public keys, and chain id
@@ -105,11 +121,15 @@ defmodule EOSRPC.Wallet do
105121
106122 """
107123 def sign_transaction ( transaction , keys ) , do: sign_transaction ( transaction , keys , "" )
124+ def sign_transaction! ( transaction , keys ) , do: unwrap_or_raise ( sign_transaction ( transaction , keys ) )
108125
109126 def sign_transaction ( transaction , keys , chain_id ) do
110127 "/sign_transaction"
111128 |> url ( )
112- |> post_request ( [ transaction , keys , chain_id ] )
129+ |> post ( [ transaction , keys , chain_id ] )
130+ end
131+ def sign_transaction! ( transaction , keys , chain_id ) do
132+ unwrap_or_raise ( sign_transaction ( transaction , key , chain_id ) )
113133 end
114134
115135 def url ( url ) ,
0 commit comments