Transaction - Post Condition

I was wondering, why transaction scope is not available in post condition? :thinking:
This way it would be possible to do something like this:

import FungibleToken from 0x01

transaction {

  let account: AuthAccount

  prepare(acct: AuthAccount) {
    self.account = acct
    self.account.link<&FungibleToken.Vault{FungibleToken.Receiver, FungibleToken.Balance}>(/public/MainReceiver, target: /storage/MainVault)
    log("Public Receiver reference created!")
  }

  post {
    self.account.getCapability(/public/MainReceiver)!
                    .check<&FungibleToken.Vault{FungibleToken.Receiver}>():
                    "Vault Receiver Reference was not created correctly"
    }
}

Because in the second transaction, if I send it from 0x02 it will make incorrect check, since it’s checking if capability on 0x01 exists :man_shrugging:

post {
        getAccount(0x01).getCapability(/public/MainReceiver)!
                        .check<&FungibleToken.Vault{FungibleToken.Receiver}>():  
                        "Vault Receiver Reference was not created correctly"
    }

Do you mean that the problem is that the account field is not accessible in the post-condition?

Accessing transaction fields in post-conditions should work as expected, e.g:

transaction {

  let num: Int

  prepare(acct: AuthAccount) {
    self.num = 1
  }

  post {
    self.num == 1
  }
}

Or is the problem that the transaction checks properly, but doesn’t work as expected when you run it?

1 Like

Oh, indeed! It works :slight_smile:
There were probably something wrong with the code in prepare block :thinking: