fix(grpc): fix getblocks func
This commit is contained in:
parent
e5eaea1527
commit
2c561b9864
|
@ -72,7 +72,7 @@ func (cbs *ChainBrokerService) GetBlock(ctx context.Context, req *pb.GetBlockReq
|
|||
}
|
||||
|
||||
func (cbs *ChainBrokerService) GetBlocks(ctx context.Context, req *pb.GetBlocksRequest) (*pb.GetBlocksResponse, error) {
|
||||
blocks, err := cbs.api.Broker().GetBlocks(req.Offset, req.Length)
|
||||
blocks, err := cbs.api.Broker().GetBlocks(req.Start, req.End)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
4
go.mod
4
go.mod
|
@ -15,8 +15,8 @@ require (
|
|||
github.com/magiconair/properties v1.8.1
|
||||
github.com/meshplus/bitxhub-core v0.1.0-rc1
|
||||
github.com/meshplus/bitxhub-kit v1.0.0
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc3
|
||||
github.com/meshplus/go-bitxhub-client v1.0.0-rc3
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc4
|
||||
github.com/meshplus/go-bitxhub-client v1.0.0-rc4
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/multiformats/go-multiaddr v0.2.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
|
|
4
go.sum
4
go.sum
|
@ -522,8 +522,12 @@ github.com/meshplus/bitxhub-kit v1.0.0 h1:+RHGTqW50CLZlEQAUm89fQHicYcjqkdYa+QMAk
|
|||
github.com/meshplus/bitxhub-kit v1.0.0/go.mod h1:7cWyhXWZfrQ3+EaxkRoXfuiG3Y5R9DXYJomeZKkETW8=
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc3 h1:oTyaDnhmMPKYifkV2Z5fH2OeY2RE7b6Bk6TzoOT9n4c=
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc3/go.mod h1:ZCctQIYTlE3vJ8Lhkrgs9bWwNA+Dw4JzojOSIzLVU6E=
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc4 h1:qnXj+8S50NQn9kmIqxRnLABRhMTVErsTC0iakLJbzKI=
|
||||
github.com/meshplus/bitxhub-model v1.0.0-rc4/go.mod h1:ZCctQIYTlE3vJ8Lhkrgs9bWwNA+Dw4JzojOSIzLVU6E=
|
||||
github.com/meshplus/go-bitxhub-client v1.0.0-rc3 h1:cuT6iUfwe2u+LwuR9VIQ888vKDEonFhgxj3c/tdr0rs=
|
||||
github.com/meshplus/go-bitxhub-client v1.0.0-rc3/go.mod h1:FpiCyf6KhydcqthrHdvvPhbPIcD92b+Ju8T7WvQtSyM=
|
||||
github.com/meshplus/go-bitxhub-client v1.0.0-rc4 h1:BwryLYBty0O9TGgGdYbFdLqHEZAQqkCinWc+55X6/Z4=
|
||||
github.com/meshplus/go-bitxhub-client v1.0.0-rc4/go.mod h1:h345/3jFkFa7bbNqY5QjSfwwRQa76UvCWLss89xtrYI=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/miekg/pkcs11 v1.0.3 h1:iMwmD7I5225wv84WxIG/bmxz9AXjWvTWIbM/TYHvWtw=
|
||||
|
|
|
@ -23,7 +23,7 @@ type BrokerAPI interface {
|
|||
GetTransactionMeta(types.Hash) (*pb.TransactionMeta, error)
|
||||
GetReceipt(types.Hash) (*pb.Receipt, error)
|
||||
GetBlock(mode string, key string) (*pb.Block, error)
|
||||
GetBlocks(offset uint64, length uint64) ([]*pb.Block, error)
|
||||
GetBlocks(start uint64, end uint64) ([]*pb.Block, error)
|
||||
|
||||
// AddPier
|
||||
AddPier(pid string) (chan *pb.MerkleWrapper, error)
|
||||
|
|
|
@ -63,12 +63,14 @@ func (b *BrokerAPI) GetBlock(mode string, value string) (*pb.Block, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (b *BrokerAPI) GetBlocks(offset uint64, length uint64) ([]*pb.Block, error) {
|
||||
func (b *BrokerAPI) GetBlocks(start uint64, end uint64) ([]*pb.Block, error) {
|
||||
meta := b.bxh.Ledger.GetChainMeta()
|
||||
|
||||
var blocks []*pb.Block
|
||||
for i := meta.Height - offset; i > 0 && length > 0; i-- {
|
||||
length--
|
||||
if meta.Height < end {
|
||||
end = meta.Height
|
||||
}
|
||||
for i := start; i > 0 && i <= end; i++ {
|
||||
b, err := b.GetBlock("HEIGHT", strconv.Itoa(int(i)))
|
||||
if err != nil {
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue