Skip to content

Commit

Permalink
v0.2.1, retrieve height info from get_block request
Browse files Browse the repository at this point in the history
  • Loading branch information
superisaac committed Oct 7, 2023
1 parent 9598e5b commit 280d0a4
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion nodemux/chains/eos.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package chains

import (
"bytes"
"context"
"encoding/json"
"github.com/superisaac/nodemux/core"
"io"
"net/http"
)

Expand All @@ -11,6 +14,10 @@ type eosChainInfo struct {
LastBlockId string `json:"last_irreversible_block_id"`
}

type eosChainGetBlockReq struct {
BlockNumOrId int `json:"block_num_or_id"`
}

type EosChain struct {
}

Expand Down Expand Up @@ -44,5 +51,20 @@ func (self *EosChain) GetBlockhead(context context.Context, b *nodemuxcore.Multi

func (self *EosChain) DelegateREST(rootCtx context.Context, b *nodemuxcore.Multiplexer, chain nodemuxcore.ChainRef, path string, w http.ResponseWriter, r *http.Request) error {
// Custom relay methods can be defined here
return b.DefaultPipeREST(rootCtx, chain, path, w, r, -30)
h := -10
if path == "/v1/chain/get_block" {
body, err := io.ReadAll(r.Body)
if err != nil {
return err
}
getBlockReq := eosChainGetBlockReq{}
if err := json.Unmarshal(body, &getBlockReq); err == nil {
h = getBlockReq.BlockNumOrId
chain.Log().Infof("retrieved block number %d from get_block request", h)
}
r.Body = io.NopCloser(bytes.NewBuffer(body))
} else if path == "/v1/chain/get_info" {
h = 0
}
return b.DefaultPipeREST(rootCtx, chain, path, w, r, h)
}

0 comments on commit 280d0a4

Please sign in to comment.