@@ -13,7 +13,7 @@ use ethereum_types::U256;
1313use prost:: Message ;
1414
1515/// Default transaction expiration window (60 seconds from block timestamp).
16- const TX_EXPIRATION_MS : i64 = 60_000 ;
16+ const DEFAULT_TX_EXPIRATION_MS : i64 = 60_000 ;
1717
1818/// Extract TAPOS reference fields from a recent block.
1919///
@@ -48,14 +48,18 @@ pub(super) fn wrap_contract(contract_type: ContractType, type_url: &str, value:
4848///
4949/// Timestamp and expiration are derived from `block_data`:
5050/// - `timestamp` = block timestamp (not validated by java-tron; matches TronWeb)
51- /// - `expiration` = block timestamp + 60s
51+ /// - `expiration` = block timestamp + `expiration_sec` (converted to ms)
5252pub fn build_trx_transfer (
5353 from : & TronAddress ,
5454 to : & TronAddress ,
5555 amount_sun : i64 ,
5656 block_data : & TaposBlockData ,
57+ expiration_seconds : Option < u64 > ,
5758) -> TransactionRaw {
5859 let ( ref_block_bytes, ref_block_hash) = tapos_from_block ( block_data. number , & block_data. block_id ) ;
60+ let expiration_ms = expiration_seconds
61+ . map ( |s| ( s as i64 ) . saturating_mul ( 1000 ) )
62+ . unwrap_or ( DEFAULT_TX_EXPIRATION_MS ) ;
5963
6064 let transfer = TransferContract {
6165 owner_address : tron_addr_bytes ( from) ,
@@ -71,7 +75,7 @@ pub fn build_trx_transfer(
7175 TransactionRaw {
7276 ref_block_bytes,
7377 ref_block_hash,
74- expiration : block_data. timestamp . saturating_add ( TX_EXPIRATION_MS ) ,
78+ expiration : block_data. timestamp . saturating_add ( expiration_ms ) ,
7579 data : Vec :: new ( ) ,
7680 contract : vec ! [ contract] ,
7781 timestamp : block_data. timestamp ,
@@ -89,8 +93,12 @@ pub fn build_trc20_transfer(
8993 amount : U256 ,
9094 fee_limit : i64 ,
9195 block_data : & TaposBlockData ,
96+ expiration_seconds : Option < u64 > ,
9297) -> Result < TransactionRaw , ethabi:: Error > {
9398 let ( ref_block_bytes, ref_block_hash) = tapos_from_block ( block_data. number , & block_data. block_id ) ;
99+ let expiration_ms = expiration_seconds
100+ . map ( |s| ( s as i64 ) . saturating_mul ( 1000 ) )
101+ . unwrap_or ( DEFAULT_TX_EXPIRATION_MS ) ;
94102
95103 let trigger = TriggerSmartContract {
96104 owner_address : tron_addr_bytes ( from) ,
@@ -109,7 +117,7 @@ pub fn build_trc20_transfer(
109117 Ok ( TransactionRaw {
110118 ref_block_bytes,
111119 ref_block_hash,
112- expiration : block_data. timestamp . saturating_add ( TX_EXPIRATION_MS ) ,
120+ expiration : block_data. timestamp . saturating_add ( expiration_ms ) ,
113121 data : Vec :: new ( ) ,
114122 contract : vec ! [ contract] ,
115123 timestamp : block_data. timestamp ,
@@ -146,10 +154,10 @@ mod tests {
146154 let from = TronAddress :: from_hex( TEST_FROM_HEX ) . unwrap( ) ;
147155 let to = TronAddress :: from_hex( TEST_TO_HEX ) . unwrap( ) ;
148156
149- let mut raw = build_trx_transfer( & from, & to, 1000 , & block_data) ;
157+ let mut raw = build_trx_transfer( & from, & to, 1000 , & block_data, None ) ;
150158 // Verify timestamp/expiration derived from block_data
151159 assert_eq!( raw. timestamp, block_data. timestamp) ;
152- assert_eq!( raw. expiration, block_data. timestamp + TX_EXPIRATION_MS ) ;
160+ assert_eq!( raw. expiration, block_data. timestamp + DEFAULT_TX_EXPIRATION_MS ) ;
153161 // Override to match the real broadcast tx values for golden vector comparison.
154162 raw. timestamp = 1_770_522_424_709 ;
155163 raw. expiration = 1_770_522_483_000 ;
@@ -179,10 +187,11 @@ mod tests {
179187 let amount = U256 :: from( 2_380_000u64 ) ;
180188 let fee_limit = 2_172_000i64 ;
181189
182- let mut raw = build_trc20_transfer( & from, & contract_addr, & recipient, amount, fee_limit, & block_data) . unwrap( ) ;
190+ let mut raw =
191+ build_trc20_transfer( & from, & contract_addr, & recipient, amount, fee_limit, & block_data, None ) . unwrap( ) ;
183192 // Verify timestamp/expiration derived from block_data
184193 assert_eq!( raw. timestamp, block_data. timestamp) ;
185- assert_eq!( raw. expiration, block_data. timestamp + TX_EXPIRATION_MS ) ;
194+ assert_eq!( raw. expiration, block_data. timestamp + DEFAULT_TX_EXPIRATION_MS ) ;
186195 // Override to match the real broadcast tx values for golden vector comparison.
187196 raw. timestamp = 1_770_972_831_784 ;
188197 raw. expiration = 1_770_972_891_000 ;
0 commit comments