|
1 | 1 | use crate::platform::transition::broadcast_identity::BroadcastRequestForNewIdentity; |
2 | 2 | use crate::platform::transition::{ |
3 | | - address_inputs::collect_address_infos_from_proof, broadcast::BroadcastStateTransition, |
| 3 | + address_inputs::{collect_address_infos_from_proof, fetch_inputs_with_nonce, nonce_inc}, |
| 4 | + broadcast::BroadcastStateTransition, |
4 | 5 | }; |
5 | 6 | use crate::{Error, Sdk}; |
6 | 7 |
|
@@ -46,13 +47,30 @@ pub trait PutIdentity<IS: Signer<IdentityPublicKey>>: Waitable { |
46 | 47 | where |
47 | 48 | Self: Sized; |
48 | 49 |
|
| 50 | + /// Creates an identity funded by Platform addresses (nonces looked up automatically). |
| 51 | + /// |
| 52 | + /// Use [Identity::new_with_input_addresses_and_keys](dpp::identity::Identity::new_with_input_addresses_and_keys) |
| 53 | + /// to create an identity. Then use this method to put it to the platform. |
| 54 | + /// |
| 55 | + /// This method automatically fetches the current nonces for each input address |
| 56 | + /// and increments them before submitting the transaction. |
| 57 | + async fn put_from_addresses<AS: Signer<PlatformAddress> + Send + Sync>( |
| 58 | + &self, |
| 59 | + sdk: &Sdk, |
| 60 | + inputs: BTreeMap<PlatformAddress, Credits>, |
| 61 | + output: Option<(PlatformAddress, Credits)>, |
| 62 | + identity_signer: &IS, |
| 63 | + input_address_signer: &AS, |
| 64 | + settings: Option<PutSettings>, |
| 65 | + ) -> Result<(Identity, AddressInfos), Error>; |
| 66 | + |
49 | 67 | /// Creates an identity funded by Platform addresses using explicit nonces. |
50 | 68 | /// |
51 | 69 | /// Use [Identity::new_with_input_addresses_and_keys](dpp::identity::Identity::new_with_input_addresses_and_keys) |
52 | 70 | /// to create an identity. Then use this method to put it to the platform. |
53 | 71 | /// |
54 | | - /// This is a preferred method, as you need to use the same nonces when creating the identity. |
55 | | - async fn put_with_address_funding<AS: Signer<PlatformAddress> + Send + Sync>( |
| 72 | + /// Inputs are not pre-validated client-side (Drive enforces authoritative checks). |
| 73 | + async fn put_from_addresses_with_nonce<AS: Signer<PlatformAddress> + Send + Sync>( |
56 | 74 | &self, |
57 | 75 | sdk: &Sdk, |
58 | 76 | inputs_with_nonce: BTreeMap<PlatformAddress, (AddressNonce, Credits)>, |
@@ -105,7 +123,28 @@ impl<IS: Signer<IdentityPublicKey>> PutIdentity<IS> for Identity { |
105 | 123 | Self::wait_for_response(sdk, state_transition, settings).await |
106 | 124 | } |
107 | 125 |
|
108 | | - async fn put_with_address_funding<AS: Signer<PlatformAddress> + Send + Sync>( |
| 126 | + async fn put_from_addresses<AS: Signer<PlatformAddress> + Send + Sync>( |
| 127 | + &self, |
| 128 | + sdk: &Sdk, |
| 129 | + inputs: BTreeMap<PlatformAddress, Credits>, |
| 130 | + output: Option<(PlatformAddress, Credits)>, |
| 131 | + identity_signer: &IS, |
| 132 | + input_address_signer: &AS, |
| 133 | + settings: Option<PutSettings>, |
| 134 | + ) -> Result<(Identity, AddressInfos), Error> { |
| 135 | + let inputs_with_nonce = nonce_inc(fetch_inputs_with_nonce(sdk, &inputs).await?); |
| 136 | + self.put_from_addresses_with_nonce( |
| 137 | + sdk, |
| 138 | + inputs_with_nonce, |
| 139 | + output, |
| 140 | + identity_signer, |
| 141 | + input_address_signer, |
| 142 | + settings, |
| 143 | + ) |
| 144 | + .await |
| 145 | + } |
| 146 | + |
| 147 | + async fn put_from_addresses_with_nonce<AS: Signer<PlatformAddress> + Send + Sync>( |
109 | 148 | &self, |
110 | 149 | sdk: &Sdk, |
111 | 150 | inputs: BTreeMap<PlatformAddress, (AddressNonce, Credits)>, |
|
0 commit comments