Skip to content

Commit

Permalink
Fixes for JSON Server
Browse files Browse the repository at this point in the history
  • Loading branch information
mtgnoah committed Oct 25, 2023
1 parent 1ce885e commit 48df7cd
Showing 1 changed file with 46 additions and 36 deletions.
82 changes: 46 additions & 36 deletions rpc/jsonrpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,10 @@ func (j *JSONRPCServer) GetBlockHeadersByHeight(req *http.Request, args *GetBloc
return true
})

res := BlockHeadersResponse{From: args.Height, Blocks: blocks, Prev: Prev, Next: Next}

reply = &res
reply.From = args.Height
reply.Blocks = blocks
reply.Prev = Prev
reply.Next = Next

return nil
}
Expand All @@ -406,7 +407,7 @@ func (j *JSONRPCServer) GetBlockHeadersID(req *http.Request, args *GetBlockHeade
// Handle hash parameter
// ...
} else {
firstBlock = 0
firstBlock = 1
// Handle error or default case
// TODO add error potentially
// http.Error(writer, "Invalid parameters", http.StatusBadRequest)
Expand Down Expand Up @@ -479,9 +480,13 @@ func (j *JSONRPCServer) GetBlockHeadersID(req *http.Request, args *GetBlockHeade
return true
})

res := BlockHeadersResponse{From: firstBlock, Blocks: blocks, Prev: Prev, Next: Next}
// res := BlockHeadersResponse{From: firstBlock, Blocks: blocks, Prev: Prev, Next: Next}

reply = &res
// reply = &res
reply.From = firstBlock
reply.Blocks = blocks
reply.Prev = Prev
reply.Next = Next
// TODO add blocks to the list of blocks contained in this time window
// Marshal res to JSON and send the response

Expand Down Expand Up @@ -534,9 +539,10 @@ func (j *JSONRPCServer) GetBlockHeadersByStart(req *http.Request, args *GetBlock
if err != nil {
return err
}
tmp := blk.Tmstmp / 1000
Prev = BlockInfo{
BlockId: prevBlkId.String(),
Timestamp: blk.Tmstmp,
Timestamp: tmp,
L1Head: l1Head.Uint64(),
}
} else {
Expand Down Expand Up @@ -566,28 +572,33 @@ func (j *JSONRPCServer) GetBlockHeadersByStart(req *http.Request, args *GetBlock
return false
}

if blk.Tmstmp >= args.End {
fmt.Println("Next Found")
fmt.Println("Blocks Length After Next:", len(blocks))

tmp := blk.Tmstmp / 1000

Next = BlockInfo{
BlockId: id.String(),
Timestamp: tmp,
L1Head: l1Head.Uint64(),
}
return false
}

if blk.Hght == heightKey {
tmp := blk.Tmstmp / 1000

blocks = append(blocks, BlockInfo{
BlockId: id.String(),
Timestamp: blk.Tmstmp,
Timestamp: tmp,
L1Head: l1Head.Uint64(),
})
fmt.Println("Match Found")
fmt.Println("Blocks Length After Append:", len(blocks))

}

if blk.Tmstmp > args.End {
fmt.Println("Next Found")
fmt.Println("Blocks Length After Next:", len(blocks))

Next = BlockInfo{
BlockId: id.String(),
Timestamp: blk.Tmstmp,
L1Head: l1Head.Uint64(),
}
return false
}
return true
})

Expand Down Expand Up @@ -621,34 +632,33 @@ func (j *JSONRPCServer) GetBlockTransactions(req *http.Request, args *GetBlockTr

block, success := j.headers.Get(args.ID)

if success {

res := TransactionResponse{Txs: block.Txs, BlockId: args.ID}

reply = &res

if !success {
return errors.New("Txs Not Found")
}

reply.Txs = block.Txs
reply.BlockId = args.ID

return nil
}

func (j *JSONRPCServer) GetBlockTransactionsByNamespace(req *http.Request, args *GetBlockTransactionsByNamespaceArgs, reply *SEQTransactionResponse) error {
BlkId, success := j.idsByHeight.Get(args.Height)

if success {
block, found := j.blocksWithValidTxs.Get(BlkId.String())
if !found {
return fmt.Errorf("Could not find Block: %s ", BlkId.String())
}

txs := block.Txs[args.Namespace]
res := SEQTransactionResponse{Txs: txs, BlockId: BlkId.String()}
if !success {
return errors.New("Txs Not Found For Namespace")
}

reply = &res
} else {
reply = &SEQTransactionResponse{}
block, found := j.blocksWithValidTxs.Get(BlkId.String())
if !found {
return fmt.Errorf("Could not find Block: %s ", BlkId.String())
}

txs := block.Txs[args.Namespace]

reply.Txs = txs
reply.BlockId = BlkId.String()

return nil
}

Expand Down

0 comments on commit 48df7cd

Please sign in to comment.