Skip to content
Draft
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
3,911 changes: 0 additions & 3,911 deletions Cargo.lock

This file was deleted.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.5"
edition = "2021"

[dependencies]
dpp = { git = "https://github.com/dashpay/platform", branch = "fix/address-list-error" , features = ["state-transition-signing", "data-contract-value-conversion"]}
dpp = { git = "https://github.com/dashpay/platform", branch = "fix/address-list-error" , features = ["all_features"]}
rs-dapi-client = { git = "https://github.com/dashpay/platform", branch = "fix/address-list-error" }
dapi-grpc = { git = "https://github.com/dashpay/platform", branch = "fix/address-list-error" }
simple-signer = { git = "https://github.com/dashpay/platform", branch = "fix/address-list-error" }
Expand All @@ -20,4 +20,9 @@ rand = "0.8.5"
getrandom = "0.2.15"
anyhow = "1.0.89"
log = "0.4.22"
regex = "1.11.0"
regex = "1.11.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
reqwest = { version = "0.12.9", features = ["json"] }
dashcore-rpc = { path = "../rust-dashcore-rpc/client" }
rust_decimal = "1.36.0"
122 changes: 122 additions & 0 deletions src/api/digitalcash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
use std::collections::HashMap;
use dpp::dashcore::{Address, InstantLock, Network, Txid};
use http::StatusCode;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::errors::Error;

pub struct DigitalCashAPI {
url: String,
}

#[derive(Serialize)]
pub struct JsonRPCHashMapArguments {
method: String,
params: Vec<HashMap<String, Vec<String>>>
}
#[derive(Serialize)]
pub struct JsonRPCArrayArguments {
method: String,
params: Vec<Vec<String>>
}
#[derive(Serialize, Deserialize)]
pub struct UTXO {
pub address: String,
pub txid: String,
#[serde(rename(deserialize = "outputIndex"))]
pub output_index: u32,
pub script: String,
pub satoshis: u64,
pub height: u32
}
#[derive(Serialize, Deserialize)]
pub struct GetTxChainLocksResult {
pub height: i32,
pub chainlock: bool,
pub mempool: bool,
}

#[derive(Serialize, Deserialize)]
pub struct JsonResponse<T> {
result: T,
}

impl DigitalCashAPI {
pub fn new(network: Network) -> Self {
let url = match network {
Network::Dash => "https://rpc.digitalcash.dev",
Network::Testnet => "https://trpc.digitalcash.dev",
_ => panic!("Network {} is not supported by digitalcash.dev", network)
};

return DigitalCashAPI { url: String::from(url) };
}

pub async fn get_address_utxos(&self, address: Address) -> Result<Vec<UTXO>, Error> {
let mut params: HashMap<String, Vec<String>> = HashMap::new();

params.insert(String::from("addresses"), vec![address.to_string()]);

let p = JsonRPCHashMapArguments {
method: String::from("getaddressutxos"),
params: vec![params],
};

let res = reqwest::Client::new()
.post(&self.url)
.json(&p)
.send()
.await.unwrap();

let status_code = res.status();

match status_code.as_u16() {
420 => {
panic!("Rate limit")
},
200 => {
let json = res
.json::<JsonResponse<Vec<UTXO>>>()
.await.unwrap();

Ok(json.result)
},
_ => {
panic!("Unknown status code")
}
}
}

pub async fn get_tx_chain_locks(&self, txid: Txid) -> Result<GetTxChainLocksResult, Error> {
let params: Vec<String> = vec![txid.to_hex()];

let p = JsonRPCArrayArguments {
method: String::from("gettxchainlocks"),
params: vec![params],
};

let res = reqwest::Client::new()
.post(&self.url)
.json(&p)
.send()
.await.unwrap();

let status_code = res.status();

match status_code.as_u16() {
420 => {
panic!("Rate limit")
},
200 => {
let json = res
.json::<JsonResponse<Vec<GetTxChainLocksResult>>>()
.await.unwrap();

return Ok(json.result.into_iter().nth(0).unwrap())
},
_ => {
panic!("Unknown status code")
}
}
}
}
1 change: 1 addition & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod digitalcash;
4 changes: 2 additions & 2 deletions src/commands/masternode_vote_dpns_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl MasternodeVoteDPNSNameCommand {
debug!("Identity with identifier {} found in the network", identity.id());

let identity_public_keys = platform_grpc_client
.get_identity_keys(identity.id()).await;
.get_identity_keys(identity.id()).await?;

debug!("Finding matching IdentityPublicKey in the Identity against applied private key");

Expand All @@ -122,7 +122,7 @@ impl MasternodeVoteDPNSNameCommand {
identity_public_key.purpose(),
identity_public_key.security_level());

let nonce = platform_grpc_client.get_identity_nonce(identity.id()).await;
let nonce = platform_grpc_client.get_identity_nonce(identity.id()).await?;

debug!("Identity nonce for identifier {} is {}", identity.id(), nonce.clone());

Expand Down
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod register_dpns_name;
pub mod withdraw;
pub mod masternode_vote_dpns_name;
pub mod register_identity;
4 changes: 2 additions & 2 deletions src/commands/register_dpns_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl RegisterDPNSNameCommand {
debug!("Identity with identifier {} found in the network", identity.id());

let identity_public_keys = platform_grpc_client
.get_identity_keys(identity.id()).await;
.get_identity_keys(identity.id()).await?;

debug!("Finding matching IdentityPublicKey in the Identity against applied private key");

Expand All @@ -137,7 +137,7 @@ impl RegisterDPNSNameCommand {
identity_public_key.purpose(),
identity_public_key.security_level());

let identity_contract_nonce = platform_grpc_client.get_identity_contract_nonce(identity.id(), dpns_contract.id()).await;
let identity_contract_nonce = platform_grpc_client.get_identity_contract_nonce(identity.id(), dpns_contract.id()).await.unwrap();

debug!("Identity contract nonce for identifier {} is {}", identity.id(), identity_contract_nonce.clone());

Expand Down
Loading
Loading