Skip to content

Commit

Permalink
feat(json-rpc): get transaction block raw effects (MystenLabs#19438)
Browse files Browse the repository at this point in the history
## Description

Add the ability to get transaction effects in BCS form, from JSON-RPC's
read path, by passing the `showRawEffects` option.

## Test plan

```
sui$ cargo build --bin sui --features indexer
sui$ $SUI start --force-regenesis --with-indexer --with-graphql --with-faucet
```

Then in another session:

```
sui$ $SUI client faucet
```

Find the transaction `$DIGEST` of the faucet transaction, and then fetch
it with:

```
curl -LX POST  "http://localhost:9000" \
        --header 'Content-Type: application/json' \
        --data-raw '{
        "jsonrpc": "2.0",
        "method": "sui_getTransactionBlock",
        "id": 1,
        "params": ["'$DIGEST'", { "showRawEffects": true }]
}' | jq .
```

And corroborate it against the following GraphQL query:

```
query ($digest: String!) {
  transactionBlock(digest: $digest) {
    effects { bcs }
  }
}
```

Which can be requested at `localhost:9125`.

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [x] Nodes (Validators and Full nodes): `sui_getTransactionBlock` and
`sui_multiGetTransactionBlock` JSON-RPC endpoints will now heed the
`showRawEffects` option, and return the BCS representation of the
transaction effects.
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
amnn authored Sep 18, 2024
1 parent 81e9fdb commit 3c1c5ef
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions crates/sui-json-rpc/src/read_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1325,28 +1325,36 @@ fn convert_to_response(
let mut response = SuiTransactionBlockResponse::new(cache.digest);
response.errors = cache.errors;

if opts.show_raw_input && cache.transaction.is_some() {
let sender_signed_data = cache.transaction.as_ref().unwrap().data();
let raw_tx = bcs::to_bytes(sender_signed_data)
.map_err(|e| anyhow!("Failed to serialize raw transaction with error: {}", e))?; // TODO: is this a client or server error?
response.raw_transaction = raw_tx;
}
if let Some(transaction) = cache.transaction {
if opts.show_raw_input {
response.raw_transaction = bcs::to_bytes(transaction.data()).map_err(|e| {
// TODO: is this a client or server error?
anyhow!("Failed to serialize raw transaction with error: {e}")
})?;
}

if opts.show_input && cache.transaction.is_some() {
let tx_block =
SuiTransactionBlock::try_from(cache.transaction.unwrap().into_data(), module_cache)?;
response.transaction = Some(tx_block);
if opts.show_input {
response.transaction = Some(SuiTransactionBlock::try_from(
transaction.into_data(),
module_cache,
)?);
}
}

if opts.show_effects && cache.effects.is_some() {
let effects = cache.effects.unwrap().try_into().map_err(|e| {
anyhow!(
if let Some(effects) = cache.effects {
if opts.show_raw_effects {
response.raw_effects = bcs::to_bytes(&effects).map_err(|e| {
// TODO: is this a client or server error?
"Failed to convert transaction block effects with error: {}",
e
)
})?;
response.effects = Some(effects);
anyhow!("Failed to serialize transaction block effects with error: {e}")
})?;
}

if opts.show_effects {
response.effects = Some(effects.try_into().map_err(|e| {
// TODO: is this a client or server error?
anyhow!("Failed to convert transaction block effects with error: {e}")
})?);
}
}

response.checkpoint = cache.checkpoint_seq;
Expand All @@ -1363,6 +1371,7 @@ fn convert_to_response(
if opts.show_object_changes {
response.object_changes = cache.object_changes;
}

Ok(response)
}

Expand Down

0 comments on commit 3c1c5ef

Please sign in to comment.