@@ -980,34 +980,31 @@ impl<'a> RandomTxMaker<'a> {
980980 // create order to exchange part of available coins for tokens
981981 if let Some ( ( token_id, token_supply) ) =
982982 get_random_token ( rng, self . tokens_store , tokens_cache)
983+ && token_supply > Amount :: ZERO
983984 {
984- if token_supply > Amount :: ZERO {
985- let ask_amount =
986- Amount :: from_atoms ( rng. random_range ( 1u128 ..=token_supply. into_atoms ( ) ) ) ;
987- let give_amount =
988- Amount :: from_atoms ( rng. random_range ( 1u128 ..=atoms_to_spend) ) ;
989- let order_data = OrderData :: new (
990- Destination :: AnyoneCanSpend ,
991- OutputValue :: TokenV1 ( token_id, ask_amount) ,
992- OutputValue :: Coin ( give_amount) ,
993- ) ;
994- let change = ( amount_to_spend - give_amount) . unwrap ( ) ;
985+ let ask_amount =
986+ Amount :: from_atoms ( rng. random_range ( 1u128 ..=token_supply. into_atoms ( ) ) ) ;
987+ let give_amount = Amount :: from_atoms ( rng. random_range ( 1u128 ..=atoms_to_spend) ) ;
988+ let order_data = OrderData :: new (
989+ Destination :: AnyoneCanSpend ,
990+ OutputValue :: TokenV1 ( token_id, ask_amount) ,
991+ OutputValue :: Coin ( give_amount) ,
992+ ) ;
993+ let change = ( amount_to_spend - give_amount) . unwrap ( ) ;
995994
996- // Transfer output is created intentionally besides order output to not waste utxo
997- // (e.g. single genesis output on issuance)
998- let outputs = vec ! [
999- TxOutput :: CreateOrder ( Box :: new( order_data) ) ,
1000- TxOutput :: Transfer (
1001- OutputValue :: Coin ( change) ,
1002- key_manager
1003- . new_destination( self . chainstate. get_chain_config( ) , rng) ,
1004- ) ,
1005- ] ;
995+ // Transfer output is created intentionally besides order output to not waste utxo
996+ // (e.g. single genesis output on issuance)
997+ let outputs = vec ! [
998+ TxOutput :: CreateOrder ( Box :: new( order_data) ) ,
999+ TxOutput :: Transfer (
1000+ OutputValue :: Coin ( change) ,
1001+ key_manager. new_destination( self . chainstate. get_chain_config( ) , rng) ,
1002+ ) ,
1003+ ] ;
10061004
1007- self . order_can_be_created = false ;
1005+ self . order_can_be_created = false ;
10081006
1009- result_outputs. extend_from_slice ( & outputs) ;
1010- }
1007+ result_outputs. extend_from_slice ( & outputs) ;
10111008 }
10121009 } else if switch == 3 && !self . account_command_used {
10131010 // try fill order
@@ -1019,28 +1016,27 @@ impl<'a> RandomTxMaker<'a> {
10191016 calculate_filled_order_value ( & orders_cache, order_id, amount_to_spend)
10201017 . unwrap ( ) ;
10211018
1022- if let Some ( filled_value) = filled_value {
1023- if !is_frozen_token ( & filled_value, tokens_cache)
1024- && !is_frozen_order ( & orders_cache, order_id)
1025- {
1026- let input = TxInput :: OrderAccountCommand (
1027- OrderAccountCommand :: FillOrder ( order_id, amount_to_spend) ,
1028- ) ;
1019+ if let Some ( filled_value) = filled_value
1020+ && !is_frozen_token ( & filled_value, tokens_cache)
1021+ && !is_frozen_order ( & orders_cache, order_id)
1022+ {
1023+ let input = TxInput :: OrderAccountCommand ( OrderAccountCommand :: FillOrder (
1024+ order_id,
1025+ amount_to_spend,
1026+ ) ) ;
10291027
1030- let output = TxOutput :: Transfer (
1031- filled_value,
1032- key_manager
1033- . new_destination ( self . chainstate . get_chain_config ( ) , rng) ,
1034- ) ;
1028+ let output = TxOutput :: Transfer (
1029+ filled_value,
1030+ key_manager. new_destination ( self . chainstate . get_chain_config ( ) , rng) ,
1031+ ) ;
10351032
1036- let _ = orders_cache
1037- . fill_order ( order_id, amount_to_spend, OrdersVersion :: V1 )
1038- . unwrap ( ) ;
1039- self . account_command_used = true ;
1033+ let _ = orders_cache
1034+ . fill_order ( order_id, amount_to_spend, OrdersVersion :: V1 )
1035+ . unwrap ( ) ;
1036+ self . account_command_used = true ;
10401037
1041- result_inputs. push ( input) ;
1042- result_outputs. push ( output) ;
1043- }
1038+ result_inputs. push ( input) ;
1039+ result_outputs. push ( output) ;
10441040 }
10451041 }
10461042 } else if switch == 6 {
@@ -1136,17 +1132,17 @@ impl<'a> RandomTxMaker<'a> {
11361132 result_outputs. push ( output) ;
11371133
11381134 // Occasionally create new delegation id
1139- if rng. random :: < bool > ( ) && self . delegation_can_be_created {
1140- if let Some ( ( pool_id, _) ) =
1135+ if rng. random :: < bool > ( )
1136+ && self . delegation_can_be_created
1137+ && let Some ( ( pool_id, _) ) =
11411138 get_random_pool_data ( rng, self . pos_accounting_store , & pos_accounting_cache)
1142- {
1143- self . delegation_can_be_created = false ;
1139+ {
1140+ self . delegation_can_be_created = false ;
11441141
1145- result_outputs. push ( TxOutput :: CreateDelegationId (
1146- key_manager. new_destination ( self . chainstate . get_chain_config ( ) , rng) ,
1147- * pool_id,
1148- ) ) ;
1149- }
1142+ result_outputs. push ( TxOutput :: CreateDelegationId (
1143+ key_manager. new_destination ( self . chainstate . get_chain_config ( ) , rng) ,
1144+ * pool_id,
1145+ ) ) ;
11501146 }
11511147 }
11521148 }
@@ -1244,32 +1240,24 @@ impl<'a> RandomTxMaker<'a> {
12441240 )
12451241 . unwrap ( ) ;
12461242
1247- if let Some ( filled_value) = filled_value {
1248- if !is_frozen_token ( & filled_value, tokens_cache)
1249- && !is_frozen_order ( orders_cache, order_id)
1250- {
1251- result_outputs. push ( TxOutput :: Transfer (
1252- filled_value,
1253- key_manager
1254- . new_destination ( self . chainstate . get_chain_config ( ) , rng) ,
1255- ) ) ;
1256-
1257- result_inputs. push ( TxInput :: OrderAccountCommand (
1258- OrderAccountCommand :: FillOrder (
1259- order_id,
1260- Amount :: from_atoms ( atoms) ,
1261- ) ,
1262- ) ) ;
1263-
1264- let _ = orders_cache
1265- . fill_order (
1266- order_id,
1267- Amount :: from_atoms ( atoms) ,
1268- OrdersVersion :: V1 ,
1269- )
1270- . unwrap ( ) ;
1271- self . account_command_used = true ;
1272- }
1243+ if let Some ( filled_value) = filled_value
1244+ && !is_frozen_token ( & filled_value, tokens_cache)
1245+ && !is_frozen_order ( orders_cache, order_id)
1246+ {
1247+ result_outputs. push ( TxOutput :: Transfer (
1248+ filled_value,
1249+ key_manager
1250+ . new_destination ( self . chainstate . get_chain_config ( ) , rng) ,
1251+ ) ) ;
1252+
1253+ result_inputs. push ( TxInput :: OrderAccountCommand (
1254+ OrderAccountCommand :: FillOrder ( order_id, Amount :: from_atoms ( atoms) ) ,
1255+ ) ) ;
1256+
1257+ let _ = orders_cache
1258+ . fill_order ( order_id, Amount :: from_atoms ( atoms) , OrdersVersion :: V1 )
1259+ . unwrap ( ) ;
1260+ self . account_command_used = true ;
12731261 }
12741262 }
12751263 }
0 commit comments