Skip to content

Commit

Permalink
Fix error on source mdia
Browse files Browse the repository at this point in the history
  • Loading branch information
josediegorobles committed Dec 5, 2023
1 parent 5ccd956 commit a8cb2ac
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/web/rgb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as BMC from "./bitmask_core";

export const issueContract = async (
nostrHexSk: string,
request: IssueRequest
request: IssuePreRequest
): Promise<IssueResponse> =>
JSON.parse(await BMC.issue_contract(nostrHexSk, request));

Expand Down Expand Up @@ -250,7 +250,7 @@ export interface IssueMetadata {
collectible?: NewCollectible[];
}

export interface IssueRequest {
export interface IssuePreRequest {
/// The ticker of the asset
ticker: string;
/// Name of the asset
Expand All @@ -266,7 +266,7 @@ export interface IssueRequest {
/// The name of the iface (ex: RGB20)
iface: string;
/// contract metadata (only RGB21/UDA)
meta?: IssueMediaRequest;
meta?: MediaRequest;
}

export interface NewCollectible {
Expand Down
35 changes: 35 additions & 0 deletions src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,41 @@ pub struct IssueAssetRequest {
pub request: IssueRequest,
}

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
#[derive(Validate)]
#[garde(context(RGBContext))]
pub struct IssuePreRequest {
/// The ticker of the asset
#[garde(ascii)]
#[garde(length(min = 1, max = 8))]
pub ticker: String,
/// Name of the asset
#[garde(ascii)]
#[garde(length(min = 1, max = 40))]
pub name: String,
/// Description of the asset
#[garde(ascii)]
#[garde(length(min = u8::MIN.into(), max = u8::MAX.into()))]
pub description: String,
/// Amount of the asset
#[garde(range(min = u64::MIN, max = u64::MAX))]
pub supply: u64,
/// Precision of the asset
#[garde(range(min = u8::MIN, max = u8::MAX))]
pub precision: u8,
/// Seal of the initial owner
#[garde(ascii)]
#[garde(custom(verify_tapret_seal))]
pub seal: String,
/// The name of the iface (ex: RGB20)
#[garde(alphanumeric)]
pub iface: String,
/// contract metadata (only RGB21/UDA)
#[garde(skip)]
pub meta: Option<MediaRequest>,
}

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
#[derive(Validate)]
Expand Down
28 changes: 23 additions & 5 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use wasm_bindgen_futures::{future_to_promise, JsFuture};

use crate::rgb::structs::ContractAmount;
use crate::structs::{
AcceptRequest, FullRgbTransferRequest, ImportRequest, InvoiceRequest, IssueRequest,
MediaRequest, PsbtRequest, PublishPsbtRequest, ReIssueRequest, RgbBidRequest, RgbOfferRequest,
RgbRemoveTransferRequest, RgbSaveTransferRequest, RgbSwapRequest, RgbTransferRequest,
SecretString, SignPsbtRequest, WatcherRequest,
AcceptRequest, FullRgbTransferRequest, ImportRequest, InvoiceRequest, IssueMediaRequest,
IssuePreRequest, IssueRequest, MediaRequest, PsbtRequest, PublishPsbtRequest, ReIssueRequest,
RgbBidRequest, RgbOfferRequest, RgbRemoveTransferRequest, RgbSaveTransferRequest,
RgbSwapRequest, RgbTransferRequest, SecretString, SignPsbtRequest, WatcherRequest,
};

pub fn set_panic_hook() {
Expand Down Expand Up @@ -381,7 +381,25 @@ pub mod rgb {
set_panic_hook();

future_to_promise(async move {
let req: IssueRequest = serde_wasm_bindgen::from_value(request).unwrap();
let pre_req: IssuePreRequest = serde_wasm_bindgen::from_value(request).unwrap();
let media = match pre_req.meta {
Some(media) => {
let media = serde_wasm_bindgen::to_value(&media).expect("");
let media = resolve(import_uda_data(media)).await;
Some(IssueMediaRequest::from(media))

Check failure on line 389 in src/web.rs

View workflow job for this annotation

GitHub Actions / lint-wasm

error[E0277]: the trait bound `structs::IssueMediaRequest: std::convert::From<wasm_bindgen::JsValue>` is not satisfied --> src/web.rs:389:26 | 389 | Some(IssueMediaRequest::from(media)) | ^^^^^^^^^^^^^^^^^ the trait `std::convert::From<wasm_bindgen::JsValue>` is not implemented for `structs::IssueMediaRequest` | = help: the following other types implement trait `std::convert::From<T>`: <structs::IssueMediaRequest as std::convert::From<structs::ContractMediaDetail>> <structs::IssueMediaRequest as std::convert::From<structs::MediaResponse>>
}
None => None,
};
let req = IssueRequest {
ticker: pre_req.ticker,
name: pre_req.name,
description: pre_req.description,
supply: pre_req.supply,
precision: pre_req.precision,
seal: pre_req.seal,
iface: pre_req.iface,
meta: Some(media),

Check failure on line 401 in src/web.rs

View workflow job for this annotation

GitHub Actions / lint-wasm

error[E0308]: mismatched types --> src/web.rs:401:28 | 401 | meta: Some(media), | ---- ^^^^^ expected `IssueMediaRequest`, found `Option<IssueMediaRequest>` | | | arguments to this enum variant are incorrect | = note: expected struct `structs::IssueMediaRequest` found enum `std::option::Option<structs::IssueMediaRequest>` help: the type constructed contains `std::option::Option<structs::IssueMediaRequest>` due to the type of the argument passed --> src/web.rs:401:23 | 401 | meta: Some(media), | ^^^^^-----^ | | | this argument influences the type of `Some` note: tuple variant defined here --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/option.rs:571:5

Check failure on line 401 in src/web.rs

View workflow job for this annotation

GitHub Actions / lint-wasm

error[E0308]: mismatched types --> src/web.rs:401:28 | 401 | meta: Some(media), | ---- ^^^^^ expected `IssueMediaRequest`, found `Option<IssueMediaRequest>` | | | arguments to this enum variant are incorrect | = note: expected struct `structs::IssueMediaRequest` found enum `std::option::Option<structs::IssueMediaRequest>` help: the type constructed contains `std::option::Option<structs::IssueMediaRequest>` due to the type of the argument passed --> src/web.rs:401:23 | 401 | meta: Some(media), | ^^^^^-----^ | | | this argument influences the type of `Some` note: tuple variant defined here --> /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/option.rs:571:5
};
match crate::rgb::issue_contract(&nostr_hex_sk, req).await {
Ok(result) => Ok(JsValue::from_string(
serde_json::to_string(&result).unwrap(),
Expand Down

0 comments on commit a8cb2ac

Please sign in to comment.