@@ -36,17 +36,15 @@ import (
36
36
37
37
// TrillianClient provides a wrapper around the Trillian client
38
38
type TrillianClient struct {
39
- client trillian.TrillianLogClient
40
- logID int64
41
- context context.Context
39
+ client trillian.TrillianLogClient
40
+ logID int64
42
41
}
43
42
44
43
// NewTrillianClient creates a TrillianClient with the given Trillian client and log/tree ID.
45
- func NewTrillianClient (ctx context. Context , logClient trillian.TrillianLogClient , logID int64 ) TrillianClient {
44
+ func NewTrillianClient (logClient trillian.TrillianLogClient , logID int64 ) TrillianClient {
46
45
return TrillianClient {
47
- client : logClient ,
48
- logID : logID ,
49
- context : ctx ,
46
+ client : logClient ,
47
+ logID : logID ,
50
48
}
51
49
}
52
50
@@ -76,26 +74,26 @@ func unmarshalLogRoot(logRoot []byte) (types.LogRootV1, error) {
76
74
return root , nil
77
75
}
78
76
79
- func (t * TrillianClient ) root () (types.LogRootV1 , error ) {
77
+ func (t * TrillianClient ) root (ctx context. Context ) (types.LogRootV1 , error ) {
80
78
rqst := & trillian.GetLatestSignedLogRootRequest {
81
79
LogId : t .logID ,
82
80
}
83
- resp , err := t .client .GetLatestSignedLogRoot (t . context , rqst )
81
+ resp , err := t .client .GetLatestSignedLogRoot (ctx , rqst )
84
82
if err != nil {
85
83
return types.LogRootV1 {}, err
86
84
}
87
85
return unmarshalLogRoot (resp .SignedLogRoot .LogRoot )
88
86
}
89
87
90
- func (t * TrillianClient ) AddLeaf (byteValue []byte ) * Response {
88
+ func (t * TrillianClient ) AddLeaf (ctx context. Context , byteValue []byte ) * Response {
91
89
leaf := & trillian.LogLeaf {
92
90
LeafValue : byteValue ,
93
91
}
94
92
rqst := & trillian.QueueLeafRequest {
95
93
LogId : t .logID ,
96
94
Leaf : leaf ,
97
95
}
98
- resp , err := t .client .QueueLeaf (t . context , rqst )
96
+ resp , err := t .client .QueueLeaf (ctx , rqst )
99
97
100
98
// check for error
101
99
if err != nil || (resp .QueuedLeaf .Status != nil && resp .QueuedLeaf .Status .Code != int32 (codes .OK )) {
@@ -106,7 +104,7 @@ func (t *TrillianClient) AddLeaf(byteValue []byte) *Response {
106
104
}
107
105
}
108
106
109
- root , err := t .root ()
107
+ root , err := t .root (ctx )
110
108
if err != nil {
111
109
return & Response {
112
110
Status : status .Code (err ),
@@ -131,7 +129,7 @@ func (t *TrillianClient) AddLeaf(byteValue []byte) *Response {
131
129
for {
132
130
root = * logClient .GetRoot ()
133
131
if root .TreeSize >= 1 {
134
- proofResp := t .getProofByHash (resp .QueuedLeaf .Leaf .MerkleLeafHash )
132
+ proofResp := t .getProofByHash (ctx , resp .QueuedLeaf .Leaf .MerkleLeafHash )
135
133
// if this call succeeds or returns an error other than "not found", return
136
134
if proofResp .Err == nil || (proofResp .Err != nil && status .Code (proofResp .Err ) != codes .NotFound ) {
137
135
return proofResp
@@ -148,7 +146,7 @@ func (t *TrillianClient) AddLeaf(byteValue []byte) *Response {
148
146
}
149
147
}
150
148
151
- proofResp := waitForInclusion (t . context , resp .QueuedLeaf .Leaf .MerkleLeafHash )
149
+ proofResp := waitForInclusion (ctx , resp .QueuedLeaf .Leaf .MerkleLeafHash )
152
150
if proofResp .Err != nil {
153
151
return & Response {
154
152
Status : status .Code (proofResp .Err ),
@@ -168,7 +166,7 @@ func (t *TrillianClient) AddLeaf(byteValue []byte) *Response {
168
166
}
169
167
170
168
leafIndex := proofs [0 ].LeafIndex
171
- leafResp := t .GetLeafAndProofByIndex (leafIndex )
169
+ leafResp := t .GetLeafAndProofByIndex (ctx , leafIndex )
172
170
if leafResp .Err != nil {
173
171
return & Response {
174
172
Status : status .Code (leafResp .Err ),
@@ -189,9 +187,9 @@ func (t *TrillianClient) AddLeaf(byteValue []byte) *Response {
189
187
}
190
188
}
191
189
192
- func (t * TrillianClient ) GetLeafAndProofByHash (hash []byte ) * Response {
190
+ func (t * TrillianClient ) GetLeafAndProofByHash (ctx context. Context , hash []byte ) * Response {
193
191
// get inclusion proof for hash, extract index, then fetch leaf using index
194
- proofResp := t .getProofByHash (hash )
192
+ proofResp := t .getProofByHash (ctx , hash )
195
193
if proofResp .Err != nil {
196
194
return & Response {
197
195
Status : status .Code (proofResp .Err ),
@@ -208,14 +206,11 @@ func (t *TrillianClient) GetLeafAndProofByHash(hash []byte) *Response {
208
206
}
209
207
}
210
208
211
- return t .GetLeafAndProofByIndex (proofs [0 ].LeafIndex )
209
+ return t .GetLeafAndProofByIndex (ctx , proofs [0 ].LeafIndex )
212
210
}
213
211
214
- func (t * TrillianClient ) GetLeafAndProofByIndex (index int64 ) * Response {
215
- ctx , cancel := context .WithTimeout (t .context , 20 * time .Second )
216
- defer cancel ()
217
-
218
- rootResp := t .GetLatest (0 )
212
+ func (t * TrillianClient ) GetLeafAndProofByIndex (ctx context.Context , index int64 ) * Response {
213
+ rootResp := t .GetLatest (ctx , 0 )
219
214
if rootResp .Err != nil {
220
215
return & Response {
221
216
Status : status .Code (rootResp .Err ),
@@ -262,11 +257,7 @@ func (t *TrillianClient) GetLeafAndProofByIndex(index int64) *Response {
262
257
}
263
258
}
264
259
265
- func (t * TrillianClient ) GetLatest (leafSizeInt int64 ) * Response {
266
-
267
- ctx , cancel := context .WithTimeout (t .context , 20 * time .Second )
268
- defer cancel ()
269
-
260
+ func (t * TrillianClient ) GetLatest (ctx context.Context , leafSizeInt int64 ) * Response {
270
261
resp , err := t .client .GetLatestSignedLogRoot (ctx ,
271
262
& trillian.GetLatestSignedLogRootRequest {
272
263
LogId : t .logID ,
@@ -280,11 +271,7 @@ func (t *TrillianClient) GetLatest(leafSizeInt int64) *Response {
280
271
}
281
272
}
282
273
283
- func (t * TrillianClient ) GetConsistencyProof (firstSize , lastSize int64 ) * Response {
284
-
285
- ctx , cancel := context .WithTimeout (t .context , 20 * time .Second )
286
- defer cancel ()
287
-
274
+ func (t * TrillianClient ) GetConsistencyProof (ctx context.Context , firstSize , lastSize int64 ) * Response {
288
275
resp , err := t .client .GetConsistencyProof (ctx ,
289
276
& trillian.GetConsistencyProofRequest {
290
277
LogId : t .logID ,
@@ -299,11 +286,8 @@ func (t *TrillianClient) GetConsistencyProof(firstSize, lastSize int64) *Respons
299
286
}
300
287
}
301
288
302
- func (t * TrillianClient ) getProofByHash (hashValue []byte ) * Response {
303
- ctx , cancel := context .WithTimeout (t .context , 20 * time .Second )
304
- defer cancel ()
305
-
306
- rootResp := t .GetLatest (0 )
289
+ func (t * TrillianClient ) getProofByHash (ctx context.Context , hashValue []byte ) * Response {
290
+ rootResp := t .GetLatest (ctx , 0 )
307
291
if rootResp .Err != nil {
308
292
return & Response {
309
293
Status : status .Code (rootResp .Err ),
0 commit comments