From 20aee2c1a90a78a07e984f53a2484cacade30a76 Mon Sep 17 00:00:00 2001 From: erwin-willems Date: Thu, 8 Feb 2024 10:02:35 +0100 Subject: [PATCH 1/6] Fix empty verification map on error --- routes/shared.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/routes/shared.go b/routes/shared.go index c050007c..8490900a 100644 --- a/routes/shared.go +++ b/routes/shared.go @@ -259,18 +259,8 @@ func (fes *APIServer) GetVerifiedUsernameToPKIDMapFromGlobalState() (_verificati return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: Cannot Decode Verification Map: %v", err) } } else { - // Create the inital map structure + // Return an empty map structure verifiedMapStruct.VerifiedUsernameToPKID = make(map[string]*lib.PKID) - - // Encode the map and stick it in the database. - metadataDataBuf := bytes.NewBuffer([]byte{}) - if err = gob.NewEncoder(metadataDataBuf).Encode(verifiedMapStruct); err != nil { - return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: cannot encode verifiedMap struct: %v", err) - } - err = fes.GlobalState.Put(_GlobalStatePrefixForVerifiedMap, metadataDataBuf.Bytes()) - if err != nil { - return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: Cannot Decode Verification Map: %v", err) - } } // Return the verificationMap return verifiedMapStruct.VerifiedUsernameToPKID, nil From 9516b64c177cb3081117637b2a8bba9aaf4ae3ab Mon Sep 17 00:00:00 2001 From: erwin-willems Date: Thu, 8 Feb 2024 10:27:26 +0100 Subject: [PATCH 2/6] Switch for price monitoring --- config/config.go | 6 ++++++ routes/server.go | 15 +++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index 81b9b47a..45b5266a 100644 --- a/config/config.go +++ b/config/config.go @@ -61,6 +61,9 @@ type Config struct { InfuraProjectID string EtherscanAPIKey string + // Exchange price monitoring + RunExchangePriceMonitoring bool + // Emails SendgridApiKey string SendgridDomain string @@ -168,6 +171,9 @@ func LoadConfig(coreConfig *coreCmd.Config) *Config { // Etherscan API Key config.EtherscanAPIKey = viper.GetString("etherscan-api-key") + // Exchange price monitoring + config.RunExchangePriceMonitoring = viper.GetBool("run-exchange-price-monitoring") + // Seed from which DeSo will be sent for orders placed through Wyre and "Buy With BTC" purchases config.BuyDESOSeed = viper.GetString("buy-deso-seed") diff --git a/routes/server.go b/routes/server.go index 8c16761a..7ebc001f 100644 --- a/routes/server.go +++ b/routes/server.go @@ -526,18 +526,21 @@ func NewAPIServer( fes.StartSeedBalancesMonitoring() - // Call this once upon starting server to ensure we have a good initial value - fes.UpdateUSDCentsToDeSoExchangeRate() - fes.UpdateUSDToBTCPrice() - fes.UpdateUSDToETHPrice() // Get the transaction fee map from global state if it exists fes.TransactionFeeMap = fes.GetTransactionFeeMapFromGlobalState() fes.ExemptPublicKeyMap = fes.GetExemptPublicKeyMapFromGlobalState() - // Then monitor them - fes.StartExchangePriceMonitoring() + if fes.Config.RunExchangePriceMonitoring { + // Call this once upon starting server to ensure we have a good initial value + fes.UpdateUSDCentsToDeSoExchangeRate() + fes.UpdateUSDToBTCPrice() + fes.UpdateUSDToETHPrice() + + // Then monitor them + fes.StartExchangePriceMonitoring() + } if fes.Config.RunHotFeedRoutine { fes.StartHotFeedRoutine() From edfdae208c89c3dcd03d25aeca372f1571f11079 Mon Sep 17 00:00:00 2001 From: "erwin.willems" Date: Tue, 12 Mar 2024 17:20:42 +0100 Subject: [PATCH 3/6] Import fix from core team --- routes/shared.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/routes/shared.go b/routes/shared.go index 8490900a..c050007c 100644 --- a/routes/shared.go +++ b/routes/shared.go @@ -259,8 +259,18 @@ func (fes *APIServer) GetVerifiedUsernameToPKIDMapFromGlobalState() (_verificati return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: Cannot Decode Verification Map: %v", err) } } else { - // Return an empty map structure + // Create the inital map structure verifiedMapStruct.VerifiedUsernameToPKID = make(map[string]*lib.PKID) + + // Encode the map and stick it in the database. + metadataDataBuf := bytes.NewBuffer([]byte{}) + if err = gob.NewEncoder(metadataDataBuf).Encode(verifiedMapStruct); err != nil { + return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: cannot encode verifiedMap struct: %v", err) + } + err = fes.GlobalState.Put(_GlobalStatePrefixForVerifiedMap, metadataDataBuf.Bytes()) + if err != nil { + return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: Cannot Decode Verification Map: %v", err) + } } // Return the verificationMap return verifiedMapStruct.VerifiedUsernameToPKID, nil From f50c000fc534091737a21841e758441159bf4fa3 Mon Sep 17 00:00:00 2001 From: "erwin.willems" Date: Thu, 7 Mar 2024 12:19:26 +0100 Subject: [PATCH 4/6] Add postentryreaderstate to getpostshashhexlist --- routes/post.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routes/post.go b/routes/post.go index 4011b435..9b881fb3 100644 --- a/routes/post.go +++ b/routes/post.go @@ -1176,6 +1176,8 @@ func (fes *APIServer) GetPostsHashHexList(ww http.ResponseWriter, req *http.Requ postEntryResponses = append(postEntryResponses, postEntryResponse) + postEntryResponse.PostEntryReaderState = utxoView.GetPostEntryReaderState(readerPublicKeyBytes, postEntry) + } if requestData.OrderBy == "newest" { From 3a791209b4723061f0b2e1e74881d7f8f9445201 Mon Sep 17 00:00:00 2001 From: "erwin.willems" Date: Wed, 24 Apr 2024 16:36:14 +0200 Subject: [PATCH 5/6] Add a temporary error so we can monitor if globalstate will be empty in the future --- routes/shared.go | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/shared.go b/routes/shared.go index c050007c..f3511cc9 100644 --- a/routes/shared.go +++ b/routes/shared.go @@ -260,6 +260,7 @@ func (fes *APIServer) GetVerifiedUsernameToPKIDMapFromGlobalState() (_verificati } } else { // Create the inital map structure + glog.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: VerifiedMap is empty, creating a new one") verifiedMapStruct.VerifiedUsernameToPKID = make(map[string]*lib.PKID) // Encode the map and stick it in the database. From 2118216b3aabc47aaca611d427f7485f6bfc9387 Mon Sep 17 00:00:00 2001 From: "erwin.willems" Date: Tue, 30 Apr 2024 08:33:07 +0200 Subject: [PATCH 6/6] Disable write empty verifiedusername map --- routes/shared.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/routes/shared.go b/routes/shared.go index f3511cc9..3cd409bc 100644 --- a/routes/shared.go +++ b/routes/shared.go @@ -260,18 +260,18 @@ func (fes *APIServer) GetVerifiedUsernameToPKIDMapFromGlobalState() (_verificati } } else { // Create the inital map structure - glog.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: VerifiedMap is empty, creating a new one") verifiedMapStruct.VerifiedUsernameToPKID = make(map[string]*lib.PKID) // Encode the map and stick it in the database. - metadataDataBuf := bytes.NewBuffer([]byte{}) - if err = gob.NewEncoder(metadataDataBuf).Encode(verifiedMapStruct); err != nil { - return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: cannot encode verifiedMap struct: %v", err) - } - err = fes.GlobalState.Put(_GlobalStatePrefixForVerifiedMap, metadataDataBuf.Bytes()) - if err != nil { - return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: Cannot Decode Verification Map: %v", err) - } + // TODO: Disabled code below because it was causing a blank verifiedusername map. We should investigate why. + // metadataDataBuf := bytes.NewBuffer([]byte{}) + // if err = gob.NewEncoder(metadataDataBuf).Encode(verifiedMapStruct); err != nil { + // return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: cannot encode verifiedMap struct: %v", err) + // } + // err = fes.GlobalState.Put(_GlobalStatePrefixForVerifiedMap, metadataDataBuf.Bytes()) + // if err != nil { + // return nil, fmt.Errorf("GetVerifiedUsernameToPKIDMapFromGlobalState: Cannot Decode Verification Map: %v", err) + // } } // Return the verificationMap return verifiedMapStruct.VerifiedUsernameToPKID, nil