MCPcopy Create free account
hub / github.com/NextDotID/proof_server / proofUpload

Function proofUpload

controller/proof_upload.go:35–71  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

33}
34
35func proofUpload(c *gin.Context) {
36 req := ProofUploadRequest{}
37 err := c.BindJSON(&req)
38 if err != nil {
39 errorResp(c, 400, xerrors.Errorf("parse request failed: %w", err))
40 return
41 }
42 pubkey, err := mycrypto.StringToPubkey(req.PublicKey)
43 if err != nil {
44 errorResp(c, 400, xerrors.Errorf("%w", err))
45 return
46 }
47
48 previous_pc, err := model.ProofChainFindLatest(mycrypto.CompressedPubkeyHex(pubkey))
49 if err != nil {
50 errorResp(c, 500, xerrors.Errorf("internal database error"))
51 return
52 }
53
54 validator, err := validateProof(req, previous_pc, pubkey)
55 if err != nil {
56 errorResp(c, 400, xerrors.Errorf("%w", err))
57 return
58 }
59
60 if err = applyUpload(&validator); err != nil {
61 errorResp(c, 400, xerrors.Errorf("%w", err))
62 return
63 }
64
65 if err = triggerArweave(model.MarshalPersona(pubkey)); err != nil {
66 // Do not errorResp here, since it is a tolerable error.
67 l.Warnf("error sending arweave upload message: %v", err)
68 }
69
70 c.JSON(http.StatusCreated, gin.H{})
71}
72
73func validateProof(req ProofUploadRequest, prev *model.ProofChain, pubkey *ecdsa.PublicKey) (validator.Base, error) {
74 prev_signature := ""

Callers

nothing calls this directly

Calls 6

ProofChainFindLatestFunction · 0.92
MarshalPersonaFunction · 0.92
validateProofFunction · 0.85
applyUploadFunction · 0.85
triggerArweaveFunction · 0.85
errorRespFunction · 0.70

Tested by

no test coverage detected