Skip to content

Commit

Permalink
rest: fix TransactionResponse serialization format
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Jul 23, 2024
1 parent 36fa74f commit bc456c8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 15 deletions.
30 changes: 23 additions & 7 deletions crates/sui-rest-api/openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@
},
"application/bcs": {}
}
},
"404": {
"description": ""
}
}
}
Expand Down Expand Up @@ -4066,28 +4069,41 @@
"TransactionResponse": {
"type": "object",
"required": [
"digest",
"effects",
"signatures",
"transaction"
],
"properties": {
"checkpoint": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
"description": "Radix-10 encoded 64-bit unsigned integer",
"default": null,
"type": "string",
"format": "u64"
},
"digest": {
"$ref": "#/components/schemas/TransactionDigest"
},
"effects": {
"$ref": "#/components/schemas/TransactionEffects"
},
"events": {
"$ref": "#/components/schemas/TransactionEvents"
},
"signatures": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UserSignature"
}
},
"timestamp_ms": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
"description": "Radix-10 encoded 64-bit unsigned integer",
"default": null,
"type": "string",
"format": "u64"
},
"transaction": {
"$ref": "#/components/schemas/SignedTransaction"
"$ref": "#/components/schemas/Transaction"
}
}
},
Expand Down
13 changes: 11 additions & 2 deletions crates/sui-rest-api/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::sync::Arc;

use sui_sdk2::types::{CheckpointSequenceNumber, EpochId, ValidatorCommittee};
use sui_sdk2::types::{CheckpointSequenceNumber, EpochId, SignedTransaction, ValidatorCommittee};
use sui_sdk2::types::{Object, ObjectId, Version};
use sui_types::storage::error::{Error as StorageError, Result};
use sui_types::storage::ObjectStore;
Expand Down Expand Up @@ -97,7 +97,14 @@ impl StateReader {
&self,
digest: sui_sdk2::types::TransactionDigest,
) -> crate::Result<super::transactions::TransactionResponse> {
let (transaction, effects, events) = self.get_transaction(digest)?;
let (
SignedTransaction {
transaction,
signatures,
},
effects,
events,
) = self.get_transaction(digest)?;

let checkpoint = self.inner().get_transaction_checkpoint(&(digest.into()))?;
let timestamp_ms = if let Some(checkpoint) = checkpoint {
Expand All @@ -109,7 +116,9 @@ impl StateReader {
};

Ok(crate::transactions::TransactionResponse {
digest: transaction.digest(),
transaction,
signatures,
effects,
events,
checkpoint,
Expand Down
24 changes: 18 additions & 6 deletions crates/sui-rest-api/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ pub use execution::TransactionExecutor;
use axum::extract::{Path, Query, State};
use axum::http::StatusCode;
use sui_sdk2::types::CheckpointSequenceNumber;
use sui_sdk2::types::{
SignedTransaction, TransactionDigest, TransactionEffects, TransactionEvents,
};
use sui_sdk2::types::Transaction;
use sui_sdk2::types::{TransactionDigest, TransactionEffects, TransactionEvents, UserSignature};
use tap::Pipe;

use crate::openapi::ApiEndpoint;
Expand Down Expand Up @@ -52,6 +51,7 @@ impl ApiEndpoint<RestService> for GetTransaction {
.bcs_content()
.build(),
)
.response(404, ResponseBuilder::new().build())
.build()
}

Expand All @@ -74,13 +74,23 @@ async fn get_transaction(
.pipe(Ok)
}

#[serde_with::serde_as]
#[derive(Debug, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
pub struct TransactionResponse {
pub transaction: SignedTransaction,
pub digest: TransactionDigest,
pub transaction: Transaction,
pub signatures: Vec<UserSignature>,
pub effects: TransactionEffects,
pub events: Option<TransactionEvents>,
//TODO fix format of u64s
#[serde_as(
as = "Option<sui_types::sui_serde::Readable<sui_types::sui_serde::BigInt<u64>, _>>"
)]
#[schemars(with = "Option<crate::_schemars::U64>")]
pub checkpoint: Option<u64>,
#[serde_as(
as = "Option<sui_types::sui_serde::Readable<sui_types::sui_serde::BigInt<u64>, _>>"
)]
#[schemars(with = "Option<crate::_schemars::U64>")]
pub timestamp_ms: Option<u64>,
}

Expand Down Expand Up @@ -165,7 +175,9 @@ async fn list_transactions(
state
.get_transaction(digest.into())
.map(|(transaction, effects, events)| TransactionResponse {
transaction,
digest: transaction.transaction.digest(),
transaction: transaction.transaction,
signatures: transaction.signatures,
effects,
events,
checkpoint: Some(cursor_info.checkpoint),
Expand Down

0 comments on commit bc456c8

Please sign in to comment.