MCPcopy Create free account
hub / github.com/etherspot/transaction-kit / update

Method update

lib/TransactionKit.ts:1183–1226  ·  view source on GitHub ↗

* Updates the currently selected named transaction with the latest working transaction data. * * This method overwrites the data of the selected named transaction with the current working transaction. If the transaction is part of a batch, the batch entry is also updated. Throws an error if th

()

Source from the content-addressed store, hash-verified

1181 * - If the transaction is part of a batch, the batch entry is also updated.
1182 */
1183 update(): INamedTransaction | IBatchedTransaction {
1184 if (!this.selectedTransactionName || !this.workingTransaction) {
1185 this.throwError(
1186 'update(): No named transaction to update. Call name() first.'
1187 );
1188 }
1189 if (!this.workingTransaction) {
1190 this.throwError('update(): No working transaction to update.');
1191 }
1192 const transactionName = this.selectedTransactionName;
1193 if (!transactionName) {
1194 this.throwError('update(): No selected transaction name.');
1195 }
1196 const transaction = this.namedTransactions[transactionName];
1197 if (!transaction) {
1198 this.throwError(`update(): Transaction '${transactionName}' not found.`);
1199 }
1200
1201 // Update namedTransactions
1202 this.namedTransactions[transactionName] = { ...this.workingTransaction };
1203
1204 // Update in batch if it exists
1205 if (transaction.batchName && this.batches[transaction.batchName]) {
1206 const batchIndex = this.batches[transaction.batchName].findIndex(
1207 (tx) => tx.transactionName === transactionName
1208 );
1209 if (batchIndex >= 0) {
1210 this.batches[transaction.batchName][batchIndex] = {
1211 ...this.workingTransaction,
1212 };
1213 }
1214 }
1215
1216 log(
1217 `update(): Updated transaction: ${transactionName}`,
1218 undefined,
1219 this.debugMode
1220 );
1221
1222 // Return appropriate state based on whether transaction is in batch
1223 return transaction.batchName
1224 ? (this as IBatchedTransaction)
1225 : (this as INamedTransaction);
1226 }
1227
1228 /**
1229 * Estimates the gas and cost for the currently selected transaction.

Callers

nothing calls this directly

Calls 2

throwErrorMethod · 0.95
logFunction · 0.90

Tested by

no test coverage detected