Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,274 changes: 725 additions & 549 deletions code/go/0chain.net/blobbercore/blobbergrpc/blobber.pb.go

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions code/go/0chain.net/blobbercore/blobbergrpc/blobber.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions code/go/0chain.net/blobbercore/blobbergrpc/blobber_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 24 additions & 5 deletions code/go/0chain.net/blobbercore/blobbergrpc/proto/blobber.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ service Blobber {
}

rpc CalculateHash(CalculateHashRequest) returns (CalculateHashResponse) {
option (google.api.http) = {
post: "/v2/file/calculatehash/{allocation}"
body: "*"
};
}
option (google.api.http) = {
post: "/v2/file/calculatehash/{allocation}"
body: "*"
};
}

rpc CommitMetaTxn(CommitMetaTxnRequest) returns (CommitMetaTxnResponse) {
option (google.api.http) = {
post: "/v2/file/commitmetatxn/{allocation}"
body: "*"
};
}
}

message CalculateHashRequest {
Expand All @@ -82,6 +89,18 @@ message CommitResponse {
bool success = 4;
}

message CommitMetaTxnRequest {
string path = 1;
string path_hash = 2;
string auth_token = 3;
string allocation = 4;
string txn_id = 5;
}

message CommitMetaTxnResponse {
string message = 1;
}

message GetObjectTreeRequest {
string path = 1;
string allocation = 2;
Expand Down
15 changes: 15 additions & 0 deletions code/go/0chain.net/blobbercore/convert/responseHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,18 @@ func GetCalculateHashResponseHandler(response *blobbergrpc.CalculateHashResponse

return result
}

func GetCommitMetaTxnHandlerResponse(response *blobbergrpc.CommitMetaTxnResponse) interface{} {
msg := response.GetMessage()
if msg == "" {
return nil
}

result := struct {
Msg string `json:"msg"`
}{
Msg: msg,
}

return result
}
59 changes: 59 additions & 0 deletions code/go/0chain.net/blobbercore/handler/grpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,62 @@ func (b *blobberGRPCService) CalculateHash(ctx context.Context, req *blobbergrpc

return &blobbergrpc.CalculateHashResponse{Message: "Hash recalculated for the given paths"}, nil
}

func (b *blobberGRPCService) CommitMetaTxn(ctx context.Context, req *blobbergrpc.CommitMetaTxnRequest) (*blobbergrpc.CommitMetaTxnResponse, error) {
allocationTx := req.GetAllocation()
allocationObj, err := b.storageHandler.verifyAllocation(ctx, allocationTx, true)
if err != nil {
return nil, common.NewError("invalid_parameters", "Invalid allocation id passed."+err.Error())
}
allocationID := allocationObj.ID

md := GetGRPCMetaDataFromCtx(ctx)
clientID := md.Client
if len(clientID) == 0 {
return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation")
}

pathHash := req.PathHash
path := req.Path
if len(pathHash) == 0 {
if len(path) == 0 {
return nil, common.NewError("invalid_parameters", "Invalid path")
}
pathHash = reference.GetReferenceLookup(allocationID, path)
}

fileRef, err := b.packageHandler.GetReferenceFromLookupHash(ctx, allocationID, pathHash)
if err != nil {
return nil, common.NewError("invalid_parameters", "Invalid file path. "+err.Error())
}

if fileRef.Type != reference.FILE {
return nil, common.NewError("invalid_parameters", "Path is not a file.")
}

auhToken := req.GetAuthToken()

if clientID != allocationObj.OwnerID || len(auhToken) > 0 {
authTicketVerified, err := b.storageHandler.verifyAuthTicket(ctx, auhToken, allocationObj, fileRef, clientID)
if err != nil {
return nil, err
}

if !authTicketVerified {
return nil, common.NewError("auth_ticket_verification_failed", "Could not verify the auth ticket.")
}
}

txnID := req.GetTxnId()
if len(txnID) == 0 {
return nil, common.NewError("invalid_parameter", "TxnID not present in the params")
}

if err := b.packageHandler.AddCommitMetaTxn(ctx, fileRef.ID, txnID); err != nil {
return nil, common.NewError("add_commit_meta_txn_failed", "Failed to add commitMetaTxn with err :"+err.Error())
}

return &blobbergrpc.CommitMetaTxnResponse{
Message: "Added commitMetaTxn successfully",
}, nil
}
Loading