Skip to content

Commit

Permalink
remove redundant methods & add blocklist init to FlowEVMBridgeConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Sep 19, 2024
1 parent 4bca82a commit 7ecca5c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
33 changes: 12 additions & 21 deletions cadence/contracts/bridge/FlowEVMBridgeConfig.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@ contract FlowEVMBridgeConfig {
?? panic("Missing or mis-typed Blocklist in storage")
}

/// Temporary method to initialize the EVMBlocklist resource as this resource was added after the contract was
/// deployed
///
access(all)
fun initBlocklist() {
let path = /storage/evmBlocklist
if self.account.storage.type(at: path) != nil{
return
}
self.account.storage.save(<-create EVMBlocklist(), to: path)
}

/*****************
Constructs
*****************/
Expand Down Expand Up @@ -414,27 +426,6 @@ contract FlowEVMBridgeConfig {
emit AssetPauseStatusUpdated(paused: false, type: type.identifier, evmAddress: evmAddress)
}

/// Blocks the given EVM address from onboarding to the bridge
///
access(Blocklist)
fun blockEVMAddress(_ evmAddress: EVM.EVMAddress) {
FlowEVMBridgeConfig.borrowBlocklist().block(evmAddress)
}

/// Unblocks the given EVM address from onboarding to the bridge
///
access(Blocklist)
fun unblockEVMAddress(_ evmAddress: EVM.EVMAddress) {
FlowEVMBridgeConfig.borrowBlocklist().unblock(evmAddress)
}

/// Removes the given EVM address from the blocklist
///
access(Blocklist)
fun removeEVMAddressFromBlocklist(_ evmAddress: EVM.EVMAddress) {
FlowEVMBridgeConfig.borrowBlocklist().remove(evmAddress)
}

/// Sets the target EVM contract address on the handler for a given Type, associating the Cadence type with the
/// provided EVM address. If a TokenHandler does not exist for the given Type, the operation reverts.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import "FlowEVMBridgeConfig"
///
transaction(evmContractHex: String) {

let admin: auth(FlowEVMBridgeConfig.Blocklist) &FlowEVMBridgeConfig.Admin
let evmBlocklist: auth(FlowEVMBridgeConfig.Blocklist) &FlowEVMBridgeConfig.EVMBlocklist
let evmAddress: EVM.EVMAddress

prepare(signer: auth(BorrowValue) &Account) {
self.admin = signer.storage.borrow<auth(FlowEVMBridgeConfig.Blocklist) &FlowEVMBridgeConfig.Admin>(
FlowEVMBridgeConfig.initBlocklist()
self.evmBlocklist = signer.storage.borrow<auth(FlowEVMBridgeConfig.Blocklist) &FlowEVMBridgeConfig.EVMBlocklist>(
from: FlowEVMBridgeConfig.adminStoragePath
) ?? panic("Could not borrow FlowEVMBridgeConfig Admin reference")
self.evmAddress = EVM.addressFromString(evmContractHex)
}

execute {
self.admin.blockEVMAddress(self.evmAddress)
self.evmBlocklist.block(self.evmAddress)
}

post {
Expand Down
14 changes: 14 additions & 0 deletions cadence/transactions/bridge/admin/blocklist/init_blocklist.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import "EVM"

import "FlowEVMBridgeConfig"

/// Initializes the EVMBlocklist in the bridge account if it does not yet exist at the expected path
///
transaction {

prepare(signer: &Account) {}

execute {
FlowEVMBridgeConfig.initBlocklist()
}
}

0 comments on commit 7ecca5c

Please sign in to comment.