Skip to content

Commit

Permalink
Add LIB_ID_RGB to version stock.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoquick committed Jul 17, 2023
1 parent 2f48390 commit 5a01beb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/rgb/carbonado.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use amplify::confinement::{Confined, U32};
use anyhow::Result;
use postcard::{from_bytes, to_allocvec};
use rgbstd::persistence::Stock;
use rgbstd::{persistence::Stock, stl::LIB_ID_RGB};
use strict_encoding::{StrictDeserialize, StrictSerialize};

use crate::{
Expand All @@ -13,7 +13,7 @@ pub async fn store_stock(sk: &str, name: &str, stock: &Stock) -> Result<()> {
let data = stock.to_strict_serialized::<U32>()?;
store(
sk,
name,
&format!("{name}/{LIB_ID_RGB}"),
&data,
false,
Some(RGB_STRICT_TYPE_VERSION.to_vec()),
Expand All @@ -25,7 +25,7 @@ pub async fn force_store_stock(sk: &str, name: &str, stock: &Stock) -> Result<()
let data = stock.to_strict_serialized::<U32>()?;
store(
sk,
name,
&format!("{name}/{LIB_ID_RGB}"),
&data,
true,
Some(RGB_STRICT_TYPE_VERSION.to_vec()),
Expand All @@ -34,7 +34,9 @@ pub async fn force_store_stock(sk: &str, name: &str, stock: &Stock) -> Result<()
}

pub async fn retrieve_stock(sk: &str, name: &str) -> Result<Stock> {
let (data, _) = retrieve(sk, name).await.unwrap_or_default();
let (data, _) = retrieve(sk, &format!("{name}/{LIB_ID_RGB}"))
.await
.unwrap_or_default();
if data.is_empty() {
Ok(Stock::default())
} else {
Expand All @@ -49,7 +51,7 @@ pub async fn store_wallets(sk: &str, name: &str, rgb_wallets: &RgbAccount) -> Re
let data = to_allocvec(rgb_wallets)?;
store(
sk,
name,
&format!("{name}/{LIB_ID_RGB}"),
&data,
false,
Some(RGB_STRICT_TYPE_VERSION.to_vec()),
Expand All @@ -58,7 +60,9 @@ pub async fn store_wallets(sk: &str, name: &str, rgb_wallets: &RgbAccount) -> Re
}

pub async fn retrieve_wallets(sk: &str, name: &str) -> Result<RgbAccount> {
let (data, _) = retrieve(sk, name).await.unwrap_or_default();
let (data, _) = retrieve(sk, &format!("{name}/{LIB_ID_RGB}"))
.await
.unwrap_or_default();
if data.is_empty() {
Ok(RgbAccount::default())
} else {
Expand Down

0 comments on commit 5a01beb

Please sign in to comment.