Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement get_asset_unlock_statuses #41

Merged
merged 16 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,27 @@ pub trait RpcApi: Sized {
fn get_transaction_are_locked(
&self,
tx_ids: &Vec<dashcore::Txid>,
) -> Result<Vec<json::GetTransactionLockedResult>> {
) -> Result<Vec<Option<json::GetTransactionLockedResult>>> {
let transaction_ids_json = tx_ids
.into_iter()
.map(|tx_id| Ok(into_json(tx_id)?))
.collect::<Result<Vec<Value>>>()?;
let args = [transaction_ids_json.into()];
self.call("gettransactionsarelocked", &args)
self.call("gettxchainlocks", &args)
}

/// Returns only Chainlocked or Unknown status if height is provided
fn get_asset_unlock_statuses(
&self,
indices: &[u64],
height: Option<u32>,
) -> Result<Vec<json::AssetUnlockStatusResult>> {
let indices_json = indices
.into_iter()
.map(|index| Ok(into_json(index.to_string())?))
.collect::<Result<Vec<Value>>>()?;
let args = [indices_json.into(), opt_into_json(height)?];
self.call("getassetunlockstatuses", &args)
}

fn list_transactions(
Expand Down
11 changes: 11 additions & 0 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ fn test_evo_node_endpoints(evo_client: &Client, wallet_client: &Client) {
// test_get_verifychainlock(evo_client);
// TODO: fix - needs real hash
// test_get_verifyislock(evo_client);

test_get_asset_unlock_statuses(&evo_client);
}


Expand Down Expand Up @@ -1636,6 +1638,15 @@ fn test_get_verifychainlock(cl: &Client) {
let _verifychainlock = cl.get_verifychainlock("00000036d5c520be6e9a32d3829efc983a7b5e88052bf138f80a2b3988689a24", "97ec34efd1615b84af62495e54024880752f57790cf450ae974b80002440963592d96826e24f109e6c149411b70bb9a0035443752368590adae60365cf4251464e0423c1263e9c56a33eae9be9e9c79a117151b2173bcee93497008cace8d793", None).unwrap();
}

fn test_get_asset_unlock_statuses(cl: &Client) {
let indices = vec![0u64, 1, 2];
let height = Some(100);
let _statuses = cl.get_asset_unlock_statuses(
&indices,
height,
);
}

fn test_get_verifyislock(cl: &Client) {
let _verifychainlock = cl.get_verifyislock("d0b1a9c70fdfff6bf7f6cbe3d1fe33a4ca44ceb17059b6381a4ac25d9c9b6495", "8b5174d0e95b5642ebec23c3fe8f0bbf8f6993502f4210322871bba0e818ff3b", "97ec34efd1615b84af62495e54024880752f57790cf450ae974b80002440963592d96826e24f109e6c149411b70bb9a0035443752368590adae60365cf4251464e0423c1263e9c56a33eae9be9e9c79a117151b2173bcee93497008cace8d793", None).unwrap();
}
22 changes: 18 additions & 4 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,24 @@ pub struct WalletTxInfo {

#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
pub struct GetTransactionLockedResult {
#[serde(default, deserialize_with = "deserialize_u32_opt")]
pub height: Option<u32>,
#[serde(rename = "chainlock")]
pub chain_lock: bool,
pub height: i32,
pub chainlock: bool,
pub mempool: bool,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum AssetUnlockStatus {
Chainlocked,
Mined,
Mempooled,
Unknown,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
pub struct AssetUnlockStatusResult {
pub index: u64,
pub status: AssetUnlockStatus,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize)]
Expand Down