Skip to content

Commit 5ce2b93

Browse files
committed
Merge branch 'deregister-scan' of https://github.com/ergoplatform/ergo-node-interface-rust into deregister-scan
2 parents 45e8cdd + ba0d246 commit 5ce2b93

File tree

4 files changed

+40
-1
lines changed

4 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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ impl NodeInterface {
7979
}
8080
}
8181

82+
pub fn from_url_str(api_key: &str, url: &str) -> Result<Self> {
83+
let url = Url::parse(url).map_err(|e| NodeError::InvalidUrl(e.to_string()))?;
84+
Ok(NodeInterface {
85+
api_key: api_key.to_string(),
86+
url,
87+
})
88+
}
89+
8290
/// Acquires unspent boxes from the blockchain by specific address
8391
pub fn unspent_boxes_by_address(&self, address: &P2PKAddressString, offset: u64, limit: u64) -> Result<Vec<ErgoBox>> {
8492
let endpoint = format!(

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 {

src/wallet.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@ impl NodeInterface {
189189
Err(NodeError::FailedParsingWalletStatus(res_json.pretty(2)))
190190
}
191191
}
192+
193+
/// Unlock wallet
194+
pub fn wallet_unlock(&self, password: &str) -> Result<bool> {
195+
let endpoint = "/wallet/unlock";
196+
let body = object! {
197+
pass: password,
198+
};
199+
200+
let res = self.send_post_req(endpoint, body.to_string())?;
201+
202+
if res.status().is_success() {
203+
Ok(true)
204+
} else {
205+
let json = self.parse_response_to_json(Ok(res))?;
206+
Err(NodeError::BadRequest(json["error"].to_string()))
207+
}
208+
}
192209
}
193210

194211
#[serde_as]

0 commit comments

Comments
 (0)