1use cyfs_base::*;
2use super::types::*;
3use super::block::{BlockHash};
4use crate::{SavedMetaObject, Receipt, MetaTx, Block, NFTDesc, NFTState};
5use serde::{Deserialize, Serialize};
6use primitive_types::H256;
7
8#[derive(RawEncode, RawDecode)]
9pub enum ViewBlockEnum {
10 Tip,
11 Number(i64),
12 Hash(BlockHash),
13}
14
15pub trait ViewMethod {
16 type Result;
17}
18
19#[derive(RawEncode, RawDecode)]
21pub struct ViewBalanceMethod {
22 pub account: ObjectId,
23 pub ctid: Vec<CoinTokenId>
24}
25
26type ViewSignleBalanceResult = Vec<(CoinTokenId, i64)>;
27type ViewUnionBalanceResult = Vec<(CoinTokenId, UnionBalance, i64)>;
28
29#[derive(RawEncode, RawDecode)]
30pub enum ViewBalanceResult {
31 Single(ViewSignleBalanceResult),
32 Union(ViewUnionBalanceResult)
33}
34
35impl ViewMethod for ViewBalanceMethod {
36 type Result = ViewBalanceResult;
37}
38
39#[derive(RawEncode, RawDecode)]
41pub struct ViewNameMethod {
42 pub name: String
43}
44
45type ViewNameResult = Option<(NameInfo, NameState)>;
46
47impl ViewMethod for ViewNameMethod {
48 type Result = ViewNameResult;
49}
50
51#[derive(RawEncode, RawDecode)]
53pub struct ViewDescMethod {
54 pub id: ObjectId
55}
56
57type ViewDescResult = SavedMetaObject;
58
59impl ViewMethod for ViewDescMethod {
60 type Result = ViewDescResult;
61}
62
63#[derive(RawEncode, RawDecode)]
64pub struct ViewRawMethod {
65 pub id: ObjectId
66}
67
68impl ViewMethod for ViewRawMethod {
69 type Result = Vec<u8>;
70}
71
72#[derive(Serialize, Deserialize, RawEncode, RawDecode)]
73pub struct GasPrice {
74 pub low: i64,
75 pub medium: i64,
76 pub high: i64,
77}
78
79#[derive(Serialize, Deserialize, RawEncode, RawDecode)]
80pub struct ChainStatus {
81 pub version: u32,
82 pub height: i64,
83 pub gas_price: GasPrice,
84}
85
86
87#[derive(RawEncode, RawDecode)]
88pub enum ViewMethodEnum {
89 ViewBalance(ViewBalanceMethod),
90 ViewName(ViewNameMethod),
91 ViewDesc(ViewDescMethod),
92 ViewRaw(ViewRawMethod),
93 ViewStatus,
94 ViewBlock,
95 ViewTx(ObjectId),
96 ViewContract(ViewContract),
97 ViewBenifi(ViewBenefi),
98 ViewLog(ViewLog),
99 ViewNFT(ObjectId),
100 ViewNFTApplyBuyList((ObjectId, u32, u8)),
101 ViewNFTBidList((ObjectId, u32, u8)),
102 ViewNFTLargestBuyValue(ObjectId),
103}
104
105impl ViewMethodEnum {
106 pub fn method_name(&self) -> &'static str {
107 match self {
108 ViewMethodEnum::ViewBalance(_) => {"balance"}
109 ViewMethodEnum::ViewName(_) => {"name"}
110 ViewMethodEnum::ViewDesc(_) => {"desc"}
111 ViewMethodEnum::ViewRaw(_) => {"raw"}
112 ViewMethodEnum::ViewStatus => {"status"}
113 ViewMethodEnum::ViewBlock => {"block"}
114 ViewMethodEnum::ViewTx(_) => {"tx"}
115 ViewMethodEnum::ViewContract(_) => {"contract"}
116 ViewMethodEnum::ViewBenifi(_) => {"benefi"}
117 ViewMethodEnum::ViewLog(_) => {"log"}
118 ViewMethodEnum::ViewNFT(_) => {"nft"}
119 ViewMethodEnum::ViewNFTApplyBuyList(_) => {"nftapply"}
120 ViewMethodEnum::ViewNFTBidList(_) => {"nftbid"}
121 ViewMethodEnum::ViewNFTLargestBuyValue(_) => {"nftlargest"}
122 }
123 }
124}
125
126#[derive(RawEncode, RawDecode)]
127pub struct ViewRequest {
128 pub block: ViewBlockEnum,
129 pub method: ViewMethodEnum
130}
131
132#[derive(RawEncode, RawDecode)]
133pub enum ViewResponse {
134 ViewBalance(<ViewBalanceMethod as ViewMethod>::Result),
135 ViewName(<ViewNameMethod as ViewMethod>::Result),
136 ViewDesc(<ViewDescMethod as ViewMethod>::Result),
137 ViewRaw(<ViewRawMethod as ViewMethod>::Result),
138 ViewStatus(ChainStatus),
139 ViewBlock(Block),
140 ViewTx(TxFullInfo),
141 ViewContract(ViewContractResult),
142 ViewBenefi(ViewBenefiResult),
143 ViewLog(ViewLogResult),
144 ViewNFT((NFTDesc, String, ObjectId, NFTState)),
145 ViewNFTApplyBuyList(ViewNFTBuyListResult),
146 ViewNFTBidList(ViewNFTBuyListResult),
147 ViewNFTLargestBuyValue(Option<(ObjectId, CoinTokenId, u64)>)
148}
149
150#[derive(RawEncode, RawDecode)]
151pub struct TxFullInfo {
152 pub status: u8,
153 pub block_number: i64,
154 pub tx: MetaTx,
155 pub receipt: Option<Receipt>,
156}
157
158#[derive(RawEncode, RawDecode)]
159pub struct ViewContract {
160 pub address: ObjectId,
161 pub data: Vec<u8>
162}
163
164#[derive(RawEncode, RawDecode)]
165pub struct ViewContractResult {
166 pub ret: u32,
167 pub value: Vec<u8>
168}
169
170impl ViewMethod for ViewContract {
171 type Result = ViewContractResult;
172}
173
174#[derive(RawEncode, RawDecode)]
175pub struct ViewBenefi {
176 pub address: ObjectId,
177}
178
179#[derive(RawEncode, RawDecode)]
180pub struct ViewBenefiResult {
181 pub address: ObjectId
182}
183
184impl ViewMethod for ViewBenefi {
185 type Result = ViewBenefiResult;
186}
187
188#[derive(RawEncode, RawDecode)]
189pub struct ViewLog {
190 pub address: ObjectId,
191 pub topics: Vec<Option<H256>>,
192 pub from :i64,
193 pub to :i64
194}
195
196#[derive(RawEncode, RawDecode)]
197pub struct ViewLogResult {
198 pub logs: Vec<(Vec<H256>, Vec<u8>)>
199}
200
201#[derive(RawEncode, RawDecode)]
202pub struct NFTBuyItem {
203 pub buyer_id: ObjectId,
204 pub price: u64,
205 pub coin_id: CoinTokenId,
206}
207
208#[derive(RawEncode, RawDecode)]
209pub struct ViewNFTBuyListResult {
210 pub sum: u32,
211 pub list: Vec<NFTBuyItem>
212}
213
214impl ViewMethod for ViewLog {
215 type Result = ViewLogResult;
216}