@@ -9,12 +9,11 @@ use tokio::{fs::OpenOptions, io::AsyncWriteExt, sync::RwLock};
9
9
use crate :: block:: DerivativeBlock ;
10
10
use crate :: dump_headers:: Headers ;
11
11
use crate :: {
12
- block:: { self , BasicInfo , Block , SummarizeBlock , TransactionBlock } ,
13
- errors:: DerivChainErrorKind ,
12
+ block:: { self , BasicInfo , Block , SummarizeBlock } ,
14
13
errors:: { BlockChainTreeError , ChainErrorKind } ,
15
14
merkletree:: MerkleTree ,
16
15
tools,
17
- transaction:: { Transaction , Transactionable } ,
16
+ transaction:: Transactionable ,
18
17
} ;
19
18
use crate :: { static_values:: * , transaction} ;
20
19
@@ -148,6 +147,7 @@ impl MainChain {
148
147
let mut file = OpenOptions :: new ( )
149
148
. write ( true )
150
149
. create ( true )
150
+ . truncate ( true )
151
151
. open ( path_config)
152
152
. await
153
153
. change_context ( BlockChainTreeError :: Chain ( ChainErrorKind :: DumpConfig ) ) ?;
@@ -249,7 +249,7 @@ impl MainChain {
249
249
let raw_transaction = self . get_transaction_raw ( transaction_hash) ?;
250
250
251
251
if let Some ( tr) = raw_transaction {
252
- if !tr. get ( 0 ) . unwrap_or ( & 10 ) . eq ( & ( Headers :: Transaction as u8 ) ) {
252
+ if !tr. first ( ) . unwrap_or ( & 10 ) . eq ( & ( Headers :: Transaction as u8 ) ) {
253
253
return Err ( BlockChainTreeError :: Chain ( ChainErrorKind :: FindByHashE ) . into ( ) ) ;
254
254
}
255
255
return Ok ( Some (
@@ -329,7 +329,7 @@ impl MainChain {
329
329
height. to_big_endian ( & mut height_serialized) ;
330
330
let mut dump = self
331
331
. blocks
332
- . get ( & height_serialized)
332
+ . get ( height_serialized)
333
333
. change_context ( BlockChainTreeError :: Chain ( ChainErrorKind :: FindByHeight ) ) ?;
334
334
335
335
if let Some ( dump) = dump. take ( ) {
@@ -529,6 +529,7 @@ impl DerivativeChain {
529
529
let mut file = OpenOptions :: new ( )
530
530
. write ( true )
531
531
. create ( true )
532
+ . truncate ( true )
532
533
. open ( path_config)
533
534
. await
534
535
. change_context ( BlockChainTreeError :: Chain ( ChainErrorKind :: DumpConfig ) ) ?;
@@ -620,7 +621,7 @@ impl DerivativeChain {
620
621
let raw_transaction = self . get_transaction_raw ( transaction_hash) ?;
621
622
622
623
if let Some ( tr) = raw_transaction {
623
- if !tr. get ( 0 ) . unwrap_or ( & 10 ) . eq ( & ( Headers :: Transaction as u8 ) ) {
624
+ if !tr. first ( ) . unwrap_or ( & 10 ) . eq ( & ( Headers :: Transaction as u8 ) ) {
624
625
return Err ( BlockChainTreeError :: Chain ( ChainErrorKind :: FindByHashE ) . into ( ) ) ;
625
626
}
626
627
return Ok ( Some (
@@ -700,7 +701,7 @@ impl DerivativeChain {
700
701
height. to_big_endian ( & mut height_serialized) ;
701
702
let mut dump = self
702
703
. blocks
703
- . get ( & height_serialized)
704
+ . get ( height_serialized)
704
705
. change_context ( BlockChainTreeError :: Chain ( ChainErrorKind :: FindByHeight ) ) ?;
705
706
706
707
if let Some ( dump) = dump. take ( ) {
@@ -774,7 +775,9 @@ impl DerivativeChain {
774
775
Some ( Arc :: new (
775
776
block:: DerivativeBlock :: parse ( & data[ 1 ..] )
776
777
. change_context ( BlockChainTreeError :: Chain ( ChainErrorKind :: FindByHeight ) )
777
- . attach_printable ( format ! ( "Failed to deserialize latest main chain block" , ) ) ?,
778
+ . attach_printable (
779
+ "Failed to deserialize latest main chain block" . to_string ( ) ,
780
+ ) ?,
778
781
) )
779
782
} else {
780
783
None
0 commit comments