-
Notifications
You must be signed in to change notification settings - Fork 16
/
msg_server_post_file.go
47 lines (35 loc) · 1.12 KB
/
msg_server_post_file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/jackalLabs/canine-chain/x/filetree/types"
)
func (k msgServer) PostFile(goCtx context.Context, msg *types.MsgPostFile) (*types.MsgPostFileResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
parentOwnerString := MakeOwnerAddress(msg.HashParent, msg.Account)
parentFile, found := k.GetFiles(ctx, msg.HashParent, parentOwnerString)
if !found {
return nil, types.ErrParentFileNotFound
}
hasEdit, err := HasEditAccess(parentFile, msg.Creator)
if err != nil {
// Error raised when json unmarshalling has failed
return nil, err
}
if !hasEdit {
return nil, types.ErrCannotWrite
}
// Make the full path
fullMerklePath := types.AddToMerkle(msg.HashParent, msg.HashChild)
owner := MakeOwnerAddress(fullMerklePath, msg.Account)
file := types.Files{
Address: fullMerklePath,
Contents: msg.Contents,
Owner: owner,
ViewingAccess: msg.Viewers,
EditAccess: msg.Editors,
TrackingNumber: msg.TrackingNumber,
}
k.SetFiles(ctx, file)
return &types.MsgPostFileResponse{Path: fullMerklePath}, nil
}