-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5ae210
commit de13818
Showing
20 changed files
with
2,970 additions
and
145 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package config | ||
|
||
import ( | ||
"gitlab.com/distributed_lab/figure" | ||
"gitlab.com/distributed_lab/kit/kv" | ||
"gitlab.com/distributed_lab/logan/v3/errors" | ||
) | ||
|
||
type CircomConfig struct { | ||
PathToCircuits string `fig:"path_to_circuits,required"` //nolint | ||
} | ||
|
||
func (c *config) Circom() *CircomConfig { | ||
return c.circom.Do(func() interface{} { | ||
config := CircomConfig{} | ||
err := figure. | ||
Out(&config). | ||
From(kv.MustGetStringMap(c.getter, "circom")). | ||
Please() | ||
if err != nil { | ||
panic(errors.Wrap(err, "failed to figure out ethereum config")) | ||
} | ||
|
||
return &config | ||
}).(*CircomConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"gitlab.com/distributed_lab/ape" | ||
"gitlab.com/distributed_lab/ape/problems" | ||
|
||
"github.com/black-pepper-team/community-indexer/internal/service/api/requests" | ||
"github.com/black-pepper-team/community-indexer/internal/service/api/responses" | ||
) | ||
|
||
func RegisterInCommunity(w http.ResponseWriter, r *http.Request) { | ||
if MockAPI(r) { | ||
ape.Render(w, responses.MockedCreateCommunity()) | ||
return | ||
} | ||
|
||
req, err := requests.NewRegisterInCommunity(r) | ||
if err != nil { | ||
Log(r).WithField("reason", err).Debug("Bad request") | ||
ape.RenderErr(w, problems.BadRequest(err)...) | ||
return | ||
} | ||
|
||
registerRequest, err := Core(r).RegisterInCommunity( | ||
req.BJJPublicKey, | ||
req.NFTOwner, | ||
req.ContractId, | ||
req.NFTID, | ||
) | ||
if err != nil { | ||
Log(r).WithError(err). | ||
Error("Failed register in community") | ||
ape.RenderErr(w, problems.InternalError()) | ||
return | ||
} | ||
|
||
ape.Render(w, responses.NewRegisterInCommunity(registerRequest)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package requests | ||
|
||
import ( | ||
"encoding/json" | ||
"math/big" | ||
"net/http" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
validation "github.com/go-ozzo/ozzo-validation/v4" | ||
"github.com/iden3/go-iden3-crypto/babyjub" | ||
"gitlab.com/distributed_lab/logan/v3/errors" | ||
) | ||
|
||
type registerInCommunityRequest struct { | ||
NFTID big.Int `json:"nft_id"` | ||
NFTOwner string `json:"nft_owner"` | ||
ContractId string `json:"contract_id"` | ||
BJJPublicKey string `json:"bjj_public_key"` | ||
} | ||
|
||
type RegisterInCommunityRequest struct { | ||
NFTID big.Int | ||
NFTOwner common.Address | ||
ContractId common.Address | ||
BJJPublicKey babyjub.PublicKey | ||
} | ||
|
||
func NewRegisterInCommunity(r *http.Request) (*RegisterInCommunityRequest, error) { | ||
var requestBody registerInCommunityRequest | ||
|
||
if err := json.NewDecoder(r.Body).Decode(&requestBody); err != nil { | ||
return nil, errors.Wrap(err, "failed to decode json request body") | ||
} | ||
|
||
if err := requestBody.validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
return requestBody.parse(), nil | ||
} | ||
|
||
// nolint | ||
func (r *registerInCommunityRequest) validate() error { | ||
return validation.Errors{ | ||
"body/nft_owner": validation.Validate( | ||
r.NFTOwner, validation.Required, validation.By(MustBeValidAddress), | ||
), | ||
"body/contract_id": validation.Validate( | ||
r.ContractId, validation.Required, validation.By(MustBeValidAddress), | ||
), | ||
"body/bjj_public_key": validation.Validate( | ||
r.BJJPublicKey, validation.Required, validation.By(MustBeValidBJJPublicKey), | ||
), | ||
}.Filter() | ||
} | ||
|
||
func (r *registerInCommunityRequest) parse() *RegisterInCommunityRequest { | ||
var bjjPublicKey babyjub.PublicKey | ||
(&bjjPublicKey).UnmarshalText([]byte(r.BJJPublicKey)) | ||
|
||
return &RegisterInCommunityRequest{ | ||
NFTID: r.NFTID, | ||
NFTOwner: common.HexToAddress(r.NFTOwner), | ||
ContractId: common.HexToAddress(r.ContractId), | ||
BJJPublicKey: bjjPublicKey, | ||
} | ||
} | ||
|
||
func MustBeValidBJJPublicKey(value interface{}) error { | ||
valueStr, ok := value.(string) | ||
if !ok { | ||
return errors.New("invalid BJJ public key") | ||
} | ||
|
||
if err := new(babyjub.PublicKey).UnmarshalText([]byte(valueStr)); err != nil { | ||
return errors.Wrap(err, "invalid BJJ public key") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package responses | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
|
||
"github.com/black-pepper-team/community-indexer/internal/service/core" | ||
) | ||
|
||
type RegisterRequest struct { | ||
Id uuid.UUID `json:"id"` | ||
Status string `json:"status"` | ||
} | ||
|
||
func NewRegisterInCommunity(registerRequest *core.RegisterRequest) *RegisterRequest { | ||
return &RegisterRequest{ | ||
Id: registerRequest.Id, | ||
Status: string(registerRequest.Status), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.