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