aboutsummaryrefslogtreecommitdiff
path: root/trillian/client.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-06-02 14:39:27 +0200
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-06-02 14:39:27 +0200
commit6e04ae48997ae5fa6e0f803792b674ca24bad8f0 (patch)
tree3cd5fd2150d0677aecbfa7cb453447740659ad54 /trillian/client.go
parent0d55439c5292ced60e7c2cfd3761f9ef990414ce (diff)
added refactored GetConsistencyProof
Diffstat (limited to 'trillian/client.go')
-rw-r--r--trillian/client.go37
1 files changed, 27 insertions, 10 deletions
diff --git a/trillian/client.go b/trillian/client.go
index c22e9cc..7b8a00a 100644
--- a/trillian/client.go
+++ b/trillian/client.go
@@ -75,19 +75,36 @@ func (c *Client) GetTreeHead(ctx context.Context) (*types.TreeHead, error) {
if len(r.RootHash) != types.HashSize {
return nil, fmt.Errorf("unexpected hash length: %d", len(r.RootHash))
}
-
- var hash [types.HashSize]byte
- th := types.TreeHead{
- Timestamp: uint64(r.TimestampNanos / 1000 / 1000 / 1000),
- TreeSize: uint64(r.TreeSize),
- RootHash: &hash,
- }
- copy(th.RootHash[:], r.RootHash)
- return &th, nil
+ return treeHeadFromLogRoot(&r), nil
}
func (c *Client) GetConsistencyProof(ctx context.Context, req *types.ConsistencyProofRequest) (*types.ConsistencyProof, error) {
- return nil, fmt.Errorf("TODO")
+ rsp, err := c.GRPC.GetConsistencyProof(ctx, &trillian.GetConsistencyProofRequest{
+ LogId: c.TreeID,
+ FirstTreeSize: int64(req.OldSize),
+ SecondTreeSize: int64(req.NewSize),
+ })
+ if err != nil {
+ return nil, fmt.Errorf("backend failure: %v", err)
+ }
+ if rsp == nil {
+ return nil, fmt.Errorf("no response")
+ }
+ if rsp.Proof == nil {
+ return nil, fmt.Errorf("no consistency proof")
+ }
+ if len(rsp.Proof.Hashes) == 0 {
+ return nil, fmt.Errorf("not a consistency proof: empty")
+ }
+ path, err := nodePathFromHashes(rsp.Proof.Hashes)
+ if err != nil {
+ return nil, fmt.Errorf("not a consistency proof: %v", err)
+ }
+ return &types.ConsistencyProof{
+ OldSize: req.OldSize,
+ NewSize: req.NewSize,
+ Path: path,
+ }, nil
}
func (c *Client) GetInclusionProof(ctx context.Context, req *types.InclusionProofRequest) (*types.InclusionProof, error) {