mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-21 12:27:49 +01:00
Housekeeping! Removing unnecessary "blockchain" prefix of status codes within the blockchain package.
This commit is contained in:
@@ -14,28 +14,28 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// AddFiles adds files to the blockchain. Status is BlockchainStatusX.
|
||||
// AddFiles adds files to the blockchain. Status is StatusX.
|
||||
// It makes sense to group all files in the same directory into one call, since only one directory record will be created per unique directory per block.
|
||||
func (blockchain *Blockchain) AddFiles(files []BlockRecordFile) (newHeight, newVersion uint64, status int) {
|
||||
encoded, err := encodeBlockRecordFiles(files)
|
||||
if err != nil {
|
||||
return 0, 0, BlockchainStatusCorruptBlockRecord
|
||||
return 0, 0, StatusCorruptBlockRecord
|
||||
}
|
||||
|
||||
return blockchain.Append(encoded)
|
||||
}
|
||||
|
||||
// ListFiles returns a list of all files. Status is BlockchainStatusX.
|
||||
// ListFiles returns a list of all files. Status is StatusX.
|
||||
// If there is a corruption in the blockchain it will stop reading but return the files parsed so far.
|
||||
func (blockchain *Blockchain) ListFiles() (files []BlockRecordFile, status int) {
|
||||
status = blockchain.Iterate(func(block *Block) (statusI int) {
|
||||
filesMore, err := decodeBlockRecordFiles(block.RecordsRaw, block.NodeID)
|
||||
if err != nil {
|
||||
return BlockchainStatusCorruptBlockRecord
|
||||
return StatusCorruptBlockRecord
|
||||
}
|
||||
files = append(files, filesMore...)
|
||||
|
||||
return BlockchainStatusOK
|
||||
return StatusOK
|
||||
})
|
||||
|
||||
return files, status
|
||||
@@ -47,7 +47,7 @@ func (blockchain *Blockchain) FileExists(hash []byte) (files []BlockRecordFile,
|
||||
status = blockchain.Iterate(func(block *Block) (statusI int) {
|
||||
filesD, err := decodeBlockRecordFiles(block.RecordsRaw, block.NodeID)
|
||||
if err != nil {
|
||||
return BlockchainStatusCorruptBlockRecord
|
||||
return StatusCorruptBlockRecord
|
||||
}
|
||||
for _, file := range filesD {
|
||||
if bytes.Equal(file.Hash, hash) {
|
||||
@@ -55,13 +55,13 @@ func (blockchain *Blockchain) FileExists(hash []byte) (files []BlockRecordFile,
|
||||
}
|
||||
}
|
||||
|
||||
return BlockchainStatusOK
|
||||
return StatusOK
|
||||
})
|
||||
|
||||
return files, status
|
||||
}
|
||||
|
||||
// DeleteFiles deletes files from the blockchain. Status is BlockchainStatusX.
|
||||
// DeleteFiles deletes files from the blockchain. Status is StatusX.
|
||||
func (blockchain *Blockchain) DeleteFiles(IDs []uuid.UUID) (newHeight, newVersion uint64, deletedFiles []BlockRecordFile, status int) {
|
||||
newHeight, newVersion, status = blockchain.IterateDeleteRecord(func(record *BlockRecordRaw) (deleteAction int) {
|
||||
if record.Type != RecordTypeFile {
|
||||
@@ -86,7 +86,7 @@ func (blockchain *Blockchain) DeleteFiles(IDs []uuid.UUID) (newHeight, newVersio
|
||||
return
|
||||
}
|
||||
|
||||
// ReplaceFiles is a convenience wrapper to replace files in the blockchain identified via their IDs. Status is BlockchainStatusX.
|
||||
// ReplaceFiles is a convenience wrapper to replace files in the blockchain identified via their IDs. Status is StatusX.
|
||||
// If a file does not exist on the blockchain, it acts as add.
|
||||
func (blockchain *Blockchain) ReplaceFiles(files []BlockRecordFile) (newHeight, newVersion uint64, status int) {
|
||||
var deleteIDs []uuid.UUID
|
||||
@@ -94,7 +94,7 @@ func (blockchain *Blockchain) ReplaceFiles(files []BlockRecordFile) (newHeight,
|
||||
deleteIDs = append(deleteIDs, files[n].ID)
|
||||
}
|
||||
|
||||
if newHeight, newVersion, _, status = blockchain.DeleteFiles(deleteIDs); status != BlockchainStatusOK {
|
||||
if newHeight, newVersion, _, status = blockchain.DeleteFiles(deleteIDs); status != StatusOK {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user