(c *gin.Context)
| 34 | } |
| 35 | |
| 36 | func proofPayload(c *gin.Context) { |
| 37 | req := &ProofPayloadRequest{} |
| 38 | err := c.BindJSON(req) |
| 39 | if err != nil { |
| 40 | errorResp(c, http.StatusBadRequest, err) |
| 41 | return |
| 42 | } |
| 43 | if !proofPayloadCheckRequest(req) { |
| 44 | errorResp(c, http.StatusBadRequest, xerrors.New("param invalid")) |
| 45 | return |
| 46 | } |
| 47 | |
| 48 | parsed_pubkey, err := crypto.StringToPubkey(req.PublicKey) |
| 49 | if err != nil { |
| 50 | errorResp(c, http.StatusBadRequest, xerrors.New("public key not recognized")) |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | previous_pc, err := model.ProofChainFindLatest(crypto.CompressedPubkeyHex(parsed_pubkey)) |
| 55 | if err != nil { |
| 56 | errorResp(c, http.StatusInternalServerError, xerrors.New("previous proof not found")) |
| 57 | return |
| 58 | } |
| 59 | |
| 60 | var previous_signature string |
| 61 | if previous_pc == nil { |
| 62 | previous_signature = "" |
| 63 | } else { |
| 64 | previous_signature = previous_pc.Signature |
| 65 | } |
| 66 | |
| 67 | v := validator.Base{ |
| 68 | Platform: req.Platform, |
| 69 | Previous: previous_signature, |
| 70 | Action: req.Action, |
| 71 | Pubkey: parsed_pubkey, |
| 72 | Identity: req.Identity, |
| 73 | Uuid: uuid.New(), |
| 74 | CreatedAt: time.Now(), |
| 75 | Extra: map[string]string{ |
| 76 | "wallet_signature": req.Extra.EthereumWalletSignature, |
| 77 | }, |
| 78 | } |
| 79 | |
| 80 | performer := validator.BaseToInterface(&v) |
| 81 | if performer == nil { |
| 82 | errorResp(c, http.StatusBadRequest, xerrors.New("unknown platform")) |
| 83 | return |
| 84 | } |
| 85 | c.JSON(http.StatusOK, ProofPayloadResponse{ |
| 86 | PostContent: performer.GeneratePostPayload(), |
| 87 | SignPayload: performer.GenerateSignPayload(), |
| 88 | CreatedAt: util.TimeToTimestampString(v.CreatedAt), |
| 89 | Uuid: v.Uuid.String(), |
| 90 | }) |
| 91 | } |
| 92 | |
| 93 | func proofPayloadCheckRequest(req *ProofPayloadRequest) bool { |
nothing calls this directly
no test coverage detected