1use prost::Name;
4use tendermint_proto::google::protobuf::Any;
5
6pub trait IntoProtobufAny {
8 fn into_any(self) -> Any;
10}
11
12impl<T> IntoProtobufAny for T
13where
14 T: Name,
15{
16 fn into_any(self) -> Any {
17 Any {
18 type_url: T::type_url(),
19 value: self.encode_to_vec(),
20 }
21 }
22}
23
24#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
25pub use wbg::*;
26
27#[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))]
28mod wbg {
29 use super::*;
30 use js_sys::Uint8Array;
31 use lumina_utils::make_object;
32 use wasm_bindgen::prelude::*;
33
34 #[wasm_bindgen(typescript_custom_section)]
35 const _: &str = "
36 /**
37 * Protobuf Any type
38 */
39 export interface ProtoAny {
40 typeUrl: string;
41 value: Uint8Array;
42 }
43 ";
44
45 #[wasm_bindgen]
46 extern "C" {
47 #[wasm_bindgen(typescript_type = "ProtoAny")]
49 pub type JsAny;
50
51 #[wasm_bindgen(method, getter, js_name = typeUrl)]
53 pub fn type_url(this: &JsAny) -> String;
54
55 #[wasm_bindgen(method, getter, js_name = value)]
57 pub fn value(this: &JsAny) -> Vec<u8>;
58 }
59
60 impl From<Any> for JsAny {
61 fn from(value: Any) -> Self {
62 let obj = make_object!(
63 "typeUrl" => value.type_url.into(),
64 "value" => Uint8Array::from(&value.value[..])
65 );
66
67 obj.unchecked_into()
68 }
69 }
70
71 impl IntoProtobufAny for JsAny {
72 fn into_any(self) -> Any {
73 Any {
74 type_url: self.type_url(),
75 value: self.value(),
76 }
77 }
78 }
79}
80
81#[cfg(feature = "uniffi")]
83mod uniffi_types {
84 use tendermint_proto::google::protobuf::Any as ProtobufAny;
85
86 #[uniffi::remote(Record)]
89 pub struct ProtobufAny {
90 pub type_url: String,
96 pub value: Vec<u8>,
98 }
99}