diff --git a/client/src/rpc_response.rs b/client/src/rpc_response.rs index 885cec85b5..4eab16e569 100644 --- a/client/src/rpc_response.rs +++ b/client/src/rpc_response.rs @@ -348,7 +348,29 @@ pub struct RpcSimulateTransactionResult { pub logs: Option>, pub accounts: Option>>, pub units_consumed: Option, - pub return_data: Option, + pub return_data: Option, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(rename_all = "camelCase")] +pub struct RpcTransactionReturnData { + pub program_id: String, + pub data: (String, ReturnDataEncoding), +} + +impl From for RpcTransactionReturnData { + fn from(return_data: TransactionReturnData) -> Self { + Self { + program_id: return_data.program_id.to_string(), + data: (base64::encode(return_data.data), ReturnDataEncoding::Base64), + } + } +} + +#[derive(Serialize, Deserialize, Clone, Copy, Debug, Eq, Hash, PartialEq)] +#[serde(rename_all = "camelCase")] +pub enum ReturnDataEncoding { + Base64, } #[derive(Serialize, Deserialize, Clone, Debug)] diff --git a/docs/src/developing/clients/jsonrpc-api.md b/docs/src/developing/clients/jsonrpc-api.md index bf2c1326a7..7a4de26bd8 100644 --- a/docs/src/developing/clients/jsonrpc-api.md +++ b/docs/src/developing/clients/jsonrpc-api.md @@ -3384,7 +3384,7 @@ The result will be an RpcResponse JSON object with `value` set to a JSON object - `err: ` - Error if transaction failed, null if transaction succeeded. [TransactionError definitions](https://github.com/solana-labs/solana/blob/c0c60386544ec9a9ec7119229f37386d9f070523/sdk/src/transaction/error.rs#L13) - `logs: ` - Array of log messages the transaction instructions output during execution, null if simulation failed before the transaction was able to execute (for example due to an invalid blockhash or signature verification failure) -- `accounts: | null>` - array of accounts with the same length as the `accounts.addresses` array in the request +- `accounts: ` - array of accounts with the same length as the `accounts.addresses` array in the request - `` - if the account doesn't exist or if `err` is not null - `` - otherwise, a JSON object containing: - `lamports: `, number of lamports assigned to this account, as a u64 @@ -3393,6 +3393,9 @@ The result will be an RpcResponse JSON object with `value` set to a JSON object - `executable: `, boolean indicating if the account contains a program \(and is strictly read-only\) - `rentEpoch: `, the epoch at which this account will next owe rent, as u64 - `unitsConsumed: `, The number of compute budget units consumed during the processing of this transaction +- `returnData: ` - the most-recent return data generated by an instruction in the transaction, with the following fields: + - `programId: `, the program that generated the return data, as base-58 encoded Pubkey + - `data: <[string, encoding]>`, the return data itself, as base-64 encoded binary data #### Example: @@ -3403,7 +3406,10 @@ curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d ' "id": 1, "method": "simulateTransaction", "params": [ - "4hXTCkRzt9WyecNzV1XPgCDfGAZzQKNxLXgynz5QDuWWPSAZBZSHptvWRL3BjCvzUXRdKvHL2b7yGrRQcWyaqsaBCncVG7BFggS8w9snUts67BSh3EqKpXLUm5UMHfD7ZBe9GhARjbNQMLJ1QD3Spr6oMTBU6EhdB4RD8CP2xUxr2u3d6fos36PD98XS6oX8TQjLpsMwncs5DAMiD4nNnR8NBfyghGCWvCVifVwvA8B8TJxE1aiyiv2L429BCWfyzAme5sZW8rDb14NeCQHhZbtNqfXhcp2tAnaAT" + "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDArczbMia1tLmq7zz4DinMNN0pJ1JtLdqIJPUw3YrGCzYAMHBsgN27lcgB6H2WQvFgyZuJYHa46puOQo9yQ8CVQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCp20C7Wj2aiuk5TReAXo+VTVg8QTHjs0UjNMMKCvpzZ+ABAgEBARU=", + { + "encoding":"base64", + } ] } ' @@ -3422,8 +3428,19 @@ Result: "err": null, "accounts": null, "logs": [ - "BPF program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri success" - ] + "Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri invoke [1]", + "Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri consumed 2366 of 1400000 compute units", + "Program return: 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri KgAAAAAAAAA=", + "Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri success" + ], + "returnData": { + "data": [ + "Kg==", + "base64" + ], + "programId": "83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri" + }, + "unitsConsumed": 2366 } }, "id": 1 diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 5239eaa5a6..423d600be1 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -3569,7 +3569,7 @@ pub mod rpc_full { logs: Some(logs), accounts: None, units_consumed: Some(units_consumed), - return_data, + return_data: return_data.map(|return_data| return_data.into()), }, } .into()); @@ -3679,7 +3679,7 @@ pub mod rpc_full { logs: Some(logs), accounts, units_consumed: Some(units_consumed), - return_data, + return_data: return_data.map(|return_data| return_data.into()), }, )) }