Skip to content

Commit ba0d246

Browse files
committed
Merge branch 'develop' of github.com:ergoplatform/ergo-node-interface-rust into deregister-scan
2 parents 143c2a3 + 344ad02 commit ba0d246

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ergo-node-interface"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
authors = ["Robert Kornacki <11645932+robkorn@users.noreply.github.com>"]
55
edition = "2018"
66
license = "MIT"

src/node_interface.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff 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]

src/transactions.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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

146160
fn parse_tx_id_unsafe(mut res_json: JsonValue) -> TxId {

0 commit comments

Comments
 (0)