import github.com/google/uuid
// msgServer is the server-side (blockchain node) implementation of
// a blockchain transaction handler.
type msgServer struct{
// store has access to the blockchain state, which is a key/value store
// (which will be merkelized) persisted on disk.
store *Store
}
// CreateBlogPost takes the request from the tx, and stores a new blog post
// in state.
func (s *msgServer) CreateBlogPost(req CreateBlogPostRequest) (CreateBlogPostResponse, error) {
// Create a new blog post struct using the inputs from the tx.
blogId := uuid.New()
blogPost := BlogPost{Id: blogId, Title: req.Title}
// Persist the blog post to the store.
// Set the key/value in store.
err := s.store.Set([]byte(uuid), proto.Marshal(&blogPost))
if err != nil {
return CreateBlogPostResponse{}, err
}
return CreateBlogPostResponse{Id: blogId}, nil
}
type CreateBlogPostRequest struct {
Title string
}
type CreateBlogPostResponse struct {
Id string
}
type BlogPost struct {
proto.Message
Id string
Title string
}
1a. With Price oracle
Apr 2, 2024Date: March-April 2023Auditors: Amaury (https://github.com/amaurym), Facundo (https://github.com/facundomedica)
Apr 26, 2023import github.com/google/uuid // msgServer is the server-side (blockchain node) implementation of // a blockchain transaction handler. type msgServer struct{ // store has access to the blockchain state, which is a key/value store // (which will be merkelized) persisted on disk. store *Store }
Nov 24, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up