# Cross Contract Calls

**URL:** https://forum.aurora.dev/t/cross-contract-calls/304
**Category:** AIPs (Aurora Improvement Proposals)
**Created:** [May 28, 2022, 12:02pm UTC](https://forum.aurora.dev/t/cross-contract-calls/304 "2022-05-28T12:02:36Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![birchmd](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.aurora.dev/birchmd/32/96_2.png) [@birchmd](https://forum.aurora.dev/u/birchmd)
#### Post date: [May 30, 2022, 8:53pm UTC](https://forum.aurora.dev/t/cross-contract-calls/304/2 "2022-05-30T20:53:47Z")

</div>

Thanks for writing this up @marcelo.near !

I have a suggestion for the `Promise` data structure and corresponding interfaces of the precompile and async contract.

I think `Promise` should be defined as a recursive data structure

```nohighlight
pub enum Promise {
    Then {base: Box<Promise>, callback: Box<Promise>},
    And(Box<Promise>, Box<Promise>),
    Call {target: AccountId, ...}
}

```

This makes writing invalid promises impossible. When the combinators are done via the index indirection it would be possible to write a promise that depends on an index that does not exist, or even was created as part of a different batch (which could maybe lead to some frontrunning problems?).

With this change the interfaces also become simpler because only a single identifier needs to be returned by the `schedule` call, and similarly only a single identifier needs to be passed to the `execute` call.

```nohighlight
trait AuroraRouter {
    pub fn schedule(&mut self, promise: Promise) -> PromiseId;
    pub fn pull(&mut self, promise: PromiseId, total_gas: Gas, total_balance: Balance) -> Option<Promise>;
}

trait AsyncAurora {
    pub fn pull_and_execute(&mut self, aurora: AccountId, promise: PromiseId, total_gas: Gas, total_balance: Balance);
    pub fn submit_and_execute(&mut self, aurora: AccountId, submit_payload: Vec<u8>, total_gas: Gas, total_balance: Balance);
}

```

Note that it is still possible to put multiple calls in a single promise because `And` and `Then` combinators are baked in to the `Promise` type. For example instead of passing `vec![0, 1]` to `execute` I would call `schedule` with `Promise::And(..., ...)`, getting back a single identifier to pass to `execute` that still does both promises.

---

_[View the full topic](https://forum.aurora.dev/t/cross-contract-calls/304)._
