Skip to content

Commit

Permalink
fix: video indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
WaDadidou committed Oct 14, 2023
1 parent 74d90e9 commit 2ac91df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions go/internal/indexerhandler/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@ type ExecCreateVideoMsg struct {
CreateVideo CreateVideoMsg `json:"create_video"`
}
type CreateVideoMsg struct {
Metadata string `json:"metadata"`
Metadata string `json:"metadata"`
}

func (h *Handler) handleExecuteCreateVideo(e *Message, execMsg *wasmtypes.MsgExecuteContract) error {
var execCreateVideoMsg ExecCreateVideoMsg
if err := json.Unmarshal(execMsg.Msg, &execCreateVideoMsg); err != nil {
return errors.Wrap(err, "failed to unmarshal execute create video msg")
}

videoIdentifiers := e.Events["wasm.video_identifier"]
if len(videoIdentifiers) == 0 {
return errors.New("no video identifier")
}
identifier := videoIdentifiers[0]

createVideo := &execCreateVideoMsg.CreateVideo

var metadataJSON map[string]interface{}
if err := json.Unmarshal([]byte(createVideo.Metadata), &metadataJSON); err != nil {
return errors.Wrap(err, "failed to unmarshal metadata")
return nil
}

Expand All @@ -34,6 +40,7 @@ func (h *Handler) handleExecuteCreateVideo(e *Message, execMsg *wasmtypes.MsgExe
}

video := indexerdb.Video{
Identifier: identifier,
Metadata: metadataJSON,
CreatedBy: h.config.Network.UserID(execMsg.Sender),
CreatedAt: createdAt.Unix(),
Expand All @@ -60,6 +67,13 @@ func (h *Handler) handleExecuteCreateComment(e *Message, execMsg *wasmtypes.MsgE
if err := json.Unmarshal(execMsg.Msg, &execCreateCommentMsg); err != nil {
return errors.Wrap(err, "failed to unmarshal execute create comment msg")
}

commentIdentifiers := e.Events["wasm.comment_identifier"]
if len(commentIdentifiers) == 0 {
return errors.New("no comment identifier")
}
identifier := commentIdentifiers[0]

createComment := &execCreateCommentMsg.CreateComment

createdAt, err := e.GetBlockTime()
Expand All @@ -68,6 +82,7 @@ func (h *Handler) handleExecuteCreateComment(e *Message, execMsg *wasmtypes.MsgE
}

comment := indexerdb.VideoComment{
Identifier: identifier,
VideoIdentifier: createComment.VideoIdentifier,
Comment: createComment.Comment,
CreatedBy: h.config.Network.UserID(execMsg.Sender),
Expand Down
2 changes: 1 addition & 1 deletion packages/networks/teritori-testnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ export const teritoriTestnetNetwork: NetworkInfo = {
coreDAOAddress:
"tori1dy5h9q9zue4swxe9mzracm8gudp0fcf2ncllch6pfq9d0fq0ftgq546063",
videoContractAddress:
"tori1m95r73qkq9amntsmr33uz549jdc8284pl0xfqd7mp46c5y8s6ljq7z4q7z",
"tori1naqea7t2lyvepa79ewudp689g4nfx4mua8qvtn8pzv70753sslmsn7m26e",
};

0 comments on commit 2ac91df

Please sign in to comment.