gear_subxt/utils/
mod.rs

1// Copyright 2019-2023 Parity Technologies (UK) Ltd.
2// This file is dual-licensed as Apache-2.0 or GPL-3.0.
3// see LICENSE for license details.
4
5//! Miscellaneous utility helpers.
6
7mod account_id;
8pub mod bits;
9mod multi_address;
10mod multi_signature;
11mod static_type;
12mod wrapper_opaque;
13
14use codec::{Decode, Encode};
15use derivative::Derivative;
16
17pub use account_id::AccountId32;
18pub use multi_address::MultiAddress;
19pub use multi_signature::MultiSignature;
20pub use static_type::Static;
21pub use wrapper_opaque::WrapperKeepOpaque;
22
23// Used in codegen
24#[doc(hidden)]
25pub use primitive_types::{H160, H256, H512};
26
27/// Wraps an already encoded byte vector, prevents being encoded as a raw byte vector as part of
28/// the transaction payload
29#[derive(Clone, Debug, Eq, PartialEq)]
30pub struct Encoded(pub Vec<u8>);
31
32impl codec::Encode for Encoded {
33    fn encode(&self) -> Vec<u8> {
34        self.0.to_owned()
35    }
36}
37
38/// A version of [`std::marker::PhantomData`] that is also Send and Sync (which is fine
39/// because regardless of the generic param, it is always possible to Send + Sync this
40/// 0 size type).
41#[derive(Derivative, Encode, Decode, scale_info::TypeInfo)]
42#[derivative(
43    Clone(bound = ""),
44    PartialEq(bound = ""),
45    Debug(bound = ""),
46    Eq(bound = ""),
47    Default(bound = ""),
48    Hash(bound = "")
49)]
50#[scale_info(skip_type_params(T))]
51#[doc(hidden)]
52pub struct PhantomDataSendSync<T>(core::marker::PhantomData<T>);
53
54impl<T> PhantomDataSendSync<T> {
55    pub(crate) fn new() -> Self {
56        Self(core::marker::PhantomData)
57    }
58}
59
60unsafe impl<T> Send for PhantomDataSendSync<T> {}
61unsafe impl<T> Sync for PhantomDataSendSync<T> {}
62
63/// This represents a key-value collection and is SCALE compatible
64/// with collections like BTreeMap. This has the same type params
65/// as `BTreeMap` which allows us to easily swap the two during codegen.
66pub type KeyedVec<K, V> = Vec<(K, V)>;