From 4d8d5aa8c0efb4a94e0295199bb47e6324928c6d Mon Sep 17 00:00:00 2001 From: Ares <75481906+ice-ares@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:16:17 +0200 Subject: [PATCH] added skip option to the reset kyc webhook --- go.mod | 5 ++--- go.sum | 8 ++++---- tokenomics/kyc.go | 26 +++++++++++++++++--------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index f77180b..f0931ee 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( ) require ( - cloud.google.com/go v0.110.10 // indirect + cloud.google.com/go v0.111.0 // indirect cloud.google.com/go/compute v1.23.3 // indirect cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/firestore v1.14.0 // indirect @@ -121,7 +121,7 @@ require ( github.com/quic-go/quic-go v0.40.0 // indirect github.com/refraction-networking/utls v1.5.4 // indirect github.com/rs/zerolog v1.31.0 // indirect - github.com/sagikazarmark/locafero v0.3.0 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/segmentio/asm v1.2.0 // indirect github.com/sirupsen/logrus v1.9.3 // indirect @@ -158,7 +158,6 @@ require ( golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.16.0 // indirect - golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect google.golang.org/api v0.152.0 // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/appengine/v2 v2.0.5 // indirect diff --git a/go.sum b/go.sum index d4ea897..8bbf981 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.110.10 h1:LXy9GEO+timppncPIAZoOj3l58LIU9k+kn48AN7IO3Y= -cloud.google.com/go v0.110.10/go.mod h1:v1OoFqYxiBkUrruItNM3eT4lLByNjxmJSV/xDKJNnic= +cloud.google.com/go v0.111.0 h1:YHLKNupSD1KqjDbQ3+LVdQ81h/UJbJyZG203cEfnQgM= +cloud.google.com/go v0.111.0/go.mod h1:0mibmpKP1TyOOFYQY5izo0LnT+ecvOQ0Sg3OdmMiNRU= cloud.google.com/go/compute v1.23.3 h1:6sVlXXBmbd7jNX0Ipq0trII3e4n1/MsADLK6a+aiVlk= cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI= cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= @@ -325,8 +325,8 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= -github.com/sagikazarmark/locafero v0.3.0 h1:zT7VEGWC2DTflmccN/5T1etyKvxSxpHsjb9cJvm4SvQ= -github.com/sagikazarmark/locafero v0.3.0/go.mod h1:w+v7UsPNFwzF1cHuOajOOzoq4U7v/ig1mpRjqV+Bu1U= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys= diff --git a/tokenomics/kyc.go b/tokenomics/kyc.go index f964090..159c704 100644 --- a/tokenomics/kyc.go +++ b/tokenomics/kyc.go @@ -7,6 +7,7 @@ import ( "fmt" "math/rand" "net/http" + "strconv" "strings" "sync/atomic" stdlibtime "time" @@ -100,7 +101,7 @@ func (r *repository) validateKYC(ctx context.Context, state *getCurrentMiningSes } } } - if err := r.overrideKYCStateWithEskimoKYCState(ctx, state.UserID, &state.KYCState); err != nil { + if err := r.overrideKYCStateWithEskimoKYCState(ctx, state.UserID, &state.KYCState, skipKYCSteps); err != nil { return errors.Wrapf(err, "failed to overrideKYCStateWithEskimoKYCState for %#v", state) } if state.KYCStepBlocked > 0 && r.isKYCEnabled(ctx, state.LatestDevice, users.FacialRecognitionKYCStep) { @@ -209,8 +210,8 @@ Because existing users have empty KYCState in dragonfly cuz usersTableSource mig And because we might need to reset any kyc steps for the user prior to starting to mine. So we need to call Eskimo for that, to be sure we have the valid kyc state for the user before starting to mine. */ -func (r *repository) overrideKYCStateWithEskimoKYCState(ctx context.Context, userID string, state *KYCState) error { - if resp, err := req. +func (r *repository) overrideKYCStateWithEskimoKYCState(ctx context.Context, userID string, state *KYCState, skipKYCSteps []users.KYCStep) error { + request := req. SetContext(ctx). SetRetryCount(25). SetRetryBackoffInterval(10*stdlibtime.Millisecond, 1*stdlibtime.Second). @@ -232,15 +233,22 @@ func (r *repository) overrideKYCStateWithEskimoKYCState(ctx context.Context, use SetHeader("Accept", "application/json"). SetHeader("Cache-Control", "no-cache, no-store, must-revalidate"). SetHeader("Pragma", "no-cache"). - SetHeader("Expires", "0"). - Post(fmt.Sprintf("%v/users/%v", r.cfg.KYC.TryResetKYCStepsURL, userID)); err != nil { - return errors.Wrapf(err, "failed to fetch eskimo user state for userID:%v", userID) + SetHeader("Expires", "0") + if len(skipKYCSteps) > 0 { + skipKYCStepsQParamValues := make([]string, 0, len(skipKYCSteps)) + for _, kycStep := range skipKYCSteps { + skipKYCStepsQParamValues = append(skipKYCStepsQParamValues, strconv.Itoa(int(kycStep))) + } + request = request.AddQueryParams("skipKYCSteps", skipKYCStepsQParamValues...) + } + if resp, err := request.Post(fmt.Sprintf("%v/users/%v", r.cfg.KYC.TryResetKYCStepsURL, userID)); err != nil { + return errors.Wrapf(err, "failed to fetch eskimo user state for userID:%v, skipKYCSteps:%#v", userID, skipKYCSteps) } else if statusCode := resp.GetStatusCode(); statusCode != http.StatusOK { - return errors.Errorf("[%v]failed to fetch eskimo user state for userID:%v", statusCode, userID) + return errors.Errorf("[%v]failed to fetch eskimo user state for userID:%v, skipKYCSteps:%#v", statusCode, userID, skipKYCSteps) } else if data, err2 := resp.ToBytes(); err2 != nil { - return errors.Wrapf(err2, "failed to read body of eskimo user state request for userID:%v", userID) + return errors.Wrapf(err2, "failed to read body of eskimo user state request for userID:%v, skipKYCSteps:%#v", userID, skipKYCSteps) } else { - return errors.Wrapf(json.Unmarshal(data, state), "failed to unmarshal into %#v, data: %v", state, string(data)) + return errors.Wrapf(json.Unmarshal(data, state), "failed to unmarshal into %#v, data: %v, skipKYCSteps:%#v", state, string(data), skipKYCSteps) } }