iota_json_rpc_api/write.rs
1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use fastcrypto::encoding::Base64;
6use iota_json_rpc_types::{
7 DevInspectArgs, DevInspectResults, DryRunTransactionBlockResponse,
8 IotaTransactionBlockResponse, IotaTransactionBlockResponseOptions,
9};
10use iota_open_rpc_macros::open_rpc;
11use iota_types::{
12 base_types::IotaAddress, iota_serde::BigInt, quorum_driver_types::ExecuteTransactionRequestType,
13};
14use jsonrpsee::{core::RpcResult, proc_macros::rpc};
15
16/// Provides methods for executing and testing transactions.
17#[open_rpc(namespace = "iota", tag = "Write API")]
18#[rpc(server, client, namespace = "iota")]
19pub trait WriteApi {
20 /// Execute the transaction and wait for results if desired.
21 /// Request types:
22 /// 1. WaitForEffectsCert: waits for TransactionEffectsCert and then return to
23 /// client. This mode is a proxy for transaction finality.
24 /// 2. WaitForLocalExecution: waits for TransactionEffectsCert and make sure the
25 /// node executed the transaction locally before returning the client. The
26 /// local execution makes sure this node is aware of this transaction when
27 /// client fires subsequent queries. However if the node fails to execute the
28 /// transaction locally in a timely manner, a bool type in the response is
29 /// set to false to indicated the case.
30 /// request_type is default to be `WaitForEffectsCert` unless
31 /// options.show_events or options.show_effects is true
32 #[rustfmt::skip]
33 #[method(name = "executeTransactionBlock")]
34 async fn execute_transaction_block(
35 &self,
36 /// BCS serialized transaction data bytes without its type tag, as base-64 encoded string.
37 tx_bytes: Base64,
38 /// A list of signatures (`flag || signature || pubkey` bytes, as base-64 encoded string). Signature is committed to the intent message of the transaction data, as base-64 encoded string.
39 signatures: Vec<Base64>,
40 /// options for specifying the content to be returned
41 options: Option<IotaTransactionBlockResponseOptions>,
42 /// The request type, derived from `IotaTransactionBlockResponseOptions` if None
43 request_type: Option<ExecuteTransactionRequestType>,
44 ) -> RpcResult<IotaTransactionBlockResponse>;
45
46 /// Runs the transaction in dev-inspect mode. Which allows for nearly any
47 /// transaction (or Move call) with any arguments. Detailed results are
48 /// provided, including both the transaction effects and any return values.
49 #[rustfmt::skip]
50 #[method(name = "devInspectTransactionBlock")]
51 async fn dev_inspect_transaction_block(
52 &self,
53 sender_address: IotaAddress,
54 /// BCS encoded TransactionKind(as opposed to TransactionData, which include gasBudget and gasPrice)
55 tx_bytes: Base64,
56 /// Gas is not charged, but gas usage is still calculated. Default to use reference gas price
57 gas_price: Option<BigInt<u64>>,
58 /// The epoch to perform the call. Will be set from the system state object if not provided
59 epoch: Option<BigInt<u64>>,
60 /// Additional arguments including gas_budget, gas_objects, gas_sponsor and skip_checks.
61 additional_args: Option<DevInspectArgs>,
62 ) -> RpcResult<DevInspectResults>;
63
64 /// Return transaction execution effects including the gas cost summary,
65 /// while the effects are not committed to the chain.
66 #[method(name = "dryRunTransactionBlock")]
67 async fn dry_run_transaction_block(
68 &self,
69 tx_bytes: Base64,
70 ) -> RpcResult<DryRunTransactionBlockResponse>;
71}