@@ -263,26 +263,42 @@ impl Value {
263263 }
264264
265265 /// Create a new value by inserting a new token or replacing the existing quantity.
266- pub fn insert_token ( & self , cs : & CurrencySymbol , tn : & TokenName , a : & BigInt ) -> Self {
266+ pub fn insert_token (
267+ & self ,
268+ currency_symbol : & CurrencySymbol ,
269+ token_name : & TokenName ,
270+ amount : & BigInt ,
271+ ) -> Self {
267272 let mut result_map = self . clone ( ) ;
268273
269- result_map. insert_token_mut ( cs , tn , a ) ;
274+ result_map. insert_token_mut ( currency_symbol . clone ( ) , token_name . clone ( ) , amount . clone ( ) ) ;
270275
271276 result_map
272277 }
273278 /// Insert a new token into the value, or replace the existing quantity.
274- pub fn insert_token_mut ( & mut self , cs : & CurrencySymbol , tn : & TokenName , a : & BigInt ) {
275- self . 0
276- . entry ( cs. clone ( ) )
277- . and_modify ( |tn_map| {
278- tn_map
279- . entry ( tn. clone ( ) )
280- . and_modify ( |old_a| {
281- old_a. clone_from ( a) ;
282- } )
283- . or_insert_with ( || a. clone ( ) ) ;
284- } )
285- . or_insert_with ( || singleton ( ( tn. clone ( ) , a. clone ( ) ) ) ) ;
279+ pub fn insert_token_mut (
280+ & mut self ,
281+ currency_symbol : CurrencySymbol ,
282+ token_name : TokenName ,
283+ amount : BigInt ,
284+ ) {
285+ let tn_map = self . 0 . get_mut ( & currency_symbol) ;
286+
287+ match tn_map {
288+ None => {
289+ self . 0
290+ . insert ( currency_symbol, singleton ( ( token_name, amount) ) ) ;
291+ }
292+ Some ( tn_map) => {
293+ let val = tn_map. get_mut ( & token_name) ;
294+ match val {
295+ None => {
296+ tn_map. insert ( token_name, amount) ;
297+ }
298+ Some ( old_amount) => * old_amount = amount,
299+ }
300+ }
301+ }
286302 }
287303
288304 /// Return true if the value don't have any entries.
0 commit comments