@@ -157,6 +157,7 @@ impl<'db> ShardLevelState<'db> {
157157 ShardTransaction :: ChangeAssetScheme {
158158 shard_id,
159159 asset_type,
160+ seq,
160161 metadata,
161162 approver,
162163 registrar,
@@ -168,6 +169,7 @@ impl<'db> ShardLevelState<'db> {
168169 sender,
169170 approvers,
170171 asset_type,
172+ * seq,
171173 metadata,
172174 approver,
173175 registrar,
@@ -178,10 +180,11 @@ impl<'db> ShardLevelState<'db> {
178180 shard_id,
179181 asset_type,
180182 output,
183+ seq,
181184 ..
182185 } => {
183186 assert_eq ! ( * shard_id, self . shard_id) ;
184- self . increase_asset_supply ( transaction. tracker ( ) , sender, approvers, asset_type, output)
187+ self . increase_asset_supply ( transaction. tracker ( ) , * seq , sender, approvers, asset_type, output)
185188 }
186189 ShardTransaction :: ComposeAsset {
187190 metadata,
@@ -456,6 +459,7 @@ impl<'db> ShardLevelState<'db> {
456459 sender : & Address ,
457460 approvers : & [ Address ] ,
458461 asset_type : & H160 ,
462+ seq : usize ,
459463 metadata : & str ,
460464 approver : & Option < Address > ,
461465 registrar : & Option < Address > ,
@@ -466,19 +470,31 @@ impl<'db> ShardLevelState<'db> {
466470 }
467471
468472 let mut asset_scheme = self . get_asset_scheme_mut ( self . shard_id , * asset_type) ?;
473+ if asset_scheme. seq ( ) != seq {
474+ return Err ( RuntimeError :: InvalidSeqOfAssetScheme {
475+ asset_type : * asset_type,
476+ shard_id : self . shard_id ,
477+ expected : asset_scheme. seq ( ) ,
478+ actual : seq,
479+ }
480+ . into ( ) )
481+ }
482+
469483 asset_scheme. change_data (
470484 metadata. to_string ( ) ,
471485 approver. clone ( ) ,
472486 registrar. clone ( ) ,
473487 allowed_script_hashes. to_vec ( ) ,
474488 ) ;
489+ asset_scheme. increase_seq ( ) ;
475490
476491 Ok ( ( ) )
477492 }
478493
479494 fn increase_asset_supply (
480495 & mut self ,
481496 transaction_tracker : H256 ,
497+ seq : usize ,
482498 sender : & Address ,
483499 approvers : & [ Address ] ,
484500 asset_type : & H160 ,
@@ -492,7 +508,17 @@ impl<'db> ShardLevelState<'db> {
492508 assert ! ( output. supply > 0 , "Supply increasing quantity must be specified and greater than 0" ) ;
493509
494510 let mut asset_scheme = self . get_asset_scheme_mut ( self . shard_id , * asset_type) ?;
511+ if seq != asset_scheme. seq ( ) {
512+ return Err ( RuntimeError :: InvalidSeqOfAssetScheme {
513+ asset_type : * asset_type,
514+ shard_id : self . shard_id ,
515+ expected : asset_scheme. seq ( ) ,
516+ actual : seq,
517+ }
518+ . into ( ) )
519+ }
495520 let previous_supply = asset_scheme. increase_supply ( output. supply ) ?;
521+ asset_scheme. increase_seq ( ) ;
496522 self . create_asset (
497523 transaction_tracker,
498524 0 ,
@@ -502,7 +528,7 @@ impl<'db> ShardLevelState<'db> {
502528 output. supply ,
503529 None ,
504530 ) ?;
505- ctrace ! ( TX , "Increased asset supply {:?} {:?} {:?}" , asset_type, previous_supply, output. supply) ;
531+ ctrace ! ( TX , "Increased asset supply {:?} {:?} => {:?}" , asset_type, previous_supply, output. supply) ;
506532 ctrace ! ( TX , "Created asset on {}:{}" , self . shard_id, transaction_tracker) ;
507533
508534 Ok ( ( ) )
@@ -2439,6 +2465,7 @@ mod tests {
24392465 network_id : "tc" . into ( ) ,
24402466 shard_id : SHARD_ID ,
24412467 asset_type,
2468+ seq : 0 ,
24422469 metadata : "New metadata" . to_string ( ) ,
24432470 approver : Some ( approver) ,
24442471 registrar : None ,
@@ -2485,6 +2512,7 @@ mod tests {
24852512 network_id : "tc" . into ( ) ,
24862513 shard_id : SHARD_ID ,
24872514 asset_type,
2515+ seq : 0 ,
24882516 output : AssetMintOutput {
24892517 lock_script_hash : H160 :: random ( ) ,
24902518 parameters : vec ! [ ] ,
0 commit comments