Skip to content

Commit f65e253

Browse files
committed
added more functionality to module
1 parent 308622e commit f65e253

4 files changed

Lines changed: 147 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1+
use crate::database::db_manger::ColumnFamilyOperations;
2+
use crate::database::db_manger::RocksDB;
3+
use crate::model::script_activity::ScriptActivity;
4+
use anyhow::{anyhow, Error, Result};
5+
use serde::{Deserialize, Serialize};
6+
use serde_json;
17

8+
pub struct ScriptUnspentDB {
9+
pub db: RocksDB,
10+
}
11+
12+
impl ScriptUnspentDB {
13+
pub async fn query(&self, limit: i32, lt: String) -> Result<Vec<ScriptActivity>> {
14+
todo!()
15+
}
16+
pub async fn store(&self, unspent: ScriptActivity) -> Result<()> {
17+
match serde_json::to_string(&unspent) {
18+
Ok(value) => {
19+
let key = unspent.id.clone();
20+
self.db
21+
.put("script_activity", key.as_bytes(), value.as_bytes())?;
22+
Ok(())
23+
}
24+
Err(e) => Err(anyhow!(e)),
25+
}
26+
}
27+
pub async fn delete(&self, id: String) -> Result<()> {
28+
match self.db.delete("script_activity", id.as_bytes()) {
29+
Ok(_) => Ok(()),
30+
Err(e) => Err(anyhow!(e)),
31+
}
32+
}
33+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
1+
use crate::database::db_manger::ColumnFamilyOperations;
2+
use crate::database::db_manger::RocksDB;
3+
use crate::model::script_aggregation::ScriptAggregation;
4+
use anyhow::{anyhow, Error, Result};
5+
use serde::{Deserialize, Serialize};
6+
use serde_json;
17

8+
pub struct ScriptAggretionDB {
9+
pub db: RocksDB,
10+
}
11+
12+
impl ScriptAggretionDB {
13+
pub async fn query(&self, limit: i32, lt: String) -> Result<Vec<ScriptAggregation>> {
14+
todo!()
15+
}
16+
pub async fn store(&self, aggregation: ScriptAggregation) -> Result<()> {
17+
match serde_json::to_string(&aggregation) {
18+
Ok(value) => {
19+
let key = aggregation.id.clone();
20+
self.db
21+
.put("script_aggregation", key.as_bytes(), value.as_bytes())?;
22+
Ok(())
23+
}
24+
Err(e) => Err(anyhow!(e)),
25+
}
26+
}
27+
pub async fn get(&self, id: String) -> Result<Option<ScriptAggregation>> {
28+
match self.db.get("script_aggregation", id.as_bytes()) {
29+
Ok(Some(value)) => {
30+
let oracle: ScriptAggregation =
31+
serde_json::from_slice(&value).map_err(|e| anyhow!(e))?;
32+
Ok(Some(oracle))
33+
}
34+
Ok(None) => Ok(None),
35+
Err(e) => Err(anyhow!(e)),
36+
}
37+
}
38+
pub async fn delete(&self, id: String) -> Result<()> {
39+
match self.db.delete("script_aggregation", id.as_bytes()) {
40+
Ok(_) => Ok(()),
41+
Err(e) => Err(anyhow!(e)),
42+
}
43+
}
44+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1+
use crate::database::db_manger::ColumnFamilyOperations;
2+
use crate::database::db_manger::RocksDB;
3+
use crate::model::script_unspent::ScriptUnspent;
4+
use anyhow::{anyhow, Error, Result};
5+
use serde::{Deserialize, Serialize};
6+
use serde_json;
17

8+
pub struct ScriptUnspentDB {
9+
pub db: RocksDB,
10+
}
11+
12+
impl ScriptUnspentDB {
13+
pub async fn query(&self, limit: i32, lt: String) -> Result<Vec<ScriptUnspent>> {
14+
todo!()
15+
}
16+
pub async fn store(&self, unspent: ScriptUnspent) -> Result<()> {
17+
match serde_json::to_string(&unspent) {
18+
Ok(value) => {
19+
let key = unspent.id.clone();
20+
self.db
21+
.put("script_unspent", key.as_bytes(), value.as_bytes())?;
22+
Ok(())
23+
}
24+
Err(e) => Err(anyhow!(e)),
25+
}
26+
}
27+
pub async fn delete(&self, id: String) -> Result<()> {
28+
match self.db.delete("script_unspent", id.as_bytes()) {
29+
Ok(_) => Ok(()),
30+
Err(e) => Err(anyhow!(e)),
31+
}
32+
}
33+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1+
use crate::database::db_manger::ColumnFamilyOperations;
2+
use crate::database::db_manger::RocksDB;
3+
use crate::model::vault_auction_batch_history::VaultAuctionBatchHistory;
4+
use anyhow::{anyhow, Error, Result};
5+
use serde::{Deserialize, Serialize};
6+
use serde_json;
17

8+
pub struct VaultAuctionDB {
9+
pub db: RocksDB,
10+
}
11+
12+
impl VaultAuctionDB {
13+
pub async fn store(&self, auction: VaultAuctionBatchHistory) -> Result<()> {
14+
match serde_json::to_string(&auction) {
15+
Ok(value) => {
16+
let key = auction.id.clone();
17+
self.db
18+
.put("vault_auction_history", key.as_bytes(), value.as_bytes())?;
19+
Ok(())
20+
}
21+
Err(e) => Err(anyhow!(e)),
22+
}
23+
}
24+
pub async fn get(&self, id: String) -> Result<Option<VaultAuctionBatchHistory>> {
25+
match self.db.get("vault_auction_history", id.as_bytes()) {
26+
Ok(Some(value)) => {
27+
let oracle: VaultAuctionBatchHistory =
28+
serde_json::from_slice(&value).map_err(|e| anyhow!(e))?;
29+
Ok(Some(oracle))
30+
}
31+
Ok(None) => Ok(None),
32+
Err(e) => Err(anyhow!(e)),
33+
}
34+
}
35+
pub async fn delete(&self, id: String) -> Result<()> {
36+
match self.db.delete("vault_auction_history", id.as_bytes()) {
37+
Ok(_) => Ok(()),
38+
Err(e) => Err(anyhow!(e)),
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)