@@ -17,6 +17,15 @@ class Transaction(typing.TypedDict):
1717
1818
1919def calculate_txid (transaction : tron_pb2 .Transaction ) -> str :
20+ """
21+ Compute the transaction ID by hashing the serialized raw data of a Tron transaction.
22+
23+ Parameters:
24+ transaction (tron_pb2.Transaction): The Tron transaction whose ID is to be calculated.
25+
26+ Returns:
27+ str: The SHA-256 hash of the transaction's raw data, represented as a hexadecimal string.
28+ """
2029 raw_bytes = transaction .raw_data .SerializeToString ()
2130 return hashlib .sha256 (raw_bytes ).hexdigest ()
2231
@@ -27,16 +36,18 @@ def calculate_txid(transaction: tron_pb2.Transaction) -> str:
2736
2837
2938def _get_tapos_meta (ref_block_id : str ) -> typing .Tuple [str , str , int , int ]:
30- """Extract TAPoS metadata from a block id.
39+ """
40+ Extracts TAPoS (Transaction as Proof of Stake) metadata from a given block ID.
3141
32- Parameters
33- ----------
34- ref_block_id: Hex string of the latest block id
42+ Parameters:
43+ ref_block_id (str): The block ID to extract TAPoS metadata from.
3544
36- Returns
37- -------
38- typing.Tuple[str, str, int, int]
39- (ref_block_bytes_hex, ref_block_hash_hex, timestamp_ms, expiration_ms)
45+ Returns:
46+ tuple: A tuple containing:
47+ - Reference block bytes as a hex string
48+ - Reference block hash as a hex string
49+ - Current timestamp in milliseconds
50+ - Expiration timestamp in milliseconds (current time plus 60 seconds)
4051 """
4152 ref_block_bytes_hex = get_ref_block_bytes (ref_block_id )
4253 ref_block_hash_hex = get_ref_block_hash (ref_block_id )
@@ -51,6 +62,23 @@ def create_transaction_offline(
5162 amount : int ,
5263 ref_block_id : str ,
5364) -> Transaction :
65+ """
66+ Construct an unsigned TRX transfer transaction offline.
67+
68+ Builds a Tron transaction dictionary for transferring TRX from one address
69+ to another using the provided reference block ID for TAPoS metadata.
70+ The transaction is not signed and includes all necessary raw data fields
71+ for later signing and broadcasting.
72+
73+ Parameters:
74+ owner_address (str): Base58 or hex-encoded address of the sender.
75+ to_address (str): Base58 or hex-encoded address of the recipient.
76+ amount (int): Amount of TRX to transfer, in SUN (1 TRX = 1_000_000 SUN).
77+ ref_block_id (str): Hex string of the reference block ID for TAPoS.
78+
79+ Returns:
80+ Transaction: Dictionary containing the transaction ID, raw data, empty signature list, and no permission.
81+ """
5482 to_address_raw = to_raw_address (to_address )
5583 from_address_raw = to_raw_address (owner_address )
5684
@@ -113,17 +141,22 @@ def create_smart_contract_transaction_offline(
113141 fee_limit : int ,
114142 contract_address : str ,
115143) -> Transaction :
116- """Create and sign a TRC-20 `transfer` transaction.
117-
118- Parameters
119- ----------
120- from_address: Base58Check address of the sender
121- to_address: Recipient address (Base58Check or hex)
122- amount: Token amount in the token's smallest unit
123- ref_block_id: Hex string of the latest block id (for TAPoS)
124- private_key: 32-byte private key of the sender
125- fee_limit: Maximum energy fee to spend (in SUN)
126- contract_address: Address of the token (smart-contract) to invoke
144+ """
145+ Construct an unsigned TRC-20 token transfer transaction offline,
146+ encoding the smart contract call and TAPoS metadata.
147+
148+ Parameters:
149+ from_address (str): Base58Check address of the sender.
150+ to_address (str): Recipient address in Base58Check or hex format.
151+ amount (int): Token amount in the token's smallest unit.
152+ ref_block_id (str): Hex string of the latest block ID for TAPoS.
153+ fee_limit (int): Maximum energy fee to spend (in SUN).
154+ contract_address (str): Address of the TRC-20 token smart contract.
155+
156+ Returns:
157+ Transaction: A dictionary representing the unsigned transaction,
158+ including transaction ID, raw data with encoded contract call,
159+ empty signature list, and no permission.
127160 """
128161
129162 # ------------------------------------------------------------------ #
0 commit comments