File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed
Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 11[package ]
22name = " ergo-node-interface"
3- version = " 0.4.0 "
3+ version = " 0.4.1 "
44authors = [" Robert Kornacki <11645932+robkorn@users.noreply.github.com>" ]
55edition = " 2018"
66license = " MIT"
Original file line number Diff line number Diff line change @@ -77,6 +77,14 @@ impl NodeInterface {
7777 }
7878 }
7979
80+ pub fn from_url_str ( api_key : & str , url : & str ) -> Result < Self > {
81+ let url = Url :: parse ( url) . map_err ( |e| NodeError :: InvalidUrl ( e. to_string ( ) ) ) ?;
82+ Ok ( NodeInterface {
83+ api_key : api_key. to_string ( ) ,
84+ url,
85+ } )
86+ }
87+
8088 /// Get all addresses from the node wallet
8189 pub fn wallet_addresses ( & self ) -> Result < Vec < P2PKAddressString > > {
8290 let endpoint = "/wallet/addresses" ;
@@ -367,6 +375,23 @@ impl NodeInterface {
367375 Err ( NodeError :: FailedParsingWalletStatus ( res_json. pretty ( 2 ) ) )
368376 }
369377 }
378+
379+ /// Unlock wallet
380+ pub fn wallet_unlock ( & self , password : & str ) -> Result < bool > {
381+ let endpoint = "/wallet/unlock" ;
382+ let body = object ! {
383+ pass: password,
384+ } ;
385+
386+ let res = self . send_post_req ( endpoint, body. to_string ( ) ) ?;
387+
388+ if res. status ( ) . is_success ( ) {
389+ Ok ( true )
390+ } else {
391+ let json = self . parse_response_to_json ( Ok ( res) ) ?;
392+ Err ( NodeError :: BadRequest ( json[ "error" ] . to_string ( ) ) )
393+ }
394+ }
370395}
371396
372397#[ serde_as]
Original file line number Diff line number Diff line change @@ -141,6 +141,20 @@ impl NodeInterface {
141141
142142 Ok ( res_json)
143143 }
144+
145+ /// Gets the recommended fee for a transaction.
146+ /// bytes - size of the transaction in bytes
147+ /// wait_time - minutes to wait for the transaction to be included in the blockchain
148+ pub fn get_recommended_fee ( & self , bytes : u64 , wait_time : u64 ) -> Result < u64 > {
149+ let endpoint = format ! (
150+ "/transactions/getFee?bytes={}&waitTime={}" ,
151+ bytes, wait_time
152+ ) ;
153+ let res = self . send_get_req ( & endpoint) ;
154+ let res_json = self . parse_response_to_json ( res) ;
155+ let fee = res_json?. as_u64 ( ) . unwrap ( ) ;
156+ Ok ( fee)
157+ }
144158}
145159
146160fn parse_tx_id_unsafe ( mut res_json : JsonValue ) -> TxId {
You can’t perform that action at this time.
0 commit comments