Rename projected to mempool

This commit is contained in:
Gustavo Chain 2020-03-29 15:48:58 +02:00
parent f5cdc20b4f
commit 616593ce4d
No known key found for this signature in database
GPG Key ID: DA7C1746DC118A46
4 changed files with 34 additions and 29 deletions

View File

@ -31,17 +31,16 @@ type Block struct {
MedianFee float64 `json:"medianFee"`
}
type ProjectedBlock struct {
BlockSize int `json:"blockSize"`
BlockWeight int `json:"blockWeight"`
NTx int `json:"nTx"`
MinFee float64 `json:"minFee"`
MaxFee float64 `json:"maxFee"`
MinWeigthFee float64 `json:"minWeigthFee"`
MaxWeigthFee float64 `json:"maxWeigthFee"`
MedianFee float64 `json:"medianFee"`
Fees float64 `json:"fees"`
HasMyTx bool `json:"hasMytx"`
type MempoolBlock struct {
BlockSize int `json:"blockSize"`
BlockWeight int `json:"blockWeight"`
NTx int `json:"nTx"`
FeeRange []float64 `json:"feeRange"`
MinWeigthFee float64 `json:"minWeigthFee"`
MaxWeigthFee float64 `json:"maxWeigthFee"`
MedianFee float64 `json:"medianFee"`
Fees float64 `json:"fees"`
HasMyTx bool `json:"hasMytx"`
}
type TrackTx struct {
@ -61,8 +60,8 @@ type Response struct {
Block *Block `json:"block"`
Blocks []Block `json:"blocks"`
ProjectedBlocks []ProjectedBlock `json:"projectedBlocks"`
TrackTx TrackTx `json:"track-tx"`
MempoolBlocks []MempoolBlock `json:"mempool-blocks"`
TrackTx TrackTx `json:"track-tx"`
TxPerSecond float64 `json:"txPerSecond"`
VBytesPerSecond int `json:"vBytesPerSecond"`
@ -82,6 +81,11 @@ func New() (*Client, error) {
if err != nil {
return nil, err
}
conn.WriteMessage(websocket.TextMessage, []byte(
`{"action": "init"}`,
))
return &Client{conn: conn}, nil
}
@ -95,7 +99,7 @@ func (c *Client) Read() (*Response, error) {
func (c *Client) Want() error {
return c.conn.WriteMessage(websocket.TextMessage, []byte(
`{"action":"want","data":["stats","blocks","projected-blocks"]}`,
`{"action":"want","data":["stats","blocks","mempool-blocks"]}`,
))
}
@ -134,9 +138,9 @@ func Get(ctx context.Context, path string, v interface{}) error {
return json.NewDecoder(r.Body).Decode(v)
}
func GetProjectedFee(ctx context.Context, n int) (Fees, error) {
func GetMempoolFee(ctx context.Context, n int) (Fees, error) {
var fees Fees
if err := Get(ctx, fmt.Sprintf("transactions/projected/%d", n), &fees); err != nil {
if err := Get(ctx, fmt.Sprintf("transactions/mempool/%d", n), &fees); err != nil {
return nil, err
}
return fees, nil

View File

@ -48,9 +48,9 @@ func (b *Box) Render(full int, bg color.Attribute) []byte {
return buf.Bytes()
}
type ProjectedBlock client.ProjectedBlock
type MempoolBlock client.MempoolBlock
func (b ProjectedBlock) Print(n int, x, _y int) []byte {
func (b MempoolBlock) Print(n int, x, _y int) []byte {
var footer string
// Attach ETA to the first 3 blocks
if n < 3 {
@ -60,9 +60,10 @@ func (b ProjectedBlock) Print(n int, x, _y int) []byte {
footer = fmt.Sprintf("+%d blocks", n)
}
min, max := b.FeeRange[0], b.FeeRange[len(b.FeeRange)-1]
box := &Box{x: x}
box.Printf(color.FgWhite, "~%d sat/vB", ceil(b.MedianFee)).
Printf(color.FgYellow, "%d-%d sat/vB", ceil(b.MinFee), ceil(b.MaxFee)).
Printf(color.FgYellow, "%d-%d sat/vB", ceil(min), ceil(max)).
Append("").
Printf(color.FgWhite, "%.2f MB", float64(b.BlockSize)/(1000*1000)).
Printf(color.FgWhite, "%4d transactions", b.NTx).

View File

@ -34,7 +34,7 @@ func (fd *FeeDistribution) newCtx() context.Context {
func (fd *FeeDistribution) FetchProjection(n int) error {
fn := func(ctx context.Context) (client.Fees, error) {
return client.GetProjectedFee(ctx, n)
return client.GetMempoolFee(ctx, n)
}
return fd.fetch(fn)
}

View File

@ -18,7 +18,7 @@ const (
type state struct {
loaded bool
blocks []client.Block
projected []client.ProjectedBlock
mempool []client.MempoolBlock
vBytesPerSecond int
info *client.MempoolInfo
tracking *client.TrackTx
@ -105,8 +105,8 @@ func (ui *UI) Render(resp *client.Response) {
ui.state.blocks = bs
}
if bs := resp.ProjectedBlocks; len(bs) != 0 {
ui.state.projected = bs
if bs := resp.MempoolBlocks; len(bs) != 0 {
ui.state.mempool = bs
}
if b := resp.Block; b != nil {
@ -144,8 +144,8 @@ func (ui *UI) Layout(g *gocui.Gui) error {
track := ui.state.tracking
// draw projected blocks (mempool)
for i, _ := range ui.state.projected {
name := fmt.Sprintf("projected-block-%d", i)
for i, _ := range ui.state.mempool {
name := fmt.Sprintf("mempool-block-%d", i)
var x0, x1, y0, y1 int
if vertical {
x0 = x - (BLOCK_WIDTH+2)*(i+1)
@ -246,8 +246,8 @@ func (ui *UI) loading(g *gocui.Gui, x, y int) error {
}
func (ui *UI) printProjectedBlock(n int, x, y int) []byte {
b := ui.state.projected[n]
return ProjectedBlock(b).Print(n, x, y)
b := ui.state.mempool[n]
return MempoolBlock(b).Print(n, x, y)
}
func (ui *UI) printBlock(n int, x, y int) []byte {
@ -306,14 +306,14 @@ func (ui *UI) info(g *gocui.Gui, x, y int) error {
}
var mSize int
for _, b := range ui.state.projected {
for _, b := range ui.state.mempool {
mSize += b.BlockSize
}
// Compute the total number of blocks on the mempool
// We use the total BlockWeight / 4mm
var w float64
for _, b := range ui.state.projected {
for _, b := range ui.state.mempool {
w += float64(b.BlockWeight)
}