Skip to content
Snippets Groups Projects
Select Git revision
  • 5ba8b5741146591bcdbe9567bea77ebeaee42f7b
  • develop default protected
  • congestioncontrol
  • merge-v-data-collection-spammer-0.8.2
  • WIP-merge-v-data-collection-spammer-0.8.2
  • merge-v-data-collection-spammer-0.7.7
  • tmp
  • test-masterpow-fixing
  • test-masterpow
  • test-echo
  • v-data-collection
  • v-data-collection-spammer
  • tmp-dump-spam-info
  • dump-msg-info-0.3.1
  • test-dump-message-info
  • spammer-exprandom
  • extra/tutorial
  • without_tipselection
  • hacking-docker-network
  • hacking-docker-network-0.2.3
  • master
  • v0.2.3
22 results

Dockerfile

Blame
  • sendPayload.go 1.14 KiB
    package message
    
    import (
    	"net/http"
    
    	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/payload"
    	"github.com/iotaledger/goshimmer/plugins/issuer"
    	"github.com/labstack/echo"
    )
    
    // sendPayload creates a message of the given payload and
    // broadcasts it to the node's neighbors. It returns the message ID if successful.
    func sendPayload(c echo.Context) error {
    	var request MsgRequest
    	if err := c.Bind(&request); err != nil {
    		log.Info(err.Error())
    		return c.JSON(http.StatusBadRequest, MsgResponse{Error: err.Error()})
    	}
    
    	parsedPayload, _, err := payload.FromBytes(request.Payload)
    	if err != nil {
    		return c.JSON(http.StatusBadRequest, MsgResponse{Error: err.Error()})
    	}
    
    	msg, err := issuer.IssuePayload(parsedPayload)
    	if err != nil {
    		return c.JSON(http.StatusBadRequest, MsgResponse{Error: err.Error()})
    	}
    
    	return c.JSON(http.StatusOK, MsgResponse{ID: msg.Id().String()})
    }
    
    // MsgResponse contains the ID of the message sent.
    type MsgResponse struct {
    	ID    string `json:"id,omitempty"`
    	Error string `json:"error,omitempty"`
    }
    
    // MsgRequest contains the message to send.
    type MsgRequest struct {
    	Payload []byte `json:"payload"`
    }