11//! Calls to the `solana` CLI.
2+
23use anchor_client:: Cluster ;
34use anyhow:: Result ;
45use solana_sdk:: pubkey:: Pubkey ;
@@ -7,105 +8,106 @@ use std::{
78 process:: { Command , Output } ,
89} ;
910
10- use crate :: {
11- utils:: { exec_command, get_cluster_url} ,
12- workspace:: Workspace ,
13- } ;
11+ use crate :: { utils:: exec_command, workspace:: Workspace } ;
1412
15- /// Sets the buffer authority of a buffer.
16- pub fn set_buffer_authority (
17- workspace : & Workspace ,
18- cluster : & Cluster ,
19- buffer_key : & Pubkey ,
20- authority : & str ,
21- ) -> Result < Output > {
22- workspace. exec_deployer_command ( cluster, |cmd : & mut Command | {
23- cmd. arg ( "program" )
24- . arg ( "set-buffer-authority" )
25- . arg ( buffer_key. to_string ( ) )
26- . arg ( "--new-buffer-authority" )
27- . arg ( authority) ;
28- Ok ( ( ) )
29- } )
30- }
13+ impl Workspace {
14+ /// Sets the buffer authority of a buffer.
15+ pub fn set_buffer_authority (
16+ & self ,
17+ cluster : & Cluster ,
18+ buffer_key : & Pubkey ,
19+ authority : & str ,
20+ ) -> Result < Output > {
21+ self . exec_deployer_command ( cluster, |cmd : & mut Command | {
22+ cmd. arg ( "program" )
23+ . arg ( "set-buffer-authority" )
24+ . arg ( buffer_key. to_string ( ) )
25+ . arg ( "--new-buffer-authority" )
26+ . arg ( authority) ;
27+ Ok ( ( ) )
28+ } )
29+ }
3130
32- /// Sets the upgrade authority of a program.
33- pub fn set_upgrade_authority (
34- cluster : & Cluster ,
35- program_id : & Pubkey ,
36- current_authority : & Path ,
37- new_authority : & str ,
38- ) -> Result < Output > {
39- exec_command (
40- std:: process:: Command :: new ( "solana" )
41- . arg ( "--url" )
42- . arg ( get_cluster_url ( cluster) ?)
43- . arg ( "--keypair" )
44- . arg ( current_authority)
45- . arg ( "program" )
46- . arg ( "set-upgrade-authority" )
47- . arg ( program_id. to_string ( ) )
48- . arg ( "--new-upgrade-authority" )
49- . arg ( new_authority) ,
50- )
51- }
31+ /// Sets the upgrade authority of a program.
32+ pub fn set_upgrade_authority (
33+ & self ,
34+ cluster : & Cluster ,
35+ program_id : & Pubkey ,
36+ current_authority : & Path ,
37+ new_authority : & str ,
38+ ) -> Result < Output > {
39+ exec_command (
40+ std:: process:: Command :: new ( "solana" )
41+ . arg ( "--url" )
42+ . arg ( self . get_cluster_url ( cluster) ?)
43+ . arg ( "--keypair" )
44+ . arg ( current_authority)
45+ . arg ( "program" )
46+ . arg ( "set-upgrade-authority" )
47+ . arg ( program_id. to_string ( ) )
48+ . arg ( "--new-upgrade-authority" )
49+ . arg ( new_authority) ,
50+ )
51+ }
5252
53- /// Writes a program buffer.
54- pub fn write_buffer (
55- workspace : & Workspace ,
56- cluster : & Cluster ,
57- program_file : & Path ,
58- buffer_kp_file : & Path ,
59- ) -> Result < Output > {
60- workspace . exec_deployer_command ( cluster, |cmd| {
61- cmd. arg ( "program" )
62- . arg ( "write-buffer" )
63- . arg ( program_file)
64- . arg ( "--buffer" )
65- . arg ( buffer_kp_file) ;
66- Ok ( ( ) )
67- } )
68- }
53+ /// Writes a program buffer.
54+ pub fn write_buffer (
55+ & self ,
56+ cluster : & Cluster ,
57+ program_file : & Path ,
58+ buffer_kp_file : & Path ,
59+ ) -> Result < Output > {
60+ self . exec_deployer_command ( cluster, |cmd| {
61+ cmd. arg ( "program" )
62+ . arg ( "write-buffer" )
63+ . arg ( program_file)
64+ . arg ( "--buffer" )
65+ . arg ( buffer_kp_file) ;
66+ Ok ( ( ) )
67+ } )
68+ }
6969
70- /// Deploys a program.
71- pub fn deploy (
72- workspace : & Workspace ,
73- cluster : & Cluster ,
74- program_file : & Path ,
75- program_kp_path : & Path ,
76- ) -> Result < Output > {
77- workspace . exec_deployer_command ( cluster, |cmd| {
78- cmd. arg ( "program" )
79- . arg ( "deploy" )
80- . arg ( "--program-id" )
81- . arg ( program_kp_path)
82- . arg ( program_file) ;
83- Ok ( ( ) )
84- } )
85- }
70+ /// Deploys a program.
71+ pub fn deploy (
72+ & self ,
73+ cluster : & Cluster ,
74+ program_file : & Path ,
75+ program_kp_path : & Path ,
76+ ) -> Result < Output > {
77+ self . exec_deployer_command ( cluster, |cmd| {
78+ cmd. arg ( "program" )
79+ . arg ( "deploy" )
80+ . arg ( "--program-id" )
81+ . arg ( program_kp_path)
82+ . arg ( program_file) ;
83+ Ok ( ( ) )
84+ } )
85+ }
8686
87- /// Upgrades a program.
88- pub fn upgrade (
89- cluster : & Cluster ,
90- upgrade_authority_kp : & str ,
91- buffer_key : & Pubkey ,
92- program_id : & str ,
93- ) -> Result < Output > {
94- exec_command (
95- std:: process:: Command :: new ( "solana" )
96- . arg ( "--url" )
97- . arg ( get_cluster_url ( cluster) ?)
98- . arg ( "--keypair" )
99- . arg ( upgrade_authority_kp)
100- . arg ( "program" )
101- . arg ( "deploy" )
102- . arg ( "--buffer" )
103- . arg ( buffer_key. to_string ( ) )
104- . arg ( "--program-id" )
105- . arg ( program_id)
106- . arg ( "--upgrade-authority" )
107- . arg ( upgrade_authority_kp) ,
108- )
87+ /// Upgrades a program.
88+ pub fn upgrade (
89+ & self ,
90+ cluster : & Cluster ,
91+ upgrade_authority_kp : & str ,
92+ buffer_key : & Pubkey ,
93+ program_id : & str ,
94+ ) -> Result < Output > {
95+ exec_command (
96+ std:: process:: Command :: new ( "solana" )
97+ . arg ( "--url" )
98+ . arg ( self . get_cluster_url ( cluster) ?)
99+ . arg ( "--keypair" )
100+ . arg ( upgrade_authority_kp)
101+ . arg ( "program" )
102+ . arg ( "deploy" )
103+ . arg ( "--buffer" )
104+ . arg ( buffer_key. to_string ( ) )
105+ . arg ( "--program-id" )
106+ . arg ( program_id)
107+ . arg ( "--upgrade-authority" )
108+ . arg ( upgrade_authority_kp) ,
109+ )
110+ }
109111}
110112
111113pub fn new_solana_cmd ( ) -> Command {
0 commit comments