Skip to content

Commit 66ac385

Browse files
authored
docs: add docs for starknet-accounts (#640)
1 parent d297f81 commit 66ac385

File tree

9 files changed

+303
-4
lines changed

9 files changed

+303
-4
lines changed

starknet-accounts/src/account/declaration.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ const QUERY_VERSION_THREE: Felt = Felt::from_raw([
5252
]);
5353

5454
impl<'a, A> DeclarationV2<'a, A> {
55+
/// Constructs a new [`DeclarationV2`].
56+
///
57+
/// Users would typically use [`declare_v2`](fn.declare_v2) on an [`Account`] instead of
58+
/// directly calling this method.
5559
pub const fn new(
5660
contract_class: Arc<FlattenedSierraClass>,
5761
compiled_class_hash: Felt,
@@ -67,20 +71,25 @@ impl<'a, A> DeclarationV2<'a, A> {
6771
}
6872
}
6973

74+
/// Returns a new [`DeclarationV2`] with the `nonce`.
7075
pub fn nonce(self, nonce: Felt) -> Self {
7176
Self {
7277
nonce: Some(nonce),
7378
..self
7479
}
7580
}
7681

82+
/// Returns a new [`DeclarationV2`] with the `max_fee`.
7783
pub fn max_fee(self, max_fee: Felt) -> Self {
7884
Self {
7985
max_fee: Some(max_fee),
8086
..self
8187
}
8288
}
8389

90+
/// Returns a new [`DeclarationV2`] with the fee estimate multiplier. The multiplier is used
91+
/// when transaction fee is not manually specified and must be fetched from a [`Provider`]
92+
/// instead.
8493
pub fn fee_estimate_multiplier(self, fee_estimate_multiplier: f64) -> Self {
8594
Self {
8695
fee_estimate_multiplier,
@@ -110,6 +119,7 @@ impl<'a, A> DeclarationV2<'a, A>
110119
where
111120
A: ConnectedAccount + Sync,
112121
{
122+
/// Estimates transaction fees from a [`Provider`].
113123
pub async fn estimate_fee(&self) -> Result<FeeEstimate, AccountError<A::SignError>> {
114124
// Resolves nonce
115125
let nonce = match self.nonce {
@@ -124,6 +134,8 @@ where
124134
self.estimate_fee_with_nonce(nonce).await
125135
}
126136

137+
/// Simulates the transaction from a [`Provider`]. Transaction validation and fee transfer can
138+
/// be skipped.
127139
pub async fn simulate(
128140
&self,
129141
skip_validate: bool,
@@ -143,6 +155,7 @@ where
143155
.await
144156
}
145157

158+
/// Signs and broadcasts the transaction to the network.
146159
pub async fn send(&self) -> Result<DeclareTransactionResult, AccountError<A::SignError>> {
147160
self.prepare().await?.send().await
148161
}
@@ -275,6 +288,10 @@ where
275288
}
276289

277290
impl<'a, A> DeclarationV3<'a, A> {
291+
/// Constructs a new [`DeclarationV3`].
292+
///
293+
/// Users would typically use [`declare_v3`](fn.declare_v3) on an [`Account`] instead of
294+
/// directly calling this method.
278295
pub const fn new(
279296
contract_class: Arc<FlattenedSierraClass>,
280297
compiled_class_hash: Felt,
@@ -292,34 +309,43 @@ impl<'a, A> DeclarationV3<'a, A> {
292309
}
293310
}
294311

312+
/// Returns a new [`DeclarationV3`] with the `nonce`.
295313
pub fn nonce(self, nonce: Felt) -> Self {
296314
Self {
297315
nonce: Some(nonce),
298316
..self
299317
}
300318
}
301319

320+
/// Returns a new [`DeclarationV3`] with the `gas`.
302321
pub fn gas(self, gas: u64) -> Self {
303322
Self {
304323
gas: Some(gas),
305324
..self
306325
}
307326
}
308327

328+
/// Returns a new [`DeclarationV3`] with the `gas_price`.
309329
pub fn gas_price(self, gas_price: u128) -> Self {
310330
Self {
311331
gas_price: Some(gas_price),
312332
..self
313333
}
314334
}
315335

336+
/// Returns a new [`DeclarationV3`] with the gas amount estimate multiplier. The multiplier is
337+
/// used when the gas amount is not manually specified and must be fetched from a [`Provider`]
338+
/// instead.
316339
pub fn gas_estimate_multiplier(self, gas_estimate_multiplier: f64) -> Self {
317340
Self {
318341
gas_estimate_multiplier,
319342
..self
320343
}
321344
}
322345

346+
/// Returns a new [`DeclarationV3`] with the gas price estimate multiplier. The multiplier is
347+
/// used when the gas price is not manually specified and must be fetched from a [`Provider`]
348+
/// instead.
323349
pub fn gas_price_estimate_multiplier(self, gas_price_estimate_multiplier: f64) -> Self {
324350
Self {
325351
gas_price_estimate_multiplier,
@@ -351,6 +377,7 @@ impl<'a, A> DeclarationV3<'a, A>
351377
where
352378
A: ConnectedAccount + Sync,
353379
{
380+
/// Estimates transaction fees from a [`Provider`].
354381
pub async fn estimate_fee(&self) -> Result<FeeEstimate, AccountError<A::SignError>> {
355382
// Resolves nonce
356383
let nonce = match self.nonce {
@@ -365,6 +392,8 @@ where
365392
self.estimate_fee_with_nonce(nonce).await
366393
}
367394

395+
/// Simulates the transaction from a [`Provider`]. Transaction validation and fee transfer can
396+
/// be skipped.
368397
pub async fn simulate(
369398
&self,
370399
skip_validate: bool,
@@ -384,6 +413,7 @@ where
384413
.await
385414
}
386415

416+
/// Signs and broadcasts the transaction to the network.
387417
pub async fn send(&self) -> Result<DeclareTransactionResult, AccountError<A::SignError>> {
388418
self.prepare().await?.send().await
389419
}
@@ -570,6 +600,10 @@ where
570600
}
571601

572602
impl<'a, A> LegacyDeclaration<'a, A> {
603+
/// Constructs a new [`LegacyDeclaration`].
604+
///
605+
/// Users would typically use [`declare_legacy`](fn.declare_legacy) on an [`Account`] instead of
606+
/// directly calling this method.
573607
pub const fn new(contract_class: Arc<LegacyContractClass>, account: &'a A) -> Self {
574608
Self {
575609
account,
@@ -580,20 +614,25 @@ impl<'a, A> LegacyDeclaration<'a, A> {
580614
}
581615
}
582616

617+
/// Returns a new [`LegacyDeclaration`] with the `nonce`.
583618
pub fn nonce(self, nonce: Felt) -> Self {
584619
Self {
585620
nonce: Some(nonce),
586621
..self
587622
}
588623
}
589624

625+
/// Returns a new [`LegacyDeclaration`] with the `max_fee`.
590626
pub fn max_fee(self, max_fee: Felt) -> Self {
591627
Self {
592628
max_fee: Some(max_fee),
593629
..self
594630
}
595631
}
596632

633+
/// Returns a new [`LegacyDeclaration`] with the fee estimate multiplier. The multiplier is used
634+
/// when transaction fee is not manually specified and must be fetched from a [`Provider`]
635+
/// instead.
597636
pub fn fee_estimate_multiplier(self, fee_estimate_multiplier: f64) -> Self {
598637
Self {
599638
fee_estimate_multiplier,
@@ -623,6 +662,7 @@ impl<'a, A> LegacyDeclaration<'a, A>
623662
where
624663
A: ConnectedAccount + Sync,
625664
{
665+
/// Estimates transaction fees from a [`Provider`].
626666
pub async fn estimate_fee(&self) -> Result<FeeEstimate, AccountError<A::SignError>> {
627667
// Resolves nonce
628668
let nonce = match self.nonce {
@@ -637,6 +677,8 @@ where
637677
self.estimate_fee_with_nonce(nonce).await
638678
}
639679

680+
/// Simulates the transaction from a [`Provider`]. Transaction validation and fee transfer can
681+
/// be skipped.
640682
pub async fn simulate(
641683
&self,
642684
skip_validate: bool,
@@ -656,6 +698,7 @@ where
656698
.await
657699
}
658700

701+
/// Signs and broadcasts the transaction to the network.
659702
pub async fn send(&self) -> Result<DeclareTransactionResult, AccountError<A::SignError>> {
660703
self.prepare().await?.send().await
661704
}
@@ -787,6 +830,7 @@ where
787830
}
788831

789832
impl RawDeclarationV2 {
833+
/// Calculates transaction hash given `chain_id`, `address`, and `query_only`.
790834
pub fn transaction_hash(&self, chain_id: Felt, address: Felt, query_only: bool) -> Felt {
791835
compute_hash_on_elements(&[
792836
PREFIX_DECLARE,
@@ -805,24 +849,29 @@ impl RawDeclarationV2 {
805849
])
806850
}
807851

852+
/// Gets a reference to the flattened Sierra (Cairo 1) class being declared.
808853
pub fn contract_class(&self) -> &FlattenedSierraClass {
809854
&self.contract_class
810855
}
811856

857+
/// Gets the CASM class hash corresponding to the Sierra class being declared.
812858
pub const fn compiled_class_hash(&self) -> Felt {
813859
self.compiled_class_hash
814860
}
815861

862+
/// Gets the `nonce` of the declaration request.
816863
pub const fn nonce(&self) -> Felt {
817864
self.nonce
818865
}
819866

867+
/// Gets the `max_fee` of the declaration request.
820868
pub const fn max_fee(&self) -> Felt {
821869
self.max_fee
822870
}
823871
}
824872

825873
impl RawDeclarationV3 {
874+
/// Calculates transaction hash given `chain_id`, `address`, and `query_only`.
826875
pub fn transaction_hash(&self, chain_id: Felt, address: Felt, query_only: bool) -> Felt {
827876
let mut hasher = PoseidonHasher::new();
828877

@@ -876,28 +925,34 @@ impl RawDeclarationV3 {
876925
hasher.finalize()
877926
}
878927

928+
/// Gets a reference to the flattened Sierra (Cairo 1) class being declared.
879929
pub fn contract_class(&self) -> &FlattenedSierraClass {
880930
&self.contract_class
881931
}
882932

933+
/// Gets the CASM class hash corresponding to the Sierra class being declared.
883934
pub const fn compiled_class_hash(&self) -> Felt {
884935
self.compiled_class_hash
885936
}
886937

938+
/// Gets the `nonce` of the declaration request.
887939
pub const fn nonce(&self) -> Felt {
888940
self.nonce
889941
}
890942

943+
/// Gets the `gas` of the declaration request.
891944
pub const fn gas(&self) -> u64 {
892945
self.gas
893946
}
894947

948+
/// Gets the `gas_price` of the declaration request.
895949
pub const fn gas_price(&self) -> u128 {
896950
self.gas_price
897951
}
898952
}
899953

900954
impl RawLegacyDeclaration {
955+
/// Calculates transaction hash given `chain_id`, `address`, and `query_only`.
901956
pub fn transaction_hash(
902957
&self,
903958
chain_id: Felt,
@@ -920,14 +975,17 @@ impl RawLegacyDeclaration {
920975
]))
921976
}
922977

978+
/// Gets a reference to the legacy (Cairo 0) class being declared.
923979
pub fn contract_class(&self) -> &LegacyContractClass {
924980
&self.contract_class
925981
}
926982

983+
/// Gets the `nonce` of the declaration request.
927984
pub const fn nonce(&self) -> Felt {
928985
self.nonce
929986
}
930987

988+
/// Gets the `max_fee` of the declaration request.
931989
pub const fn max_fee(&self) -> Felt {
932990
self.max_fee
933991
}
@@ -949,6 +1007,7 @@ impl<'a, A> PreparedDeclarationV2<'a, A>
9491007
where
9501008
A: ConnectedAccount,
9511009
{
1010+
/// Signs and broadcasts the transaction to the network.
9521011
pub async fn send(&self) -> Result<DeclareTransactionResult, AccountError<A::SignError>> {
9531012
let tx_request = self.get_declare_request(false, false).await?;
9541013
self.account
@@ -998,6 +1057,7 @@ impl<'a, A> PreparedDeclarationV3<'a, A>
9981057
where
9991058
A: ConnectedAccount,
10001059
{
1060+
/// Signs and broadcasts the transaction to the network.
10011061
pub async fn send(&self) -> Result<DeclareTransactionResult, AccountError<A::SignError>> {
10021062
let tx_request = self.get_declare_request(false, false).await?;
10031063
self.account
@@ -1066,6 +1126,7 @@ impl<'a, A> PreparedLegacyDeclaration<'a, A>
10661126
where
10671127
A: ConnectedAccount,
10681128
{
1129+
/// Signs and broadcasts the transaction to the network.
10691130
pub async fn send(&self) -> Result<DeclareTransactionResult, AccountError<A::SignError>> {
10701131
let tx_request = self.get_declare_request(false, false).await?;
10711132
self.account

0 commit comments

Comments
 (0)