1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

use polymesh_api_codegen_macro::*;

#[cfg_attr(not(feature = "download_metadata"), codegen_api(metadata_file = "specs/polymesh_dev_spec_6000000.meta"))]
#[cfg_attr(feature = "download_metadata", codegen_api(metadata_url = "ws://localhost:9944"))]
mod polymesh {}

pub use polymesh::*;

// re-export core client and common types.
#[cfg(feature = "rpc")]
pub use polymesh_api_client as client;
#[cfg(feature = "rpc")]
pub use polymesh_api_client::{ChainApi, Client};

#[cfg(feature = "ink")]
pub use polymesh_api_ink as ink;

#[cfg(feature = "polymesh_v5")]
pub mod v5_to_v6 {
  // Generate Polymesh V5.x types from chain metadata.
  #[super::codegen_api(metadata_file = "specs/polymesh_dev_spec_5004000.meta")]
  pub mod polymesh {}

  // V6 types.
  use super::polymesh::types::{
      polymesh_primitives::{
          identity_id::{
            PortfolioId as PortfolioIdV6,
            PortfolioKind as PortfolioKindV6,
            PortfolioNumber as PortfolioNumberV6,
          },
          portfolio::{Fund, FundDescription},
          settlement::Leg as LegV6,
          ticker::Ticker as TickerV6,
          Memo as MemoV6,
      },
  };
  // V5 types.
  pub use polymesh::types::{
      pallet_portfolio::MovePortfolioItem,
      pallet_settlement::Leg,
      polymesh_common_utilities::traits::balances,
      polymesh_primitives::{
          identity_id::{
              PortfolioId,
              PortfolioKind,
              PortfolioNumber,
          },
          ticker::Ticker,
      },
  };

  impl From<balances::Memo> for MemoV6 {
    fn from(other: balances::Memo) -> Self {
      Self(other.0)
    }
  }

  impl From<Ticker> for TickerV6 {
    fn from(other: Ticker) -> Self {
      Self(other.0)
    }
  }

  impl From<TickerV6> for Ticker {
    fn from(other: TickerV6) -> Self {
      Self(other.0)
    }
  }

  impl From<PortfolioId> for PortfolioIdV6 {
    fn from(other: PortfolioId) -> Self {
      Self {
        did: other.did,
        kind: other.kind.into(),
      }
    }
  }

  impl From<PortfolioIdV6> for PortfolioId {
    fn from(other: PortfolioIdV6) -> Self {
      Self {
        did: other.did,
        kind: other.kind.into(),
      }
    }
  }

  impl From<PortfolioKind> for PortfolioKindV6 {
    fn from(other: PortfolioKind) -> Self {
      match other {
        PortfolioKind::Default => Self::Default,
        PortfolioKind::User(num) => Self::User(num.into()),
      }
    }
  }

  impl From<PortfolioKindV6> for PortfolioKind {
    fn from(other: PortfolioKindV6) -> Self {
      match other {
        PortfolioKindV6::Default => Self::Default,
        PortfolioKindV6::User(num) => Self::User(num.into()),
      }
    }
  }

  impl From<PortfolioNumber> for PortfolioNumberV6 {
    fn from(other: PortfolioNumber) -> Self {
      Self(other.0)
    }
  }

  impl From<PortfolioNumberV6> for PortfolioNumber {
    fn from(other: PortfolioNumberV6) -> Self {
      Self(other.0)
    }
  }

  impl From<MovePortfolioItem> for Fund {
    fn from(old: MovePortfolioItem) -> Self {
      Self {
        description: FundDescription::Fungible {
          ticker: old.ticker.into(),
          amount: old.amount,
        },
        memo: old.memo.map(|m| m.into()),
      }
    }
  }

  impl From<Leg> for LegV6 {
    fn from(old: Leg) -> Self {
      Self::Fungible {
        sender: old.from.into(),
        receiver: old.to.into(),
        ticker: old.asset.into(),
        amount: old.amount,
      }
    }
  }
}