Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dev-inspect-txn to RPC and SDK #6998

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-ads-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mysten/sui.js": minor
---

Add devInspectTransaction, similar to dryRunTransaction, devInspectTransaction has mutableReferenceOutputs and returnValues as well.
9 changes: 8 additions & 1 deletion crates/sui-json-rpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sui_types::sui_system_state::SuiSystemState;
use fastcrypto::encoding::Base64;
use sui_json::SuiJsonValue;
use sui_json_rpc_types::{
Balance, CoinPage, DynamicFieldPage, EventPage, GetObjectDataResponse,
Balance, CoinPage, DevInspectResults, DynamicFieldPage, EventPage, GetObjectDataResponse,
GetPastObjectDataResponse, GetRawObjectDataResponse, MoveFunctionArgType,
RPCTransactionRequestParams, SuiCoinMetadata, SuiEventEnvelope, SuiEventFilter,
SuiExecuteTransactionResponse, SuiMoveNormalizedFunction, SuiMoveNormalizedModule,
Expand Down Expand Up @@ -181,6 +181,13 @@ pub trait RpcReadApi {
#[open_rpc(namespace = "sui", tag = "Full Node API")]
#[rpc(server, client, namespace = "sui")]
pub trait RpcFullNodeReadApi {
/// Return dev-inpsect results of the transaction, including both the transaction
/// effects and return values of the transaction.
#[method(name = "devInspectTransaction")]
async fn dev_inspect_transaction(&self, tx_bytes: Base64) -> RpcResult<DevInspectResults>;

/// Return transaction execution effects including the gas cost summary,
/// while the effects are not committed to the chain.
#[method(name = "dryRunTransaction")]
async fn dry_run_transaction(&self, tx_bytes: Base64) -> RpcResult<SuiTransactionEffects>;

Expand Down
15 changes: 13 additions & 2 deletions crates/sui-json-rpc/src/read_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use fastcrypto::encoding::Base64;
use jsonrpsee::RpcModule;
use sui_core::authority::AuthorityState;
use sui_json_rpc_types::{
DynamicFieldPage, GetObjectDataResponse, GetPastObjectDataResponse, MoveFunctionArgType,
ObjectValueKind, Page, SuiMoveNormalizedFunction, SuiMoveNormalizedModule,
DevInspectResults, DynamicFieldPage, GetObjectDataResponse, GetPastObjectDataResponse,
MoveFunctionArgType, ObjectValueKind, Page, SuiMoveNormalizedFunction, SuiMoveNormalizedModule,
SuiMoveNormalizedStruct, SuiObjectInfo, SuiTransactionAuthSignersResponse,
SuiTransactionEffects, SuiTransactionResponse, TransactionsPage,
};
Expand Down Expand Up @@ -220,6 +220,17 @@ impl SuiRpcModule for ReadApi {

#[async_trait]
impl RpcFullNodeReadApiServer for FullNodeApi {
async fn dev_inspect_transaction(&self, tx_bytes: Base64) -> RpcResult<DevInspectResults> {
let tx_data =
bcs::from_bytes(&tx_bytes.to_vec().map_err(|e| anyhow!(e))?).map_err(|e| anyhow!(e))?;
let intent_msg = IntentMessage::new(Intent::default(), tx_data);
let txn_digest = TransactionDigest::new(sha3_hash(&intent_msg.value));
Ok(self
.state
.dev_inspect_transaction(intent_msg.value, txn_digest)
.await?)
}

async fn dry_run_transaction(&self, tx_bytes: Base64) -> RpcResult<SuiTransactionEffects> {
let tx_data =
bcs::from_bytes(&tx_bytes.to_vec().map_err(|e| anyhow!(e))?).map_err(|e| anyhow!(e))?;
Expand Down
147 changes: 147 additions & 0 deletions crates/sui-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,39 @@
}
]
},
{
"name": "sui_devInspectTransaction",
"tags": [
{
"name": "Full Node API"
}
],
"description": "Return dev-inpsect results of the transaction, including both the transaction effects and return values of the transaction.",
"params": [
{
"name": "tx_bytes",
"required": true,
"schema": {
"$ref": "#/components/schemas/Base64"
}
}
],
"result": {
"name": "DevInspectResults",
"required": true,
"schema": {
"$ref": "#/components/schemas/DevInspectResults"
}
}
},
{
"name": "sui_dryRunTransaction",
"tags": [
{
"name": "Full Node API"
}
],
"description": "Return transaction execution effects including the gas cost summary, while the effects are not committed to the chain.",
"params": [
{
"name": "tx_bytes",
Expand Down Expand Up @@ -2782,6 +2808,32 @@
}
]
},
"DevInspectResults": {
"description": "The response from processing a dev inspect transaction",
"type": "object",
"required": [
"effects",
"results"
],
"properties": {
"effects": {
"description": "Summary of effects that likely would be generated if the transaction is actually run. Note however, that not all dev-inspect transactions are actually usable as transactions so it might not be possible actually generate these effects from a normal transaction.",
"allOf": [
{
"$ref": "#/components/schemas/TransactionEffects"
}
]
},
"results": {
"description": "Execution results (including return values) from executing the transactions Currently contains only return values from Move calls",
"allOf": [
{
"$ref": "#/components/schemas/Result_of_Array_of_Tuple_of_uint_and_SuiExecutionResult_or_String"
}
]
}
}
},
"DynamicFieldInfo": {
"type": "object",
"required": [
Expand Down Expand Up @@ -4478,6 +4530,47 @@
}
]
},
"Result_of_Array_of_Tuple_of_uint_and_SuiExecutionResult_or_String": {
"oneOf": [
{
"type": "object",
"required": [
"Ok"
],
"properties": {
"Ok": {
"type": "array",
"items": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"$ref": "#/components/schemas/SuiExecutionResult"
}
],
"maxItems": 2,
"minItems": 2
}
}
}
},
{
"type": "object",
"required": [
"Err"
],
"properties": {
"Err": {
"type": "string"
}
}
}
]
},
"Secp256k1SuiSignature": {
"$ref": "#/components/schemas/Base64"
},
Expand Down Expand Up @@ -4714,6 +4807,60 @@
}
]
},
"SuiExecutionResult": {
"type": "object",
"properties": {
"mutable_reference_outputs": {
"description": "The value of any arguments that were mutably borrowed. Non-mut borrowed values are not included",
"type": "array",
"items": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint8",
"minimum": 0.0
},
{
"type": "array",
"items": {
"type": "integer",
"format": "uint8",
"minimum": 0.0
}
},
{
"$ref": "#/components/schemas/TypeTag"
}
],
"maxItems": 3,
"minItems": 3
}
},
"return_values": {
"description": "The return values from the function",
"type": "array",
"items": {
"type": "array",
"items": [
{
"type": "array",
"items": {
"type": "integer",
"format": "uint8",
"minimum": 0.0
}
},
{
"$ref": "#/components/schemas/TypeTag"
}
],
"maxItems": 2,
"minItems": 2
}
}
}
},
"SuiJsonValue": {},
"SuiMoveAbility": {
"type": "string",
Expand Down
18 changes: 18 additions & 0 deletions sdk/typescript/src/providers/json-rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
isSuiMoveNormalizedStruct,
isSuiTransactionResponse,
isTransactionEffects,
isDevInspectResults,
isCoinMetadata,
isSuiTransactionAuthSignersResponse,
} from '../types/index.guard';
Expand Down Expand Up @@ -53,6 +54,7 @@ import {
FaucetResponse,
Order,
TransactionEffects,
DevInspectResults,
CoinMetadata,
versionToString,
isValidTransactionDigest,
Expand Down Expand Up @@ -694,6 +696,22 @@ export class JsonRpcProvider extends Provider {
return this.wsClient.unsubscribeEvent(id);
}

async devInspectTransaction(txBytes: string): Promise<DevInspectResults> {
try {
const resp = await this.client.requestWithType(
'sui_devInspectTransaction',
[txBytes],
isDevInspectResults,
this.options.skipDataValidation
);
return resp;
} catch (err) {
throw new Error(
`Error dev inspect transaction with request type: ${err}`
);
}
}

async dryRunTransaction(txBytes: string): Promise<TransactionEffects> {
try {
const resp = await this.client.requestWithType(
Expand Down
5 changes: 4 additions & 1 deletion sdk/typescript/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
Order,
TransactionEffects,
CoinMetadata,
DevInspectResults,
} from '../types';

///////////////////////////////
Expand Down Expand Up @@ -247,7 +248,9 @@ export abstract class Provider {
* @param id - subscription id to unsubscribe from (previously received from subscribeEvent)
*/
abstract unsubscribeEvent(id: SubscriptionId): Promise<boolean>;
// TODO: add more interface methods

abstract devInspectTransaction(txBytes: string): Promise<DevInspectResults>;

abstract dryRunTransaction(txBytes: string): Promise<TransactionEffects>;
// TODO: add more interface methods
}
5 changes: 5 additions & 0 deletions sdk/typescript/src/providers/void-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
Order,
TransactionEffects,
CoinMetadata,
DevInspectResults
} from '../types';
import { Provider } from './provider';

Expand Down Expand Up @@ -116,6 +117,10 @@ export class VoidProvider extends Provider {
throw this.newError('executeTransaction with request Type');
}

devInspectTransaction(_txBytes: string): Promise<DevInspectResults> {
throw this.newError('devInspectTransaction');
}

dryRunTransaction(_txBytes: string): Promise<TransactionEffects> {
throw this.newError('dryRunTransaction');
}
Expand Down
Loading