Skip to content

Commit

Permalink
modification of miningBlockchainAccountAddress via ModifyUser (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-cronus authored Oct 16, 2023
1 parent ebf5ab1 commit ecd80b5
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 7 deletions.
5 changes: 5 additions & 0 deletions cmd/eskimo-hut/api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,11 @@ const docTemplate = `{
"name": "lastName",
"in": "formData"
},
{
"type": "string",
"name": "miningBlockchainAccountAddress",
"in": "formData"
},
{
"type": "string",
"description": "Optional. Example:` + "`" + `+12099216581` + "`" + `.",
Expand Down
5 changes: 5 additions & 0 deletions cmd/eskimo-hut/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,11 @@
"name": "lastName",
"in": "formData"
},
{
"type": "string",
"name": "miningBlockchainAccountAddress",
"in": "formData"
},
{
"type": "string",
"description": "Optional. Example:`+12099216581`.",
Expand Down
3 changes: 3 additions & 0 deletions cmd/eskimo-hut/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,9 @@ paths:
in: formData
name: lastName
type: string
- in: formData
name: miningBlockchainAccountAddress
type: string
- description: Optional. Example:`+12099216581`.
in: formData
name: phoneNumber
Expand Down
3 changes: 2 additions & 1 deletion cmd/eskimo-hut/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ type (
// Optional. Example:`Ef86A6021afCDe5673511376B2,Ef86A6021afCDe5673511376B2,Ef86A6021afCDe5673511376B2,Ef86A6021afCDe5673511376B2`.
AgendaPhoneNumberHashes string `form:"agendaPhoneNumberHashes" formMultipart:"agendaPhoneNumberHashes"`
// Optional. Example:`some hash`.
BlockchainAccountAddress string `form:"blockchainAccountAddress" formMultipart:"blockchainAccountAddress"`
BlockchainAccountAddress string `form:"blockchainAccountAddress" formMultipart:"blockchainAccountAddress"`
MiningBlockchainAccountAddress string `form:"miningBlockchainAccountAddress" formMultipart:"miningBlockchainAccountAddress"`
// Optional. Example:`en`.
Language string `form:"language" formMultipart:"language"`
// Optional. Example:`1232412415326543647657`.
Expand Down
2 changes: 2 additions & 0 deletions cmd/eskimo-hut/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ func buildUserForModification(req *server.Request[ModifyUserRequestBody, ModifyU
usr.Email = req.Data.Email
usr.AgendaPhoneNumberHashes = &req.Data.AgendaPhoneNumberHashes
usr.BlockchainAccountAddress = req.Data.BlockchainAccountAddress
usr.MiningBlockchainAccountAddress = req.Data.MiningBlockchainAccountAddress
usr.Language = req.Data.Language
if req.Data.ClearHiddenProfileElements != nil && *req.Data.ClearHiddenProfileElements {
empty := make(users.Enum[users.HiddenProfileElement], 0, 0) //nolint:gosimple // .
Expand Down Expand Up @@ -325,6 +326,7 @@ func (a *ModifyUserRequestBody) verifyIfAtLeastOnePropertyProvided() *server.Res
a.Language == "" &&
a.AgendaPhoneNumberHashes == "" &&
a.BlockchainAccountAddress == "" &&
a.MiningBlockchainAccountAddress == "" &&
a.HiddenProfileElements == nil &&
a.ClearHiddenProfileElements == nil &&
a.ClientData == nil &&
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/MicahParks/keyfunc v1.9.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.1 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
Expand Down Expand Up @@ -82,7 +82,7 @@ require (
github.com/joho/godotenv v1.5.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/klauspost/compress v1.17.1 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Microsoft/hcsshim v0.11.1 h1:hJ3s7GbWlGK4YVV92sO88BQSyF4ZLVy7/awqOlPxFbA=
github.com/Microsoft/hcsshim v0.11.1/go.mod h1:nFJmaO4Zr5Y7eADdFOpYswDDlNVbvcIJJNJLECr5JQg=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE=
Expand Down Expand Up @@ -305,8 +305,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.17.1 h1:NE3C767s2ak2bweCZo3+rdP4U/HoyVXLv/X9f2gPS5g=
github.com/klauspost/compress v1.17.1/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
Expand Down
10 changes: 10 additions & 0 deletions users/users_modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (r *repository) ModifyUser(ctx context.Context, usr *User, profilePicture *
if oldUsr.ReferredBy != "" && oldUsr.ReferredBy != oldUsr.ID && usr.ReferredBy != "" && usr.ReferredBy != oldUsr.ReferredBy && notRandom {
return errors.Errorf("changing the referredBy a second time is not allowed")
}
if oldUsr.MiningBlockchainAccountAddress != "" && oldUsr.MiningBlockchainAccountAddress != oldUsr.ID &&
usr.MiningBlockchainAccountAddress != "" && usr.MiningBlockchainAccountAddress != oldUsr.MiningBlockchainAccountAddress {
return errors.Errorf("changing the miningBlockchainAccountAddress a second time is not allowed")
}
lu := lastUpdatedAt(ctx)
if lu != nil && oldUsr.UpdatedAt.UnixNano() != lu.UnixNano() {
return ErrRaceCondition
Expand Down Expand Up @@ -133,6 +137,7 @@ func (u *User) override(user *User) *User {
usr.PhoneNumber = mergeStringField(u.PhoneNumber, user.PhoneNumber)
usr.PhoneNumberHash = mergeStringField(u.PhoneNumberHash, user.PhoneNumberHash)
usr.BlockchainAccountAddress = mergeStringField(u.BlockchainAccountAddress, user.BlockchainAccountAddress)
usr.MiningBlockchainAccountAddress = mergeStringField(u.MiningBlockchainAccountAddress, user.MiningBlockchainAccountAddress)

return usr
}
Expand Down Expand Up @@ -237,6 +242,11 @@ func (u *User) genSQLUpdate(ctx context.Context, agendaUserIDs []UserID) (sql st
sql += fmt.Sprintf(", BLOCKCHAIN_ACCOUNT_ADDRESS = $%v", nextIndex)
nextIndex++
}
if u.MiningBlockchainAccountAddress != "" {
params = append(params, u.MiningBlockchainAccountAddress)
sql += fmt.Sprintf(", MINING_BLOCKCHAIN_ACCOUNT_ADDRESS = COALESCE(NULLIF(MINING_BLOCKCHAIN_ACCOUNT_ADDRESS,ID),$%v)", nextIndex)
nextIndex++
}
if u.KYCStepsLastUpdatedAt != nil {
kycStepsLastUpdatedAt := make([]stdlibtime.Time, 0, len(*u.KYCStepsLastUpdatedAt))
for _, updatedAt := range *u.KYCStepsLastUpdatedAt {
Expand Down

0 comments on commit ecd80b5

Please sign in to comment.