forked from launchbadge/hedera-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction_record.rs
67 lines (56 loc) · 1.87 KB
/
transaction_record.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::{id::PyAccountId, PyContractFunctionResult, PyDateTime, PyTransactionReceipt};
use derive_more::From;
use hedera::{TransactionRecord, TransactionRecordBody};
use pyo3::prelude::*;
use try_from::TryInto;
// todo: add a .kind field to indicate what kind the body type is: ContractCall, ContractCreate, or Transfer
#[pyclass(name = TransactionRecord)]
#[derive(From)]
pub struct PyTransactionRecord {
pub(crate) inner: TransactionRecord,
}
#[pymethods]
impl PyTransactionRecord {
#[getter]
pub fn receipt(&self) -> PyResult<PyTransactionReceipt> {
Ok(self.inner.receipt.clone().into())
}
#[getter]
pub fn transaction_hash(&self) -> PyResult<Vec<u8>> {
Ok(self.inner.transaction_hash.clone())
}
#[getter]
pub fn consensus_timestamp(&self) -> PyResult<Option<PyDateTime>> {
self.inner
.consensus_timestamp
.map(|ts| ts.try_into())
.transpose()
}
#[getter]
pub fn memo(&self) -> PyResult<String> {
Ok(self.inner.memo.clone())
}
#[getter]
pub fn transaction_fee(&self) -> PyResult<u64> {
Ok(self.inner.transaction_fee)
}
#[getter]
pub fn contract_function_result(&self) -> PyResult<Option<PyContractFunctionResult>> {
match &self.inner.body {
TransactionRecordBody::ContractCall(result) => Ok(Some(result.clone().into())),
TransactionRecordBody::ContractCreate(result) => Ok(Some(result.clone().into())),
_ => Ok(None),
}
}
#[getter]
pub fn transfers(&self) -> PyResult<Vec<(PyAccountId, i64)>> {
match &self.inner.body {
TransactionRecordBody::Transfer(transfers) => Ok(transfers
.clone()
.into_iter()
.map(|(id, amount)| (id.into(), amount))
.collect()),
_ => Ok(vec![]),
}
}
}