// For each contract, read all the pages into buffers first, and check for following conditions:
// 1. the file is successfully read into buffer,
// 2. the file size is either 0 or 65536,
//
// Considered success only if all the conditions are true, otherwise returns an error.
For each contract, read all the pages into buffers first, and check for following conditions:
1. the file is successfully read into buffer,
2. the file size is either 0 or 65536.

Considered success only if all the conditions are true, otherwise returns an error.
// For each contract read all the pages into buffers first and check for following conditions : // 1 . the file is successfully read into buffer // 2 . the file size is either 0 or 65536 // // Considered success only if all the conditions are true otherwise returns an error .
func restoreContractPages(
	tree *avl.Tree, contracts []TransactionID, contractPageFiles map[TransactionID][]string,
) error {
	pool := bytebufferpool.Pool{}
	for _, id := range contracts {
		files := contractPageFiles[id]
		WriteAccountContractNumPages(tree, id, uint64(len(files)))
		for i := range files {
			file := files[i]
			if len(file) == 0 {
				return errors.Errorf("contract %x is missing page index %d", id, i)
			}
			buf := pool.Get()
			f, err := os.Open(file)
			if err != nil {
				return errors.Wrapf(err, "failed to open contract page file %s", file)
			}
			n, err := buf.ReadFrom(f)
			if err != nil {
				return errors.Wrapf(err, "failed to read contract page file %s", file)
			}
			if n != 0 && n != PageSize {
				return errors.Errorf(
					"contract page file %s has invalid page size %d. must be 0 or %d", file, n, PageSize,
				)
			}
			if buf.Len() == 0 {
				continue
			}
			WriteAccountContractPage(tree, id, uint64(i), buf.Bytes())
			pool.Put(buf)
		}
	}
	return nil
}
func restoreContractPages ( tree * avl . Tree , contracts [ ] TransactionID , contractPageFiles map [ TransactionID ] [ ] string , ) error { pool := bytebufferpool . Pool { } for _ , id := range contracts { files := contractPageFiles [ id ] WriteAccountContractNumPages ( tree , id , uint64 ( len ( files ) ) ) for i := range files { file := files [ i ] if len ( file ) == 0 { return errors . Errorf ( " " , id , i ) } buf := pool . Get ( ) f , err := os . Open ( file ) if err != nil { return errors . Wrapf ( err , " " , file ) } n , err := buf . ReadFrom ( f ) if err != nil { return errors . Wrapf ( err , " " , file ) } if n != 0 && n != PageSize { return errors . Errorf ( " " , file , n , PageSize , ) } if buf . Len ( ) == 0 { continue } WriteAccountContractPage ( tree , id , uint64 ( i ) , buf . Bytes ( ) ) pool . Put ( buf ) } } return nil }
For each contract, read all the pages into buffers first, and check for following conditions:
1. the file is successfully read into buffer,
2. the file size is either 0 or 65536.
For each contract read all the pages into buffers first and check for following conditions : 1 . the file is successfully read into buffer 2 . the file size is either 0 or 65536 .
// Check page size // This assumes WriteAccountContractPage will make a copy of the bytes.