Skip to content

Commit

Permalink
Merge pull request #61 from CosmWasm/aw/transactions
Browse files Browse the repository at this point in the history
Add page about transactions
  • Loading branch information
aumetra authored Jun 21, 2024
2 parents 49392ef + ce1ccd3 commit e6e9e44
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/pages/core/architecture/_meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"actor-model": "Actor Model",
"events": "Events"
"events": "Events",
"transactions": "Transactions"
}
27 changes: 27 additions & 0 deletions src/pages/core/architecture/transactions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
tags: ["core", "architecture"]
---

# Transactions

Every contract invocation is wrapped into a transaction. If you know about
transactions in SQL databases, you can consider them as the same basic concept.
You execute multiple operations in a single transaction, and if one of them
fails, the whole transaction is rolled back.

In our case, these operations are invocations of contract entrypoints. If one of
the invocations in the chain fails, the whole transaction is usually rolled
back.

## Preventing rollbacks in case of failure

If you don't want your entire transaction to be rolled back in case of a
failure, you can use the `reply_on` field in the message you send. Set the field
to one of the following values and instead of rolling back the transaction, you
will receive a message containing the error:

- `ReplyOn::Always`
- `ReplyOn::Error`

That way you can handle the error and decide what to do next, whether you want
to propagate the error, retry the operation, ignore it, etc.
7 changes: 7 additions & 0 deletions src/pages/core/entrypoints/reply.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ and set it to one of the following values:
- `ReplyOn::Error`
- `ReplyOn::Success`

<Callout>
The `reply_on` value has an impact on when a transaction is cancelled. For
more info, check the page about [transactions].
</Callout>

```rust filename="contract.rs" template="core"
const CONTRACT_ADDR: &str = "other_contract";
const SUBMSG_ID: u64 = 1; // This is a unique identifier so we can associate a reply with a specific submessage. It can be any numeric value.
Expand Down Expand Up @@ -65,3 +70,5 @@ pub fn reply(deps: DepsMut, env: Env, msg: cosmwasm_std::Reply) -> StdResult<Res
Ok(Response::default())
}
```

[transactions]: ../architecture/transactions

0 comments on commit e6e9e44

Please sign in to comment.