|
1 | | -use libra::{prelude::*, vm::*}; |
| 1 | +use libra::prelude::*; |
2 | 2 | use lang::bytecode::extract_script_params; |
3 | 3 | use crate::{tonic, api}; |
4 | 4 | use tonic::{Request, Response, Status}; |
5 | 5 | use api::grpc::vm_grpc::vm_script_metadata_server::VmScriptMetadata; |
6 | | -use api::grpc::vm_grpc::vm_access_vector_server::VmAccessVector; |
7 | 6 | use api::grpc::vm_grpc::{Signature, VmScript, VmTypeTag}; |
8 | 7 | use info::metrics::meter::ScopeMeter; |
9 | 8 | use info::metrics::execution::ExecutionResult; |
10 | | -use dvm_net::api::grpc::vm_grpc::{AccessVector, StructIdent, LcsTag, LcsType}; |
11 | | -use std::convert::TryFrom; |
12 | | -use anyhow::Error; |
13 | 9 |
|
14 | 10 | /// Metadata service. |
15 | 11 | /// Provides a function to retrieve metadata for the script. |
@@ -61,105 +57,3 @@ impl VmScriptMetadata for MetadataService { |
61 | 57 | Ok(Response::new(Signature::new(&arg_types))) |
62 | 58 | } |
63 | 59 | } |
64 | | - |
65 | | -#[tonic::async_trait] |
66 | | -impl VmAccessVector for MetadataService { |
67 | | - async fn get_access_vector( |
68 | | - &self, |
69 | | - request: Request<StructIdent>, |
70 | | - ) -> Result<Response<AccessVector>, Status> { |
71 | | - let mut meter = ScopeMeter::new("get_access_vector"); |
72 | | - match Ident::try_from(request.into_inner()) { |
73 | | - Ok(ident) => { |
74 | | - meter.set_result(ExecutionResult::new(true, 200, 0)); |
75 | | - Ok(Response::new(AccessVector { |
76 | | - access_vector: ident.as_ref().access_vector(), |
77 | | - })) |
78 | | - } |
79 | | - Err(err) => { |
80 | | - meter.set_result(ExecutionResult::new(false, 400, 0)); |
81 | | - Err(Status::unimplemented(format!( |
82 | | - "Unsupported struct signature. {}", |
83 | | - err |
84 | | - ))) |
85 | | - } |
86 | | - } |
87 | | - } |
88 | | -} |
89 | | - |
90 | | -/// StructTag wrapper. |
91 | | -struct Ident(StructTag); |
92 | | - |
93 | | -impl AsRef<StructTag> for Ident { |
94 | | - fn as_ref(&self) -> &StructTag { |
95 | | - &self.0 |
96 | | - } |
97 | | -} |
98 | | - |
99 | | -impl Into<StructTag> for Ident { |
100 | | - fn into(self) -> StructTag { |
101 | | - self.0 |
102 | | - } |
103 | | -} |
104 | | - |
105 | | -impl TryFrom<StructIdent> for Ident { |
106 | | - type Error = Error; |
107 | | - |
108 | | - fn try_from(value: StructIdent) -> Result<Self, Self::Error> { |
109 | | - let type_params = value |
110 | | - .type_params |
111 | | - .into_iter() |
112 | | - .map(|p| TypeIdent::try_from(p).map(|t| t.into())) |
113 | | - .collect::<Result<Vec<TypeTag>, Error>>()?; |
114 | | - |
115 | | - Ok(Ident(StructTag { |
116 | | - address: AccountAddress::try_from(value.address)?, |
117 | | - module: Identifier::new(value.module)?, |
118 | | - name: Identifier::new(value.name)?, |
119 | | - type_params, |
120 | | - })) |
121 | | - } |
122 | | -} |
123 | | - |
124 | | -/// TypeTag wrapper. |
125 | | -struct TypeIdent(TypeTag); |
126 | | - |
127 | | -impl Into<TypeTag> for TypeIdent { |
128 | | - fn into(self) -> TypeTag { |
129 | | - self.0 |
130 | | - } |
131 | | -} |
132 | | - |
133 | | -impl TryFrom<LcsTag> for TypeIdent { |
134 | | - type Error = Error; |
135 | | - |
136 | | - fn try_from(value: LcsTag) -> Result<Self, Self::Error> { |
137 | | - let lcs_type = |
138 | | - LcsType::from_i32(value.type_tag).ok_or_else(|| anyhow!("Invalid type tag."))?; |
139 | | - |
140 | | - let tag = match lcs_type { |
141 | | - LcsType::LcsBool => TypeTag::Bool, |
142 | | - LcsType::LcsU64 => TypeTag::U64, |
143 | | - LcsType::LcsVector => { |
144 | | - let vec_type = value |
145 | | - .vector_type |
146 | | - .ok_or_else(|| anyhow!("Vector_Type is required for LcsType::LcsVector."))?; |
147 | | - TypeTag::Vector(Box::new( |
148 | | - TypeIdent::try_from(vec_type.as_ref().clone())?.into(), |
149 | | - )) |
150 | | - } |
151 | | - LcsType::LcsAddress => TypeTag::Address, |
152 | | - LcsType::LcsU8 => TypeTag::U8, |
153 | | - LcsType::LcsU128 => TypeTag::U128, |
154 | | - LcsType::LcsSigner => TypeTag::Signer, |
155 | | - LcsType::LcsStruct => { |
156 | | - let struct_ident = value |
157 | | - .struct_ident |
158 | | - .ok_or_else(|| anyhow!("StructIdent is required for LcsType::LcsStruct."))?; |
159 | | - TypeTag::Struct(Ident::try_from(struct_ident)?.into()) |
160 | | - } |
161 | | - }; |
162 | | - |
163 | | - Ok(TypeIdent(tag)) |
164 | | - } |
165 | | -} |
0 commit comments