70 lines
2.0 KiB
Rust
70 lines
2.0 KiB
Rust
//! NAC SDK - ACC-1643 文档管理协议接口
|
|
|
|
use crate::adapters::NacLensClient;
|
|
use crate::error::{NACError, Result};
|
|
use nac_udm::primitives::{Address, Hash};
|
|
use serde_json::json;
|
|
|
|
/// ACC-1643 文档管理协议客户端
|
|
pub struct Acc1643Client {
|
|
pub client: NacLensClient,
|
|
pub contract_address: Address,
|
|
}
|
|
|
|
impl Acc1643Client {
|
|
pub fn new(client: NacLensClient, contract_address: Address) -> Self {
|
|
Self { client, contract_address }
|
|
}
|
|
|
|
/// 设置文档
|
|
pub async fn set_document(
|
|
&self,
|
|
doc_name: &str,
|
|
doc_uri: &str,
|
|
doc_hash: &Hash,
|
|
constitutional_receipt: &Hash,
|
|
) -> Result<()> {
|
|
let params = json!({
|
|
"contract": self.contract_address.to_hex(),
|
|
"doc_name": doc_name,
|
|
"doc_uri": doc_uri,
|
|
"doc_hash": doc_hash.to_hex(),
|
|
"constitutional_receipt": constitutional_receipt.to_hex(),
|
|
});
|
|
self.client.call("acc1643.set_document", params).await?;
|
|
Ok(())
|
|
}
|
|
|
|
/// 查询文档
|
|
pub async fn get_document(&self, doc_name: &str) -> Result<serde_json::Value> {
|
|
let params = json!({
|
|
"contract": self.contract_address.to_hex(),
|
|
"doc_name": doc_name,
|
|
});
|
|
self.client.call("acc1643.get_document", params).await
|
|
}
|
|
|
|
/// 列出所有文档
|
|
pub async fn get_all_documents(&self) -> Result<serde_json::Value> {
|
|
let params = json!({
|
|
"contract": self.contract_address.to_hex(),
|
|
});
|
|
self.client.call("acc1643.get_all_documents", params).await
|
|
}
|
|
|
|
/// 删除文档
|
|
pub async fn remove_document(
|
|
&self,
|
|
doc_name: &str,
|
|
constitutional_receipt: &Hash,
|
|
) -> Result<()> {
|
|
let params = json!({
|
|
"contract": self.contract_address.to_hex(),
|
|
"doc_name": doc_name,
|
|
"constitutional_receipt": constitutional_receipt.to_hex(),
|
|
});
|
|
self.client.call("acc1643.remove_document", params).await?;
|
|
Ok(())
|
|
}
|
|
}
|