@@ -97,13 +97,43 @@ func (a *Auditor) Audit(tx Transaction) (*token.InputStream, *token.OutputStream
9797 return record .Inputs , record .Outputs , nil
9898}
9999
100+ func newRequestWrapper (r * token.Request , tms * token.ManagementService ) * requestWrapper {
101+ return & requestWrapper {r : r , tms : tms }
102+ }
103+
104+ type requestWrapper struct {
105+ r * token.Request
106+ tms * token.ManagementService
107+ }
108+
109+ func (r * requestWrapper ) Bytes () ([]byte , error ) { return r .r .Bytes () }
110+ func (r * requestWrapper ) AllApplicationMetadata () map [string ][]byte {
111+ return r .r .AllApplicationMetadata ()
112+ }
113+ func (r * requestWrapper ) PublicParamsHash () token.PPHash { return r .r .PublicParamsHash () }
114+
115+ func (r * requestWrapper ) AuditRecord () (* token.AuditRecord , error ) {
116+ record , err := r .r .AuditRecord ()
117+ if err != nil {
118+ return nil , err
119+ }
120+ if err := r .completeInputsWithEmptyEID (record ); err != nil {
121+ return nil , errors .WithMessagef (err , "failed filling gaps for request [%s]" , r .r .Anchor )
122+ }
123+ return record , nil
124+ }
125+
100126// Append adds the passed transaction to the auditor database.
101127// It also releases the locks acquired by Audit.
102128func (a * Auditor ) Append (tx Transaction ) error {
103129 defer a .Release (tx )
104130
131+ tms , err := a .tmsProvider .GetManagementService (token .WithTMSID (a .tmsID ))
132+ if err != nil {
133+ return err
134+ }
105135 // append request to audit db
106- if err := a .auditDB .Append (tx .Request (), a . completeInputsWithEmptyEID ); err != nil {
136+ if err := a .auditDB .Append (newRequestWrapper ( tx .Request (), tms ) ); err != nil {
107137 return errors .WithMessagef (err , "failed appending request %s" , tx .ID ())
108138 }
109139
@@ -148,7 +178,7 @@ func (a *Auditor) Check(context context.Context) ([]string, error) {
148178 return a .checkService .Check (context )
149179}
150180
151- func (a * Auditor ) completeInputsWithEmptyEID (record * token.AuditRecord ) error {
181+ func (r * requestWrapper ) completeInputsWithEmptyEID (record * token.AuditRecord ) error {
152182 filter := record .Inputs .ByEnrollmentID ("" )
153183 if filter .Count () == 0 {
154184 return nil
@@ -157,15 +187,11 @@ func (a *Auditor) completeInputsWithEmptyEID(record *token.AuditRecord) error {
157187 targetEID := record .Outputs .EnrollmentIDs ()[0 ]
158188
159189 // fetch all the tokens
160- tms , err := a .tmsProvider .GetManagementService (token .WithTMSID (a .tmsID ))
161- if err != nil {
162- return errors .WithMessagef (err , "failed getting management service for [%s]" , a .tmsID )
163- }
164- tokens , err := tms .Vault ().NewQueryEngine ().ListAuditTokens (filter .IDs ()... )
190+ tokens , err := r .tms .Vault ().NewQueryEngine ().ListAuditTokens (filter .IDs ()... )
165191 if err != nil {
166192 return errors .WithMessagef (err , "failed listing tokens for [%s]" , filter .IDs ())
167193 }
168- precision := tms .PublicParametersManager ().PublicParameters ().Precision ()
194+ precision := r . tms .PublicParametersManager ().PublicParameters ().Precision ()
169195 for i := 0 ; i < filter .Count (); i ++ {
170196 item := filter .At (i )
171197 item .EnrollmentID = targetEID
0 commit comments