3

I am trying to solve the following problem statement:- Contract A(func1) -> Contract A(func2) -> Contract B(funcB)

so, func1 will call func2 and then func2 will invoke multiple calls on different B contracts as per the payload. If any contract B call will revert, I need to revert all previous execution happened on contract B'. But at the same time some acknowledgement needs to be updated on Contract A.

So, Just like in solidity I am reverting from func2 and receiving that success flag in func1 and then performing the business logic. So, How can i implement same func1 to func2 implementation in ink smart contracts?

2 Answers 2

4

pallet-contract has a build in re-entrancy detection and re-entrancy is prevented by default. Indeed, you can allow for re-entrancy by setting the correct CallFlags, see:

https://paritytech.github.io/ink/ink_env/struct.CallFlags.html

I'd advise you to check how cross contract calls are build in the upgradable contracts example:

https://github.com/paritytech/ink/blob/master/examples/upgradeable-contracts/forward-calls/lib.rs#L72

Just that you need to set .allow_reentry(true) flag in addition when building the cross-contract call.

2

You can use call_builder to allow reentrancy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.