diff --git a/src/rpc/documentation/public_endpoints/gettransaction.md b/src/rpc/documentation/public_endpoints/gettransaction.md index e4d2f0b740..458209959d 100644 --- a/src/rpc/documentation/public_endpoints/gettransaction.md +++ b/src/rpc/documentation/public_endpoints/gettransaction.md @@ -9,10 +9,11 @@ Returns a transaction with metadata given the transaction ID. ### Response -| Parameter | Type | Description | -|:-------------:|:------:|:-----------------------------------------:| -| `metadata` | object | The metadata of the requested transaction | -| `transaction` | object | The transaction object | +| Parameter | Type | Description | +|:-------------------:|:------:|:------------------------------------------------------------------:| +| `decrypted_records` | array | The decrypted records using record view key events, if they exist. | +| `metadata` | object | The metadata of the requested transaction | +| `transaction` | object | The transaction object | #### Transaction Metadata @@ -32,6 +33,18 @@ Returns a transaction with metadata given the transaction ID. | `transaction_id` | string | The ID of this transaction. | | `transitions` | array | The state transitions. | +#### Record + +| Parameter | Type | Description | +|:-----------------:|:------:|:---------------------------------------:| +| `commitment` | string | The commitment of this record. | +| `owner` | string | The record owner. | +| `payload` | string | The record payload. | +| `program_id` | string | The program id of this record. | +| `randomizer` | string | The randomizer used for the ciphertext. | +| `record_view_key` | string | The view key of this record. | +| `value` | number | The record value. | + ### Example Request ```ignore curl --data-binary '{"jsonrpc": "2.0", "id":"1", "method": "gettransaction", "params": ["at1mka6m3kfsgt5dpnfurk2ydjefqjzng4aawj7lkpc32pjkg86hyysrke9nf"] }' -H 'content-type: application/json' http://127.0.0.1:3030/ @@ -83,7 +96,18 @@ curl --data-binary '{"jsonrpc": "2.0", "id":"1", "method": "gettransaction", "pa "value_balance": -1000000000000000 } ] - } + }, + "decrypted_records": [ + { + "commitment":"cm1xck4eyf3a3qnz69yyrr3jf698mqzwpjgkqu0j359p0sdr5wyjyqsn0604p", + "owner":"aleo1h35g4ld7wqahxw3puelmntaeddzr2rukmhty5a8cw5vqe65s2cpsrd4ghl", + "payload":"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "program_id":"ap1lhj3g5uzervu3km7rl0rsd0u5j6pj9ujum6yxrvms4mx8r2qhew88ga849hnjypghswxceh02frszs45qmd", + "randomizer":"rr1v76mftwzagt9k9nsjjpdqgytv4ddk24e9q7f240daar7avcv3q9qku3vtg", + "record_view_key":"rcvk1mujt98tc2r04l58haxjv48s5a7vnhx8ws24fxpdruuk3z37vscqsjtvlg5", + "value":1000000000000000 + } + ] }, "id": "1" } diff --git a/src/rpc/rpc.rs b/src/rpc/rpc.rs index 69815f571c..1e90555c17 100644 --- a/src/rpc/rpc.rs +++ b/src/rpc/rpc.rs @@ -444,6 +444,7 @@ mod tests { use hyper::Request; use rand::{thread_rng, SeedableRng}; use rand_chacha::ChaChaRng; + use snarkvm::dpc::Record; use std::{ path::{Path, PathBuf}, sync::atomic::AtomicBool, @@ -1166,6 +1167,7 @@ mod tests { pub struct GetTransactionResponse { pub transaction: Transaction, pub metadata: snarkos_storage::Metadata, + pub decrypted_records: Vec>, } // Initialize a new ledger. @@ -1199,11 +1201,16 @@ mod tests { let actual: GetTransactionResponse = process_response(response).await; // Check the transaction. - assert_eq!(*Testnet2::genesis_block().transactions().first().unwrap(), actual.transaction); + let expected_transaction = Testnet2::genesis_block().transactions().first().unwrap(); + assert_eq!(*expected_transaction, actual.transaction); // Check the metadata. let expected_transaction_metadata = ledger.get_transaction_metadata(&transaction_id).unwrap(); assert_eq!(expected_transaction_metadata, actual.metadata); + + // Check the records. + let expected_decrypted_records: Vec> = expected_transaction.to_records().collect(); + assert_eq!(expected_decrypted_records, actual.decrypted_records) } #[tokio::test] diff --git a/src/rpc/rpc_impl.rs b/src/rpc/rpc_impl.rs index 174feae257..9816190943 100644 --- a/src/rpc/rpc_impl.rs +++ b/src/rpc/rpc_impl.rs @@ -34,7 +34,7 @@ use snarkvm::{ }; use jsonrpc_core::Value; -use snarkvm::utilities::ToBytes; +use snarkvm::{dpc::Record, utilities::ToBytes}; use std::{cmp::max, net::SocketAddr, ops::Deref, sync::Arc}; use tokio::sync::RwLock; @@ -264,12 +264,13 @@ impl RpcFunctions for RpcImpl { Ok(self.memory_pool.read().await.transactions()) } - /// Returns a transaction with metadata given the transaction ID. + /// Returns a transaction with metadata and decrypted records given the transaction ID. async fn get_transaction(&self, transaction_id: serde_json::Value) -> Result { let transaction_id: N::TransactionID = serde_json::from_value(transaction_id)?; let transaction: Transaction = self.ledger.get_transaction(&transaction_id)?; let metadata: Metadata = self.ledger.get_transaction_metadata(&transaction_id)?; - Ok(serde_json::json!({ "transaction": transaction, "metadata": metadata })) + let decrypted_records: Vec> = transaction.to_records().collect(); + Ok(serde_json::json!({ "transaction": transaction, "metadata": metadata, "decrypted_records": decrypted_records })) } /// Returns a transition given the transition ID.