Skip to content

Commit

Permalink
Implemented sign tx & submit tx
Browse files Browse the repository at this point in the history
  • Loading branch information
robkorn committed Nov 20, 2020
1 parent 5ffa915 commit 9dc1a52
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/node_interface.rs
Expand Up @@ -4,6 +4,7 @@ use crate::JsonString;
use crate::{BlockHeight, NanoErg, P2PKAddressString, P2SAddressString, TxId};
use ergo_lib::chain::ergo_box::ErgoBox;
use ergo_lib::chain::transaction::unsigned::UnsignedTransaction;
use ergo_lib::chain::transaction::Transaction;
use json::JsonValue;
use serde_json::from_str;
use thiserror::Error;
Expand Down Expand Up @@ -122,6 +123,21 @@ impl NodeInterface {
return Ok(tx_id);
}

/// Submits a Signed `Transaction` provided as input
/// to the Ergo Blockchain mempool.
pub fn submit_transaction(&self, signed_tx: &Transaction) -> Result<TxId> {
let signed_tx_json = &serde_json::to_string(&signed_tx)
.map_err(|_| NodeError::Other("Failed Converting `Transaction` to json".to_string()))?;
self.submit_json_transaction(signed_tx_json)
}

/// Sign an `UnsignedTransaction`
pub fn sign_transaction(&self, unsigned_tx: &UnsignedTransaction) -> Result<JsonValue> {
self.sign_json_transaction(&serde_json::to_string(&unsigned_tx).map_err(|_| {
NodeError::Other("Failed Converting `UnsignedTransaction` to json".to_string())
})?)
}

/// Get all addresses from the node wallet
pub fn wallet_addresses(&self) -> Result<Vec<P2PKAddressString>> {
let endpoint = "/wallet/addresses";
Expand Down

0 comments on commit 9dc1a52

Please sign in to comment.