@@ -36,17 +36,15 @@ import (
3636
3737// TrillianClient provides a wrapper around the Trillian client
3838type TrillianClient struct {
39- client trillian.TrillianLogClient
40- logID int64
41- context context.Context
39+ client trillian.TrillianLogClient
40+ logID int64
4241}
4342
4443// 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 {
4645 return TrillianClient {
47- client : logClient ,
48- logID : logID ,
49- context : ctx ,
46+ client : logClient ,
47+ logID : logID ,
5048 }
5149}
5250
@@ -76,26 +74,26 @@ func unmarshalLogRoot(logRoot []byte) (types.LogRootV1, error) {
7674 return root , nil
7775}
7876
79- func (t * TrillianClient ) root () (types.LogRootV1 , error ) {
77+ func (t * TrillianClient ) root (ctx context. Context ) (types.LogRootV1 , error ) {
8078 rqst := & trillian.GetLatestSignedLogRootRequest {
8179 LogId : t .logID ,
8280 }
83- resp , err := t .client .GetLatestSignedLogRoot (t . context , rqst )
81+ resp , err := t .client .GetLatestSignedLogRoot (ctx , rqst )
8482 if err != nil {
8583 return types.LogRootV1 {}, err
8684 }
8785 return unmarshalLogRoot (resp .SignedLogRoot .LogRoot )
8886}
8987
90- func (t * TrillianClient ) AddLeaf (byteValue []byte ) * Response {
88+ func (t * TrillianClient ) AddLeaf (ctx context. Context , byteValue []byte ) * Response {
9189 leaf := & trillian.LogLeaf {
9290 LeafValue : byteValue ,
9391 }
9492 rqst := & trillian.QueueLeafRequest {
9593 LogId : t .logID ,
9694 Leaf : leaf ,
9795 }
98- resp , err := t .client .QueueLeaf (t . context , rqst )
96+ resp , err := t .client .QueueLeaf (ctx , rqst )
9997
10098 // check for error
10199 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 {
106104 }
107105 }
108106
109- root , err := t .root ()
107+ root , err := t .root (ctx )
110108 if err != nil {
111109 return & Response {
112110 Status : status .Code (err ),
@@ -131,7 +129,7 @@ func (t *TrillianClient) AddLeaf(byteValue []byte) *Response {
131129 for {
132130 root = * logClient .GetRoot ()
133131 if root .TreeSize >= 1 {
134- proofResp := t .getProofByHash (resp .QueuedLeaf .Leaf .MerkleLeafHash )
132+ proofResp := t .getProofByHash (ctx , resp .QueuedLeaf .Leaf .MerkleLeafHash )
135133 // if this call succeeds or returns an error other than "not found", return
136134 if proofResp .Err == nil || (proofResp .Err != nil && status .Code (proofResp .Err ) != codes .NotFound ) {
137135 return proofResp
@@ -148,7 +146,7 @@ func (t *TrillianClient) AddLeaf(byteValue []byte) *Response {
148146 }
149147 }
150148
151- proofResp := waitForInclusion (t . context , resp .QueuedLeaf .Leaf .MerkleLeafHash )
149+ proofResp := waitForInclusion (ctx , resp .QueuedLeaf .Leaf .MerkleLeafHash )
152150 if proofResp .Err != nil {
153151 return & Response {
154152 Status : status .Code (proofResp .Err ),
@@ -168,7 +166,7 @@ func (t *TrillianClient) AddLeaf(byteValue []byte) *Response {
168166 }
169167
170168 leafIndex := proofs [0 ].LeafIndex
171- leafResp := t .GetLeafAndProofByIndex (leafIndex )
169+ leafResp := t .GetLeafAndProofByIndex (ctx , leafIndex )
172170 if leafResp .Err != nil {
173171 return & Response {
174172 Status : status .Code (leafResp .Err ),
@@ -189,9 +187,9 @@ func (t *TrillianClient) AddLeaf(byteValue []byte) *Response {
189187 }
190188}
191189
192- func (t * TrillianClient ) GetLeafAndProofByHash (hash []byte ) * Response {
190+ func (t * TrillianClient ) GetLeafAndProofByHash (ctx context. Context , hash []byte ) * Response {
193191 // get inclusion proof for hash, extract index, then fetch leaf using index
194- proofResp := t .getProofByHash (hash )
192+ proofResp := t .getProofByHash (ctx , hash )
195193 if proofResp .Err != nil {
196194 return & Response {
197195 Status : status .Code (proofResp .Err ),
@@ -208,14 +206,11 @@ func (t *TrillianClient) GetLeafAndProofByHash(hash []byte) *Response {
208206 }
209207 }
210208
211- return t .GetLeafAndProofByIndex (proofs [0 ].LeafIndex )
209+ return t .GetLeafAndProofByIndex (ctx , proofs [0 ].LeafIndex )
212210}
213211
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 )
219214 if rootResp .Err != nil {
220215 return & Response {
221216 Status : status .Code (rootResp .Err ),
@@ -262,11 +257,7 @@ func (t *TrillianClient) GetLeafAndProofByIndex(index int64) *Response {
262257 }
263258}
264259
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 {
270261 resp , err := t .client .GetLatestSignedLogRoot (ctx ,
271262 & trillian.GetLatestSignedLogRootRequest {
272263 LogId : t .logID ,
@@ -280,11 +271,7 @@ func (t *TrillianClient) GetLatest(leafSizeInt int64) *Response {
280271 }
281272}
282273
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 {
288275 resp , err := t .client .GetConsistencyProof (ctx ,
289276 & trillian.GetConsistencyProofRequest {
290277 LogId : t .logID ,
@@ -299,11 +286,8 @@ func (t *TrillianClient) GetConsistencyProof(firstSize, lastSize int64) *Respons
299286 }
300287}
301288
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 )
307291 if rootResp .Err != nil {
308292 return & Response {
309293 Status : status .Code (rootResp .Err ),
0 commit comments