contract_extrinsics/
extrinsic_opts.rs1use anyhow::Result;
18use contract_build::Verbosity;
19use derivative::Derivative;
20use ink_env::Environment;
21use subxt::{
22 Config,
23 tx,
24};
25use url::Url;
26
27use crate::{
28 ContractArtifacts,
29 url_to_string,
30};
31use std::{
32 marker::PhantomData,
33 option::Option,
34 path::PathBuf,
35};
36
37#[derive(Derivative)]
39#[derivative(Clone(bound = "E::Balance: Clone"))]
40pub struct ExtrinsicOpts<C: Config, E: Environment, Signer: Clone> {
41 file: Option<PathBuf>,
42 manifest_path: Option<PathBuf>,
43 url: url::Url,
44 signer: Signer,
45 storage_deposit_limit: Option<E::Balance>,
46 verbosity: Verbosity,
47 _marker: PhantomData<C>,
48}
49
50pub struct ExtrinsicOptsBuilder<C: Config, E: Environment, Signer: Clone> {
51 opts: ExtrinsicOpts<C, E, Signer>,
52}
53
54impl<C: Config, E: Environment, Signer> ExtrinsicOptsBuilder<C, E, Signer>
55where
56 Signer: tx::Signer<C> + Clone,
57{
58 pub fn new(signer: Signer) -> ExtrinsicOptsBuilder<C, E, Signer> {
60 ExtrinsicOptsBuilder {
61 opts: ExtrinsicOpts {
62 file: None,
63 manifest_path: None,
64 url: url::Url::parse("ws://localhost:9944").unwrap(),
65 signer,
66 storage_deposit_limit: None,
67 verbosity: Verbosity::Default,
68 _marker: PhantomData,
69 },
70 }
71 }
72
73 pub fn file<T: Into<PathBuf>>(self, file: Option<T>) -> Self {
75 let mut this = self;
76 this.opts.file = file.map(|f| f.into());
77 this
78 }
79
80 pub fn manifest_path<T: Into<PathBuf>>(self, manifest_path: Option<T>) -> Self {
82 let mut this = self;
83 this.opts.manifest_path = manifest_path.map(|f| f.into());
84 this
85 }
86
87 pub fn url<T: Into<Url>>(self, url: T) -> Self {
89 let mut this = self;
90 this.opts.url = url.into();
91 this
92 }
93
94 pub fn storage_deposit_limit(
97 self,
98 storage_deposit_limit: Option<E::Balance>,
99 ) -> Self {
100 let mut this = self;
101 this.opts.storage_deposit_limit = storage_deposit_limit;
102 this
103 }
104
105 pub fn verbosity(self, verbosity: Verbosity) -> Self {
107 let mut this = self;
108 this.opts.verbosity = verbosity;
109 this
110 }
111
112 pub fn done(self) -> ExtrinsicOpts<C, E, Signer> {
113 self.opts
114 }
115}
116
117impl<C: Config, E: Environment, Signer> ExtrinsicOpts<C, E, Signer>
118where
119 Signer: tx::Signer<C> + Clone,
120{
121 pub fn contract_artifacts(&self) -> Result<ContractArtifacts> {
123 ContractArtifacts::from_manifest_or_file(
124 self.manifest_path.as_ref(),
125 self.file.as_ref(),
126 )
127 }
128
129 pub fn set_storage_deposit_limit(&mut self, limit: Option<E::Balance>) {
131 self.storage_deposit_limit = limit;
132 }
133
134 pub fn file(&self) -> Option<&PathBuf> {
136 self.file.as_ref()
137 }
138
139 pub fn manifest_path(&self) -> Option<&PathBuf> {
141 self.manifest_path.as_ref()
142 }
143
144 pub fn url(&self) -> String {
146 url_to_string(&self.url)
147 }
148
149 pub fn signer(&self) -> &Signer {
151 &self.signer
152 }
153
154 pub fn storage_deposit_limit(&self) -> Option<E::Balance> {
156 self.storage_deposit_limit
157 }
158
159 pub fn verbosity(&self) -> &Verbosity {
161 &self.verbosity
162 }
163}