Skip to content

Commit 37deea3

Browse files
committed
address PR comments
1 parent 83c33e6 commit 37deea3

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

contracts/FlowTransactionSchedulerUtils.cdc

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -612,40 +612,59 @@ access(all) contract FlowTransactionSchedulerUtils {
612612
/// @param id: The ID of the scheduled transaction
613613
/// @param data: Optional data passed to the transaction execution. In this case, the data must be a COAHandlerParams struct with valid values.
614614
access(FlowTransactionScheduler.Execute) fun executeTransaction(id: UInt64, data: AnyStruct?) {
615+
616+
// Borrow the COA capability
615617
let coa = self.coaCapability.borrow()
616618
if coa == nil {
617619
emit COAHandlerExecutionError(id: id, owner: self.owner?.address ?? Address(0x0), coaAddress: nil,
618620
errorMessage: "COA capability is invalid or expired for scheduled transaction with ID \(id)")
619621
return
620622
}
621623

622-
if let transactions = data as? [COAHandlerParams] {
624+
// Parse the data into a list of COAHandlerParams
625+
// If the data is a single COAHandlerParams struct, wrap it in a list
626+
var params: [COAHandlerParams]? = data as? [COAHandlerParams]
627+
if params == nil {
628+
if let param = data as? COAHandlerParams {
629+
params = [param]
630+
}
631+
}
632+
633+
// Iterate through all the COA transactions and execute them all
634+
// If revertOnFailure is true for a transaction and any part of it fails, the entire scheduled transaction will be reverted
635+
// If not but a part of the transaction fails, an error event will be emitted but the scheduled transaction will continue to execute the next transaction
636+
//
637+
if let transactions = params {
623638
for index, txParams in transactions {
624639
switch txParams.txType {
625640
case COAHandlerTxType.DepositFLOW:
626-
if txParams.amount == nil {
627-
self.emitError(id: id, errorMessage: "Amount is required for deposit for scheduled transaction with ID \(id) and index \(index)")
628-
return
629-
}
630641
let vault = self.flowTokenVaultCapability.borrow()
631642
if vault == nil {
632-
self.emitError(id: id, errorMessage: "FlowToken vault capability is invalid or expired for scheduled transaction with ID \(id) and index \(index)")
633-
return
643+
if !txParams.revertOnFailure {
644+
self.emitError(id: id, errorMessage: "FlowToken vault capability is invalid or expired for scheduled transaction with ID \(id) and index \(index)")
645+
continue
646+
} else {
647+
panic("FlowToken vault capability is invalid or expired for scheduled transaction with ID \(id) and index \(index)")
648+
}
634649
}
650+
635651
if txParams.amount! > vault!.balance && !txParams.revertOnFailure {
636652
self.emitError(id: id, errorMessage: "Insufficient FLOW in FlowToken vault for deposit into COA for scheduled transaction with ID \(id) and index \(index)")
637653
continue
638654
}
655+
656+
// Deposit the FLOW into the COA vault. If there isn't enough FLOW in the vault,
657+
//the transaction will be reverted because we know revertOnFailure is true
639658
coa!.deposit(from: <-vault!.withdraw(amount: txParams.amount!) as! @FlowToken.Vault)
640659
case COAHandlerTxType.WithdrawFLOW:
641-
if txParams.amount == nil {
642-
self.emitError(id: id, errorMessage: "Amount is required for withdrawal from COA for scheduled transaction with ID \(id) and index \(index)")
643-
}
644-
645660
let vault = self.flowTokenVaultCapability.borrow()
646661
if vault == nil {
647-
self.emitError(id: id, errorMessage: "FlowToken vault capability is invalid or expired for scheduled transaction with ID \(id) and index \(index)")
648-
return
662+
if !txParams.revertOnFailure {
663+
self.emitError(id: id, errorMessage: "FlowToken vault capability is invalid or expired for scheduled transaction with ID \(id) and index \(index)")
664+
continue
665+
} else {
666+
panic("FlowToken vault capability is invalid or expired for scheduled transaction with ID \(id) and index \(index)")
667+
}
649668
}
650669

651670
let amount = EVM.Balance(attoflow: 0)
@@ -656,12 +675,10 @@ access(all) contract FlowTransactionSchedulerUtils {
656675
continue
657676
}
658677

678+
// Withdraw the FLOW from the COA vault. If there isn't enough FLOW in the COA,
679+
// the transaction will be reverted because we know revertOnFailure is true
659680
vault!.deposit(from: <-coa!.withdraw(balance: amount))
660681
case COAHandlerTxType.Call:
661-
if txParams.callToEVMAddress == nil || txParams.data == nil || txParams.gasLimit == nil || txParams.value == nil {
662-
self.emitError(id: id, errorMessage: "Call to EVM address, data, gas limit, and value are required for EVM call for scheduled transaction with ID \(id) and index \(index)")
663-
return
664-
}
665682
let result = coa!.call(to: txParams.callToEVMAddress!, data: txParams.data!, gasLimit: txParams.gasLimit!, value: txParams.value!)
666683

667684
if result.status != EVM.Status.successful {

0 commit comments

Comments
 (0)