paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.com/
1.89k stars 692 forks source link

Utility `if_else` call #6000

Open ggwpez opened 1 month ago

ggwpez commented 1 month ago

Some internal discussions brought up the idea of making calls easier to compose, starting simple with an if_else call.
The purpose of this call would be execute an error callback when the first call is not successful. Other names for this could be unless or otherwise. Signature can look like this:

fn if_else(
    predicate: RuntimeCall,
    else_call: RuntimeCall,
)

This would allow users to not just compose calls on their success case (via batch), but also in the error case.
The error is not accessible, and AFAIK that is also not easily implementable without using double-encoded partial calls.

Alternatively this can already be done via XCM, but nobody seems to know/do that, so having this alternative way without XCM can make the runtime easier to use.

rainbow-promise commented 1 month ago

Hi @ggwpez would be great to have link references if possible, would like to take this on!

Maybe assigning me also?

ggwpez commented 1 month ago

Hi @ggwpez would be great to have link references if possible, would like to take this on!

Yea please go ahead. What else do you need references for? I would suggest to check out how the utility::batch can be used and extrapolation from there.
The issue should contain all the info needed.

rainbow-promise commented 1 week ago

@ggwpez What might interrupt calls? https://github.com/paritytech/polkadot-sdk/blob/d1c115b6197bf6c45d5640594f0432e6c2781a4f/substrate/frame/utility/src/lib.rs#L215

ggwpez commented 1 week ago

Calls can return an error, in which case we want to call the else (aka fallback) call.