Skip to content

Commit 200e9a5

Browse files
feat(starknet_api): add getters for InternalRpcTransaction
1 parent 541ae00 commit 200e9a5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

crates/starknet_api/src/rpc_transaction.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,44 @@ impl From<RpcTransaction> for Transaction {
122122
}
123123
}
124124

125+
macro_rules! implement_internal_getters_for_internal_rpc {
126+
($(($field_name:ident, $field_ty:ty)),* $(,)?) => {
127+
$(
128+
pub fn $field_name(&self) -> $field_ty {
129+
match &self.tx {
130+
InternalRpcTransactionWithoutTxHash::Declare(tx) => tx.$field_name.clone(),
131+
InternalRpcTransactionWithoutTxHash::Invoke(RpcInvokeTransaction::V3(tx)) => tx.$field_name.clone(),
132+
InternalRpcTransactionWithoutTxHash::DeployAccount(tx) => {
133+
let RpcDeployAccountTransaction::V3(tx) = &tx.tx;
134+
tx.$field_name.clone()
135+
},
136+
}
137+
}
138+
)*
139+
};
140+
}
141+
142+
impl InternalRpcTransaction {
143+
implement_internal_getters_for_internal_rpc!(
144+
(nonce, Nonce),
145+
(resource_bounds, AllResourceBounds),
146+
(tip, Tip),
147+
);
148+
149+
pub fn contract_address(&self) -> ContractAddress {
150+
match &self.tx {
151+
InternalRpcTransactionWithoutTxHash::Declare(tx) => tx.sender_address,
152+
InternalRpcTransactionWithoutTxHash::Invoke(RpcInvokeTransaction::V3(tx)) => {
153+
tx.sender_address
154+
}
155+
InternalRpcTransactionWithoutTxHash::DeployAccount(tx) => tx.contract_address,
156+
}
157+
}
158+
159+
pub fn tx_hash(&self) -> TransactionHash {
160+
self.tx_hash
161+
}
162+
}
125163
/// A RPC declare transaction.
126164
///
127165
/// This transaction is equivalent to the component DECLARE_TXN in the

0 commit comments

Comments
 (0)