diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-06-02 15:42:54 +0200 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-06-02 15:42:54 +0200 |
commit | 5d945794190b0088b5a953d4931d8ede31866182 (patch) | |
tree | 9f9f3fedc2413b2b11a40788c1ec79c09524c6b0 /trillian/client.go | |
parent | 0c5cd634e95d0ce07908a8ac32ecf80639f52785 (diff) |
added refactored GetInclusionProof
Diffstat (limited to 'trillian/client.go')
-rw-r--r-- | trillian/client.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/trillian/client.go b/trillian/client.go index cbeb1ca..c619b03 100644 --- a/trillian/client.go +++ b/trillian/client.go @@ -139,5 +139,32 @@ func (c *Client) GetInclusionProof(ctx context.Context, req *types.InclusionProo } func (c *Client) GetLeaves(ctx context.Context, req *types.LeavesRequest) (*types.LeafList, error) { - return nil, fmt.Errorf("TODO") + rsp, err := c.GRPC.GetLeavesByRange(ctx, &trillian.GetLeavesByRangeRequest{ + LogId: c.TreeID, + StartIndex: int64(req.StartSize), + Count: int64(req.EndSize-req.StartSize) + 1, + }) + if err != nil { + return nil, fmt.Errorf("backend failure: %v", err) + } + if rsp == nil { + return nil, fmt.Errorf("no response") + } + if got, want := len(rsp.Leaves), int(req.EndSize-req.StartSize+1); got != want { + return nil, fmt.Errorf("unexpected number of leaves: %d", got) + } + var list types.LeafList + for i, leaf := range rsp.Leaves { + leafIndex := int64(req.StartSize + uint64(i)) + if leafIndex != leaf.LeafIndex { + return nil, fmt.Errorf("unexpected leaf(%d): got index %d", leafIndex, leaf.LeafIndex) + } + + var l types.Leaf + if err := l.Unmarshal(leaf.LeafValue); err != nil { + return nil, fmt.Errorf("unexpected leaf(%d): %v", leafIndex, err) + } + list = append(list[:], &l) + } + return &list, nil } |