예제 #1
0
파일: main.go 프로젝트: ZhuZhengyi/eris-db
func roomGET(c *gin.Context) {
	roomid := c.Param("roomid")
	userid := fmt.Sprint(rand.Int31())
	c.HTML(200, "chat_room", gin.H{
		"roomid": roomid,
		"userid": userid,
	})
}
예제 #2
0
func (this *RestServer) handlePeers(c *gin.Context) {
	peers, err := this.pipe.Net().Peers()
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(peers, c.Writer)
}
예제 #3
0
func (this *RestServer) handleListeners(c *gin.Context) {
	listeners, err := this.pipe.Net().Listeners()
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(&ep.Listeners{listeners}, c.Writer)
}
예제 #4
0
func (this *RestServer) handleMoniker(c *gin.Context) {
	moniker, err := this.pipe.Net().Moniker()
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(&ep.Moniker{moniker}, c.Writer)
}
예제 #5
0
func (this *RestServer) handleValidatorList(c *gin.Context) {
	vl, err := this.pipe.Consensus().Validators()
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(vl, c.Writer)
}
예제 #6
0
func (this *RestServer) handleChainId(c *gin.Context) {
	cId, err := this.pipe.Blockchain().ChainId()
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(&ep.ChainId{cId}, c.Writer)
}
예제 #7
0
func (this *RestServer) handleLatestBlock(c *gin.Context) {
	lb, err := this.pipe.Blockchain().LatestBlock()
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(lb, c.Writer)
}
예제 #8
0
func (this *RestServer) handleGenesisHash(c *gin.Context) {
	gh, err := this.pipe.Blockchain().GenesisHash()
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(&ep.GenesisHash{gh}, c.Writer)
}
예제 #9
0
func (this *RestServer) handleBlockchainInfo(c *gin.Context) {
	bci, err := this.pipe.Blockchain().Info()
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(bci, c.Writer)
}
예제 #10
0
func (this *RestServer) handleNetworkInfo(c *gin.Context) {
	nInfo, err := this.pipe.Net().Info()
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(nInfo, c.Writer)
}
예제 #11
0
func (this *RestServer) handleClientVersion(c *gin.Context) {
	version, err := this.pipe.Net().ClientVersion()
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(&ep.ClientVersion{version}, c.Writer)
}
예제 #12
0
func (this *RestServer) handleEventUnsubscribe(c *gin.Context) {
	subId := c.MustGet("id").(string)
	err := this.eventSubs.remove(subId)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(&ep.EventUnsub{true}, c.Writer)
}
예제 #13
0
func (this *RestServer) handleEventPoll(c *gin.Context) {
	subId := c.MustGet("id").(string)
	data, err := this.eventSubs.poll(subId)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(&ep.PollResponse{data}, c.Writer)
}
예제 #14
0
func (this *RestServer) handleBlock(c *gin.Context) {
	height := c.MustGet("height").(int)
	block, err := this.pipe.Blockchain().Block(height)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(block, c.Writer)
}
예제 #15
0
func (this *RestServer) handleUnconfirmedTxs(c *gin.Context) {

	txs, err := this.pipe.Transactor().UnconfirmedTxs()
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(txs, c.Writer)
}
예제 #16
0
func (this *RestServer) handleStorage(c *gin.Context) {
	addr := c.MustGet("addrBts").([]byte)
	s, err := this.pipe.Accounts().Storage(addr)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(s, c.Writer)
}
예제 #17
0
// ********************************* Consensus *********************************
func (this *RestServer) handleConsensusState(c *gin.Context) {

	cs, err := this.pipe.Consensus().State()
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(cs, c.Writer)
}
예제 #18
0
func (this *RestServer) handlePeer(c *gin.Context) {
	address := c.MustGet("address").(string)
	peer, err := this.pipe.Net().Peer(address)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(peer, c.Writer)
}
예제 #19
0
func (this *RestServer) handleNameRegEntry(c *gin.Context) {
	name := c.MustGet("name").(string)
	entry, err := this.pipe.NameReg().Entry(name)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(entry, c.Writer)
}
예제 #20
0
func heightParam(c *gin.Context) {
	h, err := strconv.Atoi(c.Param("height"))
	if err != nil {
		c.AbortWithError(400, err)
	}
	if h < 0 {
		c.AbortWithError(400, fmt.Errorf("Negative number used as height."))
	}
	c.Set("height", h)
	c.Next()
}
예제 #21
0
func (this *RestServer) handleEventSubscribe(c *gin.Context) {
	param := &EventIdParam{}
	errD := this.codec.Decode(param, c.Request.Body)
	if errD != nil {
		c.AbortWithError(500, errD)
	}
	subId, err := this.eventSubs.add(param.EventId)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(&ep.EventSub{subId}, c.Writer)
}
예제 #22
0
func (this *RestServer) handleBroadcastTx(c *gin.Context) {
	param := &types.CallTx{}
	errD := this.codec.Decode(param, c.Request.Body)
	if errD != nil {
		c.AbortWithError(500, errD)
	}
	receipt, err := this.pipe.Transactor().BroadcastTx(param)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(receipt, c.Writer)
}
예제 #23
0
func (this *RestServer) handleSignTx(c *gin.Context) {
	param := &SignTxParam{}
	errD := this.codec.Decode(param, c.Request.Body)
	if errD != nil {
		c.AbortWithError(500, errD)
	}
	tx, err := this.pipe.Transactor().SignTx(param.Tx, param.PrivAccounts)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(tx, c.Writer)
}
예제 #24
0
func (this *RestServer) handleNameRegEntries(c *gin.Context) {
	var filters []*ep.FilterData
	fs, exists := c.Get("filters")
	if exists {
		filters = fs.([]*ep.FilterData)
	}
	entries, err := this.pipe.NameReg().Entries(filters)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(entries, c.Writer)
}
예제 #25
0
func (this *RestServer) handleTransactNameReg(c *gin.Context) {
	param := &TransactNameRegParam{}
	errD := this.codec.Decode(param, c.Request.Body)
	if errD != nil {
		c.AbortWithError(500, errD)
	}
	receipt, err := this.pipe.Transactor().TransactNameReg(param.PrivKey, param.Name, param.Data, param.Amount, param.Fee)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(receipt, c.Writer)
}
예제 #26
0
func (this *RestServer) handleCallCode(c *gin.Context) {
	param := &CallCodeParam{}
	errD := this.codec.Decode(param, c.Request.Body)
	if errD != nil {
		c.AbortWithError(500, errD)
	}
	call, err := this.pipe.Transactor().CallCode(param.From, param.Code, param.Data)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(call, c.Writer)
}
예제 #27
0
func (this *RestServer) handleTransact(c *gin.Context) {

	_, hold := c.Get("hold")

	param := &TransactParam{}
	errD := this.codec.Decode(param, c.Request.Body)
	if errD != nil {
		c.AbortWithError(500, errD)
	}
	if hold {
		res, err := this.pipe.Transactor().TransactAndHold(param.PrivKey, param.Address, param.Data, param.GasLimit, param.Fee)
		if err != nil {
			c.AbortWithError(500, err)
		}
		c.Writer.WriteHeader(200)
		this.codec.Encode(res, c.Writer)
	} else {
		receipt, err := this.pipe.Transactor().Transact(param.PrivKey, param.Address, param.Data, param.GasLimit, param.Fee)
		if err != nil {
			c.AbortWithError(500, err)
		}
		c.Writer.WriteHeader(200)
		this.codec.Encode(receipt, c.Writer)
	}
}
예제 #28
0
func (this *RestServer) handleBlocks(c *gin.Context) {
	var filters []*ep.FilterData
	fs, exists := c.Get("filters")
	if exists {
		filters = fs.([]*ep.FilterData)
	}

	blocks, err := this.pipe.Blockchain().Blocks(filters)
	if err != nil {
		c.AbortWithError(500, err)
	}
	c.Writer.WriteHeader(200)
	this.codec.Encode(blocks, c.Writer)
}
예제 #29
0
// Just a catch-all for POST requests right now. Only allow default charset (utf8).
func contentTypeMW(c *gin.Context) {
	if c.Request.Method == "POST" && c.ContentType() != "application/json" {
		c.AbortWithError(415, fmt.Errorf("Media type not supported: "+c.ContentType()))
	} else {
		c.Next()
	}
}
예제 #30
0
func subIdParam(c *gin.Context) {
	subId := c.Param("id")
	if len(subId) != 64 || !util.IsHex(subId) {
		c.AbortWithError(400, fmt.Errorf("Malformed event id"))
	}
	c.Set("id", subId)
	c.Next()
}