1- use std:: { fs:: File , io:: Read } ;
1+ use std:: { fs:: File , io:: Read , path :: Path } ;
22
3- use anyhow:: { Result , anyhow } ;
3+ use anyhow:: { Context , Result } ;
44use clap:: { Parser , ValueEnum } ;
55use regex:: Regex ;
66use reqwest:: Client ;
@@ -42,32 +42,6 @@ pub enum ContractsSubcommands {
4242 #[ arg( long, default_value_t = ContractType :: Project ) ]
4343 contract_type : ContractType ,
4444 } ,
45- #[ command( visible_alias = "s" ) ]
46- State {
47- address : String ,
48- } ,
49- Code {
50- address : String ,
51- } ,
52- Test {
53- // body
54- } ,
55- Call {
56- // body
57- #[ arg( short, long) ]
58- multiple : Option < bool > ,
59- } ,
60- Parent {
61- address : String ,
62- } ,
63- SubContracts {
64- address : String ,
65- #[ arg( short, long) ]
66- current_count : Option < bool > ,
67- } ,
68- CallTxScript {
69- // body
70- } ,
7145}
7246
7347fn get_file_buffer ( file_path : & str ) -> Result < String > {
@@ -79,7 +53,7 @@ fn get_file_buffer(file_path: &str) -> Result<String> {
7953
8054pub async fn compile_file (
8155 url : & str ,
82- compiler_options_path : Option < String > ,
56+ compiler_options_path : Option < & str > ,
8357 file_buffer : & str ,
8458 end_point : & str ,
8559) -> Result < ( ) > {
@@ -106,7 +80,7 @@ pub async fn compile_file(
10680 } ) ;
10781
10882 let response = client. post ( url) . json ( & body) . send ( ) . await ?;
109- let value = response. json :: < Value > ( ) . await ?;
83+ let value: Value = response. json ( ) . await ?;
11084
11185 serde_json:: to_writer_pretty ( std:: io:: stdout ( ) , & value) ?;
11286 println ! ( ) ;
@@ -116,15 +90,15 @@ pub async fn compile_file(
11690
11791pub async fn compile_project (
11892 url : & str ,
119- compiler_options_path : Option < String > ,
93+ compiler_options_path : Option < & str > ,
12094 file_path : & str ,
12195) -> Result < ( ) > {
12296 let re = Regex :: new ( r#"^import "[^"./]+/[^"]*[a-z][a-z_0-9]*(\.ral)?"# ) ?;
12397
124- let file_path: & std :: path :: Path = std :: path :: Path :: new ( file_path) ;
98+ let file_path = Path :: new ( file_path) ;
12599 let project_cwd = file_path
126100 . parent ( )
127- . ok_or_else ( || anyhow ! ( "Invalid file path" ) ) ?
101+ . context ( "Invalid file path" ) ?
128102 . canonicalize ( ) ?;
129103
130104 let mut buffer = String :: new ( ) ;
@@ -154,11 +128,11 @@ pub async fn compile_project(
154128 project_cwd. join ( import_file) . into ( )
155129 } ;
156130
157- let path = path_buf. to_str ( ) . ok_or_else ( || anyhow ! ( "Invalid path" ) ) ?;
131+ let path = path_buf. to_str ( ) . context ( "Invalid path" ) ?;
158132
159133 Ok ( get_file_buffer ( path) ?)
160134 } )
161- . collect :: < Result < Vec < String > , anyhow :: Error > > ( ) ?;
135+ . collect :: < Result < Vec < _ > > > ( ) ?;
162136
163137 compile_file (
164138 url,
@@ -170,10 +144,10 @@ pub async fn compile_project(
170144}
171145
172146pub async fn deploy_contract (
173- url : String ,
174- public_key : String ,
147+ url : & str ,
148+ public_key : & str ,
175149 network : NetworkType ,
176- compile_output_path : String ,
150+ compile_output_path : & str ,
177151) -> Result < ( ) > {
178152 let client = Client :: new ( ) ;
179153 let url = format ! ( "{url}/contracts/unsigned-tx/deploy-contract" ) ;
@@ -187,17 +161,17 @@ pub async fn deploy_contract(
187161
188162 let contracts = compile_output[ "contracts" ]
189163 . as_array ( )
190- . ok_or_else ( || anyhow ! ( "contracts Not an array" ) ) ?
164+ . context ( "contracts Not an array" ) ?
191165 . get ( 0 )
192- . ok_or_else ( || anyhow ! ( "no contracts in array" ) ) ;
166+ . context ( "no contracts in array" ) ;
193167
194168 for contract in contracts. iter ( ) {
195169 let byte_code = contract[ "bytecode" ]
196170 . as_str ( )
197- . ok_or_else ( || anyhow ! ( "Bytecode not found" ) ) ?;
171+ . context ( "Bytecode not found" ) ?;
198172 let byte_code_debug = contract[ "bytecodeDebugPatch" ]
199173 . as_str ( )
200- . ok_or_else ( || anyhow ! ( "Bytecode not found" ) ) ?;
174+ . context ( "Bytecode not found" ) ?;
201175
202176 let fields = & contract[ "fields" ] ;
203177 let final_byte_code =
@@ -228,19 +202,19 @@ impl ContractsSubcommands {
228202 ContractType :: Contract => {
229203 compile_file (
230204 & url,
231- compiler_options_path,
205+ compiler_options_path. as_deref ( ) ,
232206 & get_file_buffer ( & file_path) ?,
233207 "/compile-contract" ,
234208 )
235209 . await ?
236210 } ,
237211 ContractType :: Project => {
238- compile_project ( & url, compiler_options_path, & file_path) . await ?
212+ compile_project ( & url, compiler_options_path. as_deref ( ) , & file_path) . await ?
239213 } ,
240214 ContractType :: Script => {
241215 compile_file (
242216 & url,
243- compiler_options_path,
217+ compiler_options_path. as_deref ( ) ,
244218 & get_file_buffer ( & file_path) ?,
245219 "/compile-script" ,
246220 )
@@ -255,11 +229,10 @@ impl ContractsSubcommands {
255229 } => match contract_type {
256230 // Problems with devnet bytecode, doesn't deploy
257231 ContractType :: Contract => {
258- deploy_contract ( url, public_key, network, compile_output_path) . await ?
232+ deploy_contract ( & url, & public_key, network, & compile_output_path) . await ?
259233 } ,
260- _ => todo ! ( "Contract type not yet deployable " ) ,
234+ _ => unimplemented ! ( "Contract type not supported yet " ) ,
261235 } ,
262- _ => todo ! ( ) ,
263236 }
264237
265238 Ok ( ( ) )
0 commit comments