github.com/koko1123/flow-go-1@v0.29.6/fvm/blueprints/scripts/setupStorageForServiceAccountsTemplate.cdc (about)

     1  import FlowServiceAccount from 0xFLOWSERVICEADDRESS
     2  import FlowStorageFees from 0xFLOWSTORAGEFEESADDRESS
     3  import FungibleToken from 0xFUNGIBLETOKENADDRESS
     4  import FlowToken from 0xFLOWTOKENADDRESS
     5  
     6  // This transaction sets up storage on any auth accounts that were created before the storage fees.
     7  // This is used during bootstrapping a local environment
     8  transaction() {
     9      prepare(service: AuthAccount, fungibleToken: AuthAccount, flowToken: AuthAccount, feeContract: AuthAccount) {
    10          let authAccounts = [service, fungibleToken, flowToken, feeContract]
    11  
    12          // take all the funds from the service account
    13          let tokenVault = service.borrow<&FlowToken.Vault>(from: /storage/flowTokenVault)
    14              ?? panic("Unable to borrow reference to the default token vault")
    15  
    16          for account in authAccounts {
    17              let storageReservation <- tokenVault.withdraw(amount: FlowStorageFees.minimumStorageReservation) as! @FlowToken.Vault
    18              let hasReceiver = account.getCapability(/public/flowTokenReceiver)!.check<&{FungibleToken.Receiver}>()
    19              if !hasReceiver {
    20                  FlowServiceAccount.initDefaultToken(account)
    21              }
    22              let receiver = account.getCapability(/public/flowTokenReceiver)!.borrow<&{FungibleToken.Receiver}>()
    23                  ?? panic("Could not borrow receiver reference to the recipient's Vault")
    24  
    25              receiver.deposit(from: <-storageReservation)
    26          }
    27      }
    28  }