Skip to content

Add Docs for Ralph Danube Features #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 8, 2025
Merged

Conversation

h0ngcha0
Copy link
Member

@h0ngcha0 h0ngcha0 commented Apr 8, 2025

No description provided.

Copy link
Member

@Lbqds Lbqds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍


There are a few things worth emphasizing here:

- TxScript can only chain the asset outputs from the contract call, contract output cannot be chained
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TxScript can only chain the asset outputs of the callers. If the asset outputs are for non-callers, then they can't be chained either.

  def chainCallerOutputs(frameBalanceState: MutBalanceState): ExeResult[Unit] = {
    EitherF.foreachTry(allInputAddresses.toIterable) { caller =>


The Danube upgrade introduces the `@preserveCaller` function annotation. When a function is annotated with `@preserveCaller`, the caller information is preserved for the next function call in the chain.

More specifically, if a `@preserveCaller` annotated function calls another function, the `callerAddress!()` in the called function will return the caller address of the annotated function rather than the annotated function itself. This feature is particularly valuable for implementing routing patterns in smart contracts, where maintaining the identity of the original caller is essential for proper access control and authorization.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's note that the same mechanism works for externalCallerAddress!()

Here's an example of how `@preserveCaller` works:

```rust
Contract PreserveCaller(internal: PreserveCallerInternal) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about naming it Rounter since it's the most common use case?

pub fn ifStmts(x: U256, y: U256) -> U256 {
let num1 = if (x > y) 1 else 0
let num2 = if x > y 1 else 0
let num3 = if x > y { log(x) 1 } else { log(x) 0 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't recommended. Better do this. We will introduce fmt for such cases.

let num3 = if x > y {
  log(x)
  1
} else {
  log(x)
  0
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add this change: alephium/alephium#1255 (comment)

@polarker polarker merged commit eb8969c into master Apr 8, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants