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

Fix proxy metadata deduplication #446

Merged
merged 1 commit into from
Jan 12, 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
9 changes: 6 additions & 3 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ mod server {
let (id, source) = match encode {
MediaEncode::Base64 => {
let source = base64::encode(&content);
let id = blake3::hash(&content).to_hex().to_string();
let id = blake3::hash(blake3::hash(&content).as_bytes())
.to_hex()
.to_string();
(id, source)
}
MediaEncode::Sha2 => {
Expand All @@ -105,15 +107,15 @@ mod server {
}
MediaEncode::Blake3 => {
let source = blake3::hash(&content).to_hex().to_string();
let id = source.clone();
let id = source.to_string();
(id, source)
}
};

let metadata = MediaMetadata::new(&id, &media.ty, &media.uri, &source);

// Store File
let attachment_id = blake3::hash(source.as_bytes()).to_hex().to_lowercase();
let attachment_id = id;
let file_req = RgbProxyMediaFileReq {
params: RgbProxyMedia {
attachment_id: attachment_id.clone(),
Expand All @@ -134,6 +136,7 @@ mod server {
file_name: metadata_id.clone(),
bytes: metadata_content,
};

proxy_media_store(file_req).await?;

Ok(metadata)
Expand Down
2 changes: 1 addition & 1 deletion src/rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,7 @@ pub async fn finish_auction_offers(
iface,
buyer_invoice,
..
}) = all_bids.clone().get(0)
}) = all_bids.clone().first()
{
let all_invoices = all_bids
.clone()
Expand Down
2 changes: 1 addition & 1 deletion tests/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub async fn get_balance_test() -> Result<()> {
thread::sleep(time::Duration::from_secs(1));
if let AuthResponse::Result { refresh: _, token } = response {
let accounts = get_balance(&token).await?;
let btc_account = accounts.get(0).unwrap();
let btc_account = accounts.first().unwrap();
assert_eq!(btc_account.balance, "0");
}

Expand Down
20 changes: 20 additions & 0 deletions tests/rgb/web/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,23 @@ async fn create_uda_with_medias() {
let issue_resp: JsValue = resolve(full_issue_contract(issuer_sk.to_string(), issue_req)).await;
let issuer_resp: IssueResponse = json_parse(&issue_resp);
}

#[wasm_bindgen_test]
#[allow(unused_assignments)]
async fn import_attachments_into_proxy() {
set_panic_hook();
info!("Import Attachments (Static Files Media) on the RGB Proxy");
let media_item = MediaItemRequest {
ty: "image/svg+xml".to_string(),
uri: "https://www.torproject.org/static/images/yec-2023/main-illo.svg".to_string(),
};
let import_media_req = MediaRequest {
preview: Some(media_item.clone()),
media: Some(media_item.clone()),
attachments: vec![media_item.clone()],
};

let import_media_req = serde_wasm_bindgen::to_value(&import_media_req).expect("");
let import_media_resp: JsValue = resolve(import_uda_data(import_media_req)).await;
let import_media_resp: MediaResponse = json_parse(&import_media_resp);
}
Loading