-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5070 from onflow/janez/setup-evm-account-on-boots…
…trap Setup EVM account Flow vault during bootstrap
- Loading branch information
Showing
4 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import FlowServiceAccount from 0xFLOWSERVICEADDRESS | ||
import FlowStorageFees from 0xFLOWSTORAGEFEESADDRESS | ||
import FungibleToken from 0xFUNGIBLETOKENADDRESS | ||
import FlowToken from 0xFLOWTOKENADDRESS | ||
|
||
// This transaction sets up storage on a auth account. | ||
// This is used during bootstrapping a local environment | ||
transaction() { | ||
prepare(account: AuthAccount, service: AuthAccount) { | ||
|
||
// take all the funds from the service account | ||
let tokenVault = service.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault) | ||
?? panic("Unable to borrow reference to the default token vault") | ||
|
||
let storageReservation <- tokenVault.withdraw(amount: FlowStorageFees.minimumStorageReservation) as! @FlowToken.Vault | ||
let hasReceiver = account.getCapability(/public/flowTokenReceiver)!.check<&{FungibleToken.Receiver}>() | ||
if !hasReceiver { | ||
FlowServiceAccount.initDefaultToken(account) | ||
} | ||
let receiver = account.getCapability(/public/flowTokenReceiver)!.borrow<&{FungibleToken.Receiver}>() | ||
?? panic("Could not borrow receiver reference to the recipient's Vault") | ||
|
||
receiver.deposit(from: <-storageReservation) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters