Housekeeping! Removing unnecessary "blockchain" prefix of status codes within the blockchain package.

This commit is contained in:
Kleissner
2021-10-13 21:22:17 +02:00
parent b556acb86c
commit 1c0406dc60
7 changed files with 71 additions and 74 deletions

View File

@@ -149,7 +149,7 @@ func apiBlockchainSelfAddFile(w http.ResponseWriter, r *http.Request) {
http.Error(w, "", http.StatusBadRequest)
return
} else if _, _, valid := core.UserWarehouse.FileExists(hashA); !valid {
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: blockchain.BlockchainStatusNotInWarehouse})
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: blockchain.StatusNotInWarehouse})
return
}
}
@@ -204,9 +204,9 @@ func apiBlockchainSelfDeleteFile(w http.ResponseWriter, r *http.Request) {
newHeight, newVersion, deletedFiles, status := core.UserBlockchain.DeleteFiles(deleteIDs)
// If successfully deleted from the blockchain, delete from the Warehouse in case there are no other references.
if status == blockchain.BlockchainStatusOK {
if status == blockchain.StatusOK {
for n := range deletedFiles {
if files, status := core.UserBlockchain.FileExists(deletedFiles[n].Hash); status == blockchain.BlockchainStatusOK && len(files) == 0 {
if files, status := core.UserBlockchain.FileExists(deletedFiles[n].Hash); status == blockchain.StatusOK && len(files) == 0 {
core.UserWarehouse.DeleteFile(deletedFiles[n].Hash)
}
}
@@ -237,7 +237,7 @@ func apiBlockchainFileUpdate(w http.ResponseWriter, r *http.Request) {
http.Error(w, "", http.StatusBadRequest)
return
} else if _, _, valid := core.UserWarehouse.FileExists(hashA); !valid {
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: blockchain.BlockchainStatusNotInWarehouse})
EncodeJSON(w, r, apiBlockchainBlockStatus{Status: blockchain.StatusNotInWarehouse})
return
}
}

View File

@@ -17,7 +17,7 @@ import (
// apiProfileData contains profile metadata stored on the blockchain. Any data is treated as untrusted and unverified by default.
type apiProfileData struct {
Fields []apiBlockRecordProfile `json:"fields"` // All fields
Status int `json:"status"` // Status of the operation, only used when this structure is returned from the API. See core.BlockchainStatusX.
Status int `json:"status"` // Status of the operation, only used when this structure is returned from the API. See blockchain.StatusX.
}
// apiBlockRecordProfile provides information about the end user. Note that all profile data is arbitrary and shall be considered untrusted and unverified.
@@ -64,7 +64,7 @@ func apiProfileRead(w http.ResponseWriter, r *http.Request) {
var result apiProfileData
var data []byte
if data, result.Status = core.UserBlockchain.ProfileReadField(uint16(fieldN)); result.Status == blockchain.BlockchainStatusOK {
if data, result.Status = core.UserBlockchain.ProfileReadField(uint16(fieldN)); result.Status == blockchain.StatusOK {
result.Fields = append(result.Fields, blockRecordProfileToAPI(blockchain.BlockRecordProfile{Type: uint16(fieldN), Data: data}))
}

View File

@@ -107,18 +107,16 @@ type apiResponsePeerSelf struct {
## Blockchain Functions
Common status codes returned by various endpoints:
Common status codes returned by various endpoints in the `blockchain` package:
```go
const (
BlockchainStatusOK = 0 // No problems in the blockchain detected.
BlockchainStatusBlockNotFound = 1 // Missing block in the blockchain.
BlockchainStatusCorruptBlock = 2 // Error block encoding
BlockchainStatusCorruptBlockRecord = 3 // Error block record encoding
BlockchainStatusDataNotFound = 4 // Requested data not available in the blockchain
BlockchainStatusNotInWarehouse = 5 // File to be added to blockchain does not exist in the Warehouse
)
```
| Status | Constant | Info |
|------|----------------|-------------------------------|
| 0 | StatusOK | Successful operation. |
| 1 | StatusBlockNotFound | Missing block in the blockchain. |
| 2 | StatusCorruptBlock | Error block encoding. |
| 3 | StatusCorruptBlockRecord | Error block record encoding. |
| 4 | StatusDataNotFound | Requested data not available in the blockchain. |
| 5 | StatusNotInWarehouse | File to be added to blockchain does not exist in the Warehouse. |
### Blockchain Self Header
@@ -158,7 +156,7 @@ type apiBlockchainBlockRaw struct {
}
type apiBlockchainBlockStatus struct {
Status int `json:"status"` // Status: 0 = Success, 1 = Error invalid data
Status int `json:"status"` // See blockchain.StatusX.
Height uint64 `json:"height"` // Height of the blockchain (number of blocks).
Version uint64 `json:"version"` // Version of the blockchain.
}
@@ -175,7 +173,7 @@ Response: 200 with JSON structure apiBlockchainBlock
```go
type apiBlockchainBlock struct {
Status int `json:"status"` // Status: 0 = Success, 1 = Error block not found, 2 = Error block encoding (indicates that the blockchain is corrupt)
Status int `json:"status"` // See blockchain.StatusX.
PeerID string `json:"peerid"` // Peer ID hex encoded.
LastBlockHash []byte `json:"lastblockhash"` // Hash of the last block. Blake3.
BlockchainVersion uint64 `json:"blockchainversion"` // Blockchain version
@@ -417,7 +415,7 @@ Response: 200 with JSON structure apiProfileData
```go
type apiProfileData struct {
Fields []apiBlockRecordProfile `json:"fields"` // All fields
Status int `json:"status"` // Status of the operation, only used when this structure is returned from the API. See core.BlockchainStatusX.
Status int `json:"status"` // Status of the operation, only used when this structure is returned from the API. See blockchain.StatusX.
}
type apiBlockRecordProfile struct {