MCPcopy Create free account
hub / github.com/dfinity/orbit / execute

Method execute

core/station/impl/src/factories/requests/transfer.rs:107–157  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

105#[async_trait]
106impl Execute for TransferRequestExecute<'_, '_> {
107 async fn execute(&self) -> Result<RequestExecuteStage, RequestExecuteError> {
108 let asset = ASSET_REPOSITORY
109 .get(&self.operation.input.from_asset_id)
110 .ok_or(RequestExecuteError::Failed {
111 reason: format!(
112 "Asset {} does not exist.",
113 Uuid::from_bytes(self.operation.input.from_asset_id).hyphenated()
114 ),
115 })?;
116
117 let blockchain_api = BlockchainApiFactory::build(&asset.blockchain).map_err(|e| {
118 RequestExecuteError::Failed {
119 reason: format!("Failed to build blockchain api: {e}"),
120 }
121 })?;
122 let fee = match &self.operation.input.fee {
123 Some(fee) => fee.clone(),
124 None => {
125 let transaction_fee = blockchain_api
126 .transaction_fee(&asset, self.operation.input.with_standard.clone())
127 .await
128 .map_err(|e| RequestExecuteError::Failed {
129 reason: format!("Failed to fetch transaction fee: {e}"),
130 })?;
131
132 candid::Nat(transaction_fee.fee)
133 }
134 };
135
136 self.transfer_service
137 .add_transfer(Transfer::new(
138 self.request.id,
139 *generate_uuid_v4().await.as_bytes(),
140 self.request.requested_by,
141 self.operation.input.from_account_id,
142 self.operation.input.from_asset_id,
143 self.operation.input.with_standard.clone(),
144 self.operation.input.to.clone(),
145 self.operation.input.metadata.clone(),
146 self.operation.input.amount.clone(),
147 fee,
148 self.operation.input.network.clone(),
149 ))
150 .map_err(|e| RequestExecuteError::Failed {
151 reason: format!("Failed to validate transfer: {e}"),
152 })?;
153
154 Ok(RequestExecuteStage::Processing(
155 self.request.operation.clone(),
156 ))
157 }
158}

Callers

nothing calls this directly

Calls 4

transaction_feeMethod · 0.80
add_transferMethod · 0.80
generate_uuid_v4Function · 0.50
getMethod · 0.45

Tested by

no test coverage detected