@@ -14,7 +14,10 @@ use fuel_tx::{
1414 Cacheable , Chargeable , ConsensusParameters , Create , Input as FuelInput , Output , Script ,
1515 StorageSlot , Transaction as FuelTransaction , TransactionFee , TxPointer , UniqueIdentifier ,
1616 Upgrade , Upload , UploadBody , Witness ,
17- field:: { Inputs , MaxFeeLimit , Outputs , Policies as PoliciesField , ScriptGasLimit , Witnesses } ,
17+ field:: {
18+ Inputs , MaxFeeLimit , Outputs , Policies as PoliciesField , ScriptGasLimit , WitnessLimit ,
19+ Witnesses ,
20+ } ,
1821 input:: {
1922 coin:: CoinSigned ,
2023 message:: { MessageCoinSigned , MessageDataSigned } ,
@@ -377,8 +380,6 @@ macro_rules! impl_tx_builder_trait {
377380 fn generate_fuel_policies_assemble( & self ) -> Policies {
378381 let mut policies = Policies :: default ( ) ;
379382
380- policies. set( PolicyType :: WitnessLimit , self . tx_policies. witness_limit( ) ) ;
381- policies. set( PolicyType :: MaxFee , self . tx_policies. tip( ) ) ;
382383 policies. set( PolicyType :: Maturity , self . tx_policies. maturity( ) ) ;
383384 policies. set( PolicyType :: Tip , self . tx_policies. tip( ) ) ;
384385 policies. set( PolicyType :: Expiration , self . tx_policies. expiration( ) ) ;
@@ -814,7 +815,7 @@ impl ScriptTransactionBuilder {
814815 consensus_parameters : & ConsensusParameters ,
815816 dry_runner : impl DryRunner ,
816817 ) -> Result < Script > {
817- let mut tx = FuelTransaction :: script (
818+ let tx = FuelTransaction :: script (
818819 0 , // default value - will be overwritten
819820 self . script . clone ( ) ,
820821 self . script_data . clone ( ) ,
@@ -828,10 +829,6 @@ impl ScriptTransactionBuilder {
828829 self . witnesses . clone ( ) ,
829830 ) ;
830831
831- if let Some ( max_fee) = self . tx_policies . max_fee ( ) {
832- tx. policies_mut ( ) . set ( PolicyType :: MaxFee , Some ( max_fee) ) ;
833- } ;
834-
835832 let mut tx = match dry_runner
836833 . assemble_tx (
837834 & tx. into ( ) ,
@@ -880,6 +877,15 @@ impl ScriptTransactionBuilder {
880877 }
881878 }
882879
880+ //if user set `witness_limit` we will use it's value only
881+ //if it is higher then the one estimated by assemble_tx
882+ if let Some ( witness_limit) = self . tx_policies . witness_limit ( ) {
883+ if witness_limit > tx. witness_limit ( ) {
884+ tx. policies_mut ( )
885+ . set ( PolicyType :: WitnessLimit , Some ( witness_limit) ) ;
886+ }
887+ }
888+
883889 update_witnesses (
884890 & mut tx,
885891 & self . unresolved_signers ,
@@ -1243,7 +1249,7 @@ impl CreateTransactionBuilder {
12431249 ) -> Result < Create > {
12441250 let num_witnesses = self . num_witnesses ( ) ?;
12451251
1246- let mut tx = FuelTransaction :: create (
1252+ let tx = FuelTransaction :: create (
12471253 self . bytecode_witness_index ,
12481254 self . generate_fuel_policies_assemble ( ) ,
12491255 self . salt ,
@@ -1253,10 +1259,6 @@ impl CreateTransactionBuilder {
12531259 self . witnesses ,
12541260 ) ;
12551261
1256- if let Some ( max_fee) = self . tx_policies . max_fee ( ) {
1257- tx. policies_mut ( ) . set ( PolicyType :: MaxFee , Some ( max_fee) ) ;
1258- } ;
1259-
12601262 let mut tx = match dry_runner
12611263 . assemble_tx (
12621264 & tx. into ( ) ,
@@ -1289,6 +1291,15 @@ impl CreateTransactionBuilder {
12891291 }
12901292 }
12911293
1294+ //if user set `witness_limit` we will use it's value only
1295+ //if it is higher then the one estimated by assemble_tx
1296+ if let Some ( witness_limit) = self . tx_policies . witness_limit ( ) {
1297+ if witness_limit > tx. witness_limit ( ) {
1298+ tx. policies_mut ( )
1299+ . set ( PolicyType :: WitnessLimit , Some ( witness_limit) ) ;
1300+ }
1301+ }
1302+
12921303 update_witnesses (
12931304 & mut tx,
12941305 & self . unresolved_signers ,
@@ -1438,7 +1449,7 @@ impl UploadTransactionBuilder {
14381449 let num_witnesses = self . num_witnesses ( ) ?;
14391450 let policies = self . generate_fuel_policies_assemble ( ) ;
14401451
1441- let mut tx = FuelTransaction :: upload (
1452+ let tx = FuelTransaction :: upload (
14421453 UploadBody {
14431454 root : self . root ,
14441455 witness_index : self . witness_index ,
@@ -1452,10 +1463,6 @@ impl UploadTransactionBuilder {
14521463 self . witnesses ,
14531464 ) ;
14541465
1455- if let Some ( max_fee) = self . tx_policies . max_fee ( ) {
1456- tx. policies_mut ( ) . set ( PolicyType :: MaxFee , Some ( max_fee) ) ;
1457- } ;
1458-
14591466 let mut tx = match dry_runner
14601467 . assemble_tx (
14611468 & tx. into ( ) ,
@@ -1488,6 +1495,15 @@ impl UploadTransactionBuilder {
14881495 }
14891496 }
14901497
1498+ //if user set `witness_limit` we will use it's value only
1499+ //if it is higher then the one estimated by assemble_tx
1500+ if let Some ( witness_limit) = self . tx_policies . witness_limit ( ) {
1501+ if witness_limit > tx. witness_limit ( ) {
1502+ tx. policies_mut ( )
1503+ . set ( PolicyType :: WitnessLimit , Some ( witness_limit) ) ;
1504+ }
1505+ }
1506+
14911507 update_witnesses (
14921508 & mut tx,
14931509 & self . unresolved_signers ,
@@ -1646,18 +1662,14 @@ impl UpgradeTransactionBuilder {
16461662 let num_witnesses = self . num_witnesses ( ) ?;
16471663 let policies = self . generate_fuel_policies_assemble ( ) ;
16481664
1649- let mut tx = FuelTransaction :: upgrade (
1665+ let tx = FuelTransaction :: upgrade (
16501666 self . purpose ,
16511667 policies,
16521668 resolve_fuel_inputs ( self . inputs , num_witnesses, & self . unresolved_witness_indexes ) ?,
16531669 self . outputs ,
16541670 self . witnesses ,
16551671 ) ;
16561672
1657- if let Some ( max_fee) = self . tx_policies . max_fee ( ) {
1658- tx. policies_mut ( ) . set ( PolicyType :: MaxFee , Some ( max_fee) ) ;
1659- } ;
1660-
16611673 let mut tx = match dry_runner
16621674 . assemble_tx (
16631675 & tx. into ( ) ,
@@ -1690,6 +1702,15 @@ impl UpgradeTransactionBuilder {
16901702 }
16911703 }
16921704
1705+ //if user set `witness_limit` we will use it's value only
1706+ //if it is higher then the one estimated by assemble_tx
1707+ if let Some ( witness_limit) = self . tx_policies . witness_limit ( ) {
1708+ if witness_limit > tx. witness_limit ( ) {
1709+ tx. policies_mut ( )
1710+ . set ( PolicyType :: WitnessLimit , Some ( witness_limit) ) ;
1711+ }
1712+ }
1713+
16931714 update_witnesses (
16941715 & mut tx,
16951716 & self . unresolved_signers ,
0 commit comments