// SendPayload sends the given payload to each orderer and returns a block response
970065
func SendPayload(reqCtx reqContext.Context, payload *common.Payload, orderers []fab.Orderer) (*common.Block, error) {
	if len(orderers) == 0 {
		return nil, errors.New("orderers not set")
	}

	ctx, ok := context.RequestClientContext(reqCtx)
	if !ok {
		return nil, errors.New("failed get client context from reqContext for signPayload")
	}
	envelope, err := signPayload(ctx, payload)
	if err != nil {
		return nil, err
	}

	// Copy aside the ordering service endpoints
	randOrderers := []fab.Orderer{}
	randOrderers = append(randOrderers, orderers...)

	// Iterate them in a random order and try broadcasting 1 by 1
	var errResp error
	for _, i := range rand.Perm(len(randOrderers)) {
		resp, err := sendEnvelope(reqCtx, envelope, randOrderers[i])
		if err != nil {
			errResp = err
		} else {
			return resp, nil
		}
	}
	return nil, errResp
}
643620
func (o *GetEndpointOK) WithPayload(payload []*models.Endpoint) *GetEndpointOK {
	o.Payload = payload
	return o
}
1189090
func (o *AddOrderDefault) WithPayload(payload *models.Error) *AddOrderDefault {
	o.Payload = payload
	return o
}
328731
func (o *GetLoginOK) WithPayload(payload *GetLoginOKBody) *GetLoginOK {
	o.Payload = payload
	return o
}
1023869
func GetPayload(e *common.Envelope) (*common.Payload, error) {
	payload := &common.Payload{}
	err := proto.Unmarshal(e.Payload, payload)
	return payload, errors.Wrap(err, "error unmarshaling Payload")
}
188458
func (o *GetEndpointIDOK) WithPayload(payload *models.Endpoint) *GetEndpointIDOK {
	o.Payload = payload
	return o
}
306206
func (s *RecordsEvent) SetPayload(v []byte) *RecordsEvent {
	s.Payload = v
	return s
}
700680
func (g *gossipServiceImpl) AddPayload(chainID string, payload *gproto.Payload) error {
	g.lock.RLock()
	defer g.lock.RUnlock()
	return g.chains[chainID].AddPayload(payload)
}
1100062
func (o *ListTasksDefault) WithPayload(payload *models.Error) *ListTasksDefault {
	o.Payload = payload
	return o
}
1207952
func (s *GetMediaForFragmentListOutput) SetPayload(v io.ReadCloser) *GetMediaForFragmentListOutput {
	s.Payload = v
	return s
}
1130574
func (o *PutEndpointIDInvalid) WithPayload(payload models.Error) *PutEndpointIDInvalid {
	o.Payload = payload
	return o
}
848888
func (o *FindTodosDefault) WithPayload(payload *models.Error) *FindTodosDefault {
	o.Payload = payload
	return o
}
382619
func (o *PutServiceIDInvalidFrontend) WithPayload(payload models.Error) *PutServiceIDInvalidFrontend {
	o.Payload = payload
	return o
}
34275
func (o *GetItemsOK) WithPayload(payload []models.Item) *GetItemsOK {
	o.Payload = payload
	return o
}
969364
func (n *NetworkServerAPI) SendProprietaryPayload(ctx context.Context, req *ns.SendProprietaryPayloadRequest) (*empty.Empty, error) {
	var mic lorawan.MIC
	var gwIDs []lorawan.EUI64

	copy(mic[:], req.Mic)
	for i := range req.GatewayMacs {
		var id lorawan.EUI64
		copy(id[:], req.GatewayMacs[i])
		gwIDs = append(gwIDs, id)
	}

	err := proprietarydown.Handle(req.MacPayload, mic, gwIDs, req.PolarizationInversion, int(req.Frequency), int(req.Dr))
	if err != nil {
		return nil, errToRPCError(err)
	}

	return &empty.Empty{}, nil
}
564221
func (o *OrderGetOK) WithPayload(payload *models.Order) *OrderGetOK {
	o.Payload = payload
	return o
}
802550
func (o *PutServiceIDInvalidBackend) WithPayload(payload models.Error) *PutServiceIDInvalidBackend {
	o.Payload = payload
	return o
}