Skip to content
Snippets Groups Projects
Select Git revision
  • fedfad7429621bd588c753346b6a1732ac185ece
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

node.go

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"`
    }