diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-06-02 15:01:18 +0200 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-06-02 15:01:18 +0200 |
commit | 0c5cd634e95d0ce07908a8ac32ecf80639f52785 (patch) | |
tree | de2ec3fc1b6adc848bae45b01784c260651e31a6 /trillian/client.go | |
parent | 6e04ae48997ae5fa6e0f803792b674ca24bad8f0 (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 7b8a00a..cbeb1ca 100644 --- a/trillian/client.go +++ b/trillian/client.go @@ -108,7 +108,34 @@ func (c *Client) GetConsistencyProof(ctx context.Context, req *types.Consistency } func (c *Client) GetInclusionProof(ctx context.Context, req *types.InclusionProofRequest) (*types.InclusionProof, error) { - return nil, fmt.Errorf("TODO") + rsp, err := c.GRPC.GetInclusionProofByHash(ctx, &trillian.GetInclusionProofByHashRequest{ + LogId: c.TreeID, + LeafHash: req.LeafHash[:], + TreeSize: int64(req.TreeSize), + OrderBySequence: true, + }) + if err != nil { + return nil, fmt.Errorf("backend failure: %v", err) + } + if rsp == nil { + return nil, fmt.Errorf("no response") + } + if len(rsp.Proof) != 1 { + return nil, fmt.Errorf("bad proof count: %d", len(rsp.Proof)) + } + proof := rsp.Proof[0] + if len(proof.Hashes) == 0 { + return nil, fmt.Errorf("not an inclusion proof: empty") + } + path, err := nodePathFromHashes(proof.Hashes) + if err != nil { + return nil, fmt.Errorf("not an inclusion proof: %v", err) + } + return &types.InclusionProof{ + TreeSize: req.TreeSize, + LeafIndex: uint64(proof.LeafIndex), + Path: path, + }, nil } func (c *Client) GetLeaves(ctx context.Context, req *types.LeavesRequest) (*types.LeafList, error) { |