Contract Predecessor vs Signer vs Current
Asked Answered
B

2

5

Can someone help me understand the relationship and distinction amongst these three concepts? It seems like context.predecessor == context.contractName checks are common.

Banjo answered 28/4, 2021 at 9:2 Comment(0)
R
6

signer - account that signed the initial transaction.

predecessor - the last account who made the current contract call.

current - the account of the contract.

For an example, consider contract contract.near and a user alice.near.

alice.near calls method foo on contract.near. In the context of foo:

  • signer == alice.near
  • predecessor == alice.near
  • current == contract.near

Then if a promise call is made to another method say faa, then its context is:

  • signer == alice.near
  • predecessor == contract.near
  • current == contract.near

So the check predecessor == current or context.predecessor == context.contractName is to make sure that the contract was the account that made the contract call. A method with this assertion is considered "private" because only the contract can call it even though it is part of a public facing API.

Roundish answered 28/4, 2021 at 12:24 Comment(0)
S
0

The answer from sirwillem above explains it well

Just remember the idea behind assertions like context.predecessor == context.contractName can be:

  • Calling private methods in a contract indirectly (which can only be called by the contract itself)
  • Calling admin level methods that only the contract id (contract owner) should call
Steffens answered 2/6, 2022 at 9:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.