Exposed certain variables in the struct public for the Test framework. (#101)

* Exposed peer seed as a public struct

* Made certain variables public in the struct WebAPIInstance
This commit is contained in:
Akilan Selvacoumar
2023-02-11 21:57:41 +00:00
committed by GitHub
parent 6989ef4a19
commit 3537d04c4d
24 changed files with 167 additions and 149 deletions

View File

@@ -130,7 +130,8 @@ In case the function aborts, the blockchain remains unchanged.
Request: POST /blockchain/file/add with JSON structure apiBlockAddFiles
Response: 200 with JSON structure apiBlockchainBlockStatus
400 if invalid input
400 if invalid input
*/
func (api *WebapiInstance) apiBlockchainFileAdd(w http.ResponseWriter, r *http.Request) {
var input apiBlockAddFiles
@@ -154,8 +155,8 @@ func (api *WebapiInstance) apiBlockchainFileAdd(w http.ResponseWriter, r *http.R
if _, err := warehouse.ValidateHash(file.Hash); err != nil {
http.Error(w, "", http.StatusBadRequest)
return
} else if _, fileSize, status, _ := api.backend.UserWarehouse.FileExists(file.Hash); status != warehouse.StatusOK {
EncodeJSON(api.backend, w, r, apiBlockchainBlockStatus{Status: blockchain.StatusNotInWarehouse})
} else if _, fileSize, status, _ := api.Backend.UserWarehouse.FileExists(file.Hash); status != warehouse.StatusOK {
EncodeJSON(api.Backend, w, r, apiBlockchainBlockStatus{Status: blockchain.StatusNotInWarehouse})
return
} else {
file.Size = fileSize
@@ -168,17 +169,17 @@ func (api *WebapiInstance) apiBlockchainFileAdd(w http.ResponseWriter, r *http.R
blockRecord := blockRecordFileFromAPI(file)
// Set the merkle tree info as appropriate.
if !setFileMerkleInfo(api.backend, &blockRecord) {
EncodeJSON(api.backend, w, r, apiBlockchainBlockStatus{Status: blockchain.StatusNotInWarehouse})
if !setFileMerkleInfo(api.Backend, &blockRecord) {
EncodeJSON(api.Backend, w, r, apiBlockchainBlockStatus{Status: blockchain.StatusNotInWarehouse})
return
}
filesAdd = append(filesAdd, blockRecord)
}
newHeight, newVersion, status := api.backend.UserBlockchain.AddFiles(filesAdd)
newHeight, newVersion, status := api.Backend.UserBlockchain.AddFiles(filesAdd)
EncodeJSON(api.backend, w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
EncodeJSON(api.Backend, w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
}
/*
@@ -188,7 +189,7 @@ Request: GET /blockchain/file/list
Response: 200 with JSON structure apiBlockAddFiles
*/
func (api *WebapiInstance) apiBlockchainFileList(w http.ResponseWriter, r *http.Request) {
files, status := api.backend.UserBlockchain.ListFiles()
files, status := api.Backend.UserBlockchain.ListFiles()
var result apiBlockAddFiles
@@ -198,7 +199,7 @@ func (api *WebapiInstance) apiBlockchainFileList(w http.ResponseWriter, r *http.
result.Status = status
EncodeJSON(api.backend, w, r, result)
EncodeJSON(api.Backend, w, r, result)
}
/*
@@ -220,18 +221,18 @@ func (api *WebapiInstance) apiBlockchainFileDelete(w http.ResponseWriter, r *htt
deleteIDs = append(deleteIDs, input.Files[n].ID)
}
newHeight, newVersion, deletedFiles, status := api.backend.UserBlockchain.DeleteFiles(deleteIDs)
newHeight, newVersion, deletedFiles, status := api.Backend.UserBlockchain.DeleteFiles(deleteIDs)
// If successfully deleted from the blockchain, delete from the Warehouse in case there are no other references.
if status == blockchain.StatusOK {
for n := range deletedFiles {
if files, status := api.backend.UserBlockchain.FileExists(deletedFiles[n].Hash); status == blockchain.StatusOK && len(files) == 0 {
api.backend.UserWarehouse.DeleteFile(deletedFiles[n].Hash)
if files, status := api.Backend.UserBlockchain.FileExists(deletedFiles[n].Hash); status == blockchain.StatusOK && len(files) == 0 {
api.Backend.UserWarehouse.DeleteFile(deletedFiles[n].Hash)
}
}
}
EncodeJSON(api.backend, w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
EncodeJSON(api.Backend, w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
}
/*
@@ -239,7 +240,8 @@ apiBlockchainSelfUpdateFile updates files that are already published on the bloc
Request: POST /blockchain/file/update with JSON structure apiBlockAddFiles
Response: 200 with JSON structure apiBlockchainBlockStatus
400 if invalid input
400 if invalid input
*/
func (api *WebapiInstance) apiBlockchainFileUpdate(w http.ResponseWriter, r *http.Request) {
var input apiBlockAddFiles
@@ -263,8 +265,8 @@ func (api *WebapiInstance) apiBlockchainFileUpdate(w http.ResponseWriter, r *htt
if _, err := warehouse.ValidateHash(file.Hash); err != nil {
http.Error(w, "", http.StatusBadRequest)
return
} else if _, fileSize, status, _ := api.backend.UserWarehouse.FileExists(file.Hash); status != warehouse.StatusOK {
EncodeJSON(api.backend, w, r, apiBlockchainBlockStatus{Status: blockchain.StatusNotInWarehouse})
} else if _, fileSize, status, _ := api.Backend.UserWarehouse.FileExists(file.Hash); status != warehouse.StatusOK {
EncodeJSON(api.Backend, w, r, apiBlockchainBlockStatus{Status: blockchain.StatusNotInWarehouse})
return
} else {
file.Size = fileSize
@@ -277,17 +279,17 @@ func (api *WebapiInstance) apiBlockchainFileUpdate(w http.ResponseWriter, r *htt
blockRecord := blockRecordFileFromAPI(file)
// Set the merkle tree info as appropriate.
if !setFileMerkleInfo(api.backend, &blockRecord) {
EncodeJSON(api.backend, w, r, apiBlockchainBlockStatus{Status: blockchain.StatusNotInWarehouse})
if !setFileMerkleInfo(api.Backend, &blockRecord) {
EncodeJSON(api.Backend, w, r, apiBlockchainBlockStatus{Status: blockchain.StatusNotInWarehouse})
return
}
filesAdd = append(filesAdd, blockRecord)
}
newHeight, newVersion, status := api.backend.UserBlockchain.ReplaceFiles(filesAdd)
newHeight, newVersion, status := api.Backend.UserBlockchain.ReplaceFiles(filesAdd)
EncodeJSON(api.backend, w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
EncodeJSON(api.Backend, w, r, apiBlockchainBlockStatus{Status: status, Height: newHeight, Version: newVersion})
}
// ---- metadata functions ----