@@ -121,90 +121,6 @@ type VoidCreditPurchaseResult struct {
121121 TransactionGroupID string
122122}
123123
124- type Record struct {
125- ID models.NamespacedID
126- Amount alpacadecimal.Decimal
127- CreatedAt time.Time
128- UpdatedAt time.Time
129- DeletedAt * time.Time
130-
131- CustomerID customer.CustomerID
132- Currency currencyx.Code
133- VoidedAt time.Time
134-
135- SourceChargeID string
136-
137- VoidTransactionGroupID string
138- VoidTransactionID string
139-
140- FBOSubAccountID string
141- ReceivableSubAccountID string
142-
143- Annotations models.Annotations
144- }
145-
146- type PendingRecord struct {
147- Record
148- }
149-
150- type CreateRecordsInput struct {
151- Records []Record
152- }
153-
154- func (i CreateRecordsInput ) Validate () error {
155- for idx , record := range i .Records {
156- if err := record .Validate (); err != nil {
157- return fmt .Errorf ("records[%d]: %w" , idx , err )
158- }
159- }
160-
161- return nil
162- }
163-
164- func (r Record ) Validate () error {
165- var errs []error
166-
167- if err := r .ID .Validate (); err != nil {
168- errs = append (errs , fmt .Errorf ("id: %w" , err ))
169- }
170- if ! r .Amount .IsPositive () {
171- errs = append (errs , errors .New ("amount must be positive" ))
172- }
173- if err := r .CustomerID .Validate (); err != nil {
174- errs = append (errs , fmt .Errorf ("customer id: %w" , err ))
175- }
176- if err := r .Currency .Validate (); err != nil {
177- errs = append (errs , fmt .Errorf ("currency: %w" , err ))
178- }
179- if r .VoidedAt .IsZero () {
180- errs = append (errs , errors .New ("voided at is required" ))
181- }
182- if r .SourceChargeID == "" {
183- errs = append (errs , errors .New ("source charge id is required" ))
184- }
185- if r .VoidTransactionGroupID == "" {
186- errs = append (errs , errors .New ("void transaction group id is required" ))
187- }
188- if r .VoidTransactionID == "" {
189- errs = append (errs , errors .New ("void transaction id is required" ))
190- }
191- if r .FBOSubAccountID == "" {
192- errs = append (errs , errors .New ("FBO sub-account id is required" ))
193- }
194- if r .ReceivableSubAccountID == "" {
195- errs = append (errs , errors .New ("receivable sub-account id is required" ))
196- }
197-
198- return errors .Join (errs ... )
199- }
200-
201- type ListRecordsInput struct {
202- CustomerID customer.CustomerID
203- Currency * currencyx.Code
204- AsOf time.Time
205- Route ledger.RouteFilter
206- }
207-
208124type ListVoidedCreditImpactsInput struct {
209125 CustomerID customer.CustomerID
210126 Currency * currencyx.Code
@@ -275,11 +191,6 @@ func (i VoidImpact) Cursor() ledger.TransactionCursor {
275191 }
276192}
277193
278- type Adapter interface {
279- CreateRecords (ctx context.Context , input CreateRecordsInput ) error
280- ListRecords (ctx context.Context , input ListRecordsInput ) ([]Record , error )
281- }
282-
283194// voidPlan is the read-only outcome of the planning step: the concrete
284195// remaining balance slices to forfeit, each with the open expiry breakage plan
285196// it must release.
@@ -414,7 +325,7 @@ func (s *service) executeVoid(ctx context.Context, input VoidCreditPurchaseInput
414325 var (
415326 inputs []ledger.TransactionInput
416327 pendingBreakage []breakage.PendingRecord
417- pendingVoidRecords []PendingRecord
328+ pendingVoidRecords []pendingVoidRecord
418329 )
419330 amount := alpacadecimal .Zero
420331
@@ -476,13 +387,13 @@ func (s *service) executeVoid(ctx context.Context, input VoidCreditPurchaseInput
476387 }, nil
477388}
478389
479- func (s * service ) resolveVoidSlice (ctx context.Context , input VoidCreditPurchaseInput , voidedAt time.Time , slice voidSlice ) (ledger.TransactionInput , PendingRecord , error ) {
390+ func (s * service ) resolveVoidSlice (ctx context.Context , input VoidCreditPurchaseInput , voidedAt time.Time , slice voidSlice ) (ledger.TransactionInput , pendingVoidRecord , error ) {
480391 recordID := newRecordID (input .CustomerID .Namespace )
481392 route := slice .fboAddress .Route ().Route ()
482393
483394 issueTx , err := s .originalIssueTransaction (ctx , input , voidedAt , slice )
484395 if err != nil {
485- return nil , PendingRecord {}, err
396+ return nil , pendingVoidRecord {}, err
486397 }
487398
488399 inputs , err := transactions .CorrectTransaction (ctx , s .deps , transactions.CorrectionInput {
@@ -491,21 +402,21 @@ func (s *service) resolveVoidSlice(ctx context.Context, input VoidCreditPurchase
491402 OriginalTransaction : issueTx ,
492403 })
493404 if err != nil {
494- return nil , PendingRecord {}, fmt .Errorf ("resolve issue correction: %w" , err )
405+ return nil , pendingVoidRecord {}, fmt .Errorf ("resolve issue correction: %w" , err )
495406 }
496407 if len (inputs ) != 1 {
497- return nil , PendingRecord {}, fmt .Errorf ("expected one issue correction transaction input, got %d" , len (inputs ))
408+ return nil , pendingVoidRecord {}, fmt .Errorf ("expected one issue correction transaction input, got %d" , len (inputs ))
498409 }
499410
500411 correctedFBO , correctedReceivable , err := correctionEntrySubAccounts (inputs [0 ])
501412 if err != nil {
502- return nil , PendingRecord {}, err
413+ return nil , pendingVoidRecord {}, err
503414 }
504415 if correctedFBO != slice .fboAddress .SubAccountID () {
505- return nil , PendingRecord {}, fmt .Errorf ("issue correction FBO sub-account %s does not match voided FBO sub-account %s" , correctedFBO , slice .fboAddress .SubAccountID ())
416+ return nil , pendingVoidRecord {}, fmt .Errorf ("issue correction FBO sub-account %s does not match voided FBO sub-account %s" , correctedFBO , slice .fboAddress .SubAccountID ())
506417 }
507418
508- record := PendingRecord { Record : Record {
419+ record := pendingVoidRecord {
509420 ID : recordID ,
510421 Amount : slice .amount ,
511422 CustomerID : input .CustomerID ,
@@ -514,7 +425,7 @@ func (s *service) resolveVoidSlice(ctx context.Context, input VoidCreditPurchase
514425 SourceChargeID : input .ChargeID ,
515426 FBOSubAccountID : correctedFBO ,
516427 ReceivableSubAccountID : correctedReceivable ,
517- }}
428+ }
518429
519430 return transactions .WithAnnotations (inputs [0 ], creditVoidRecordAnnotations (recordID .ID )), record , nil
520431}
@@ -627,15 +538,15 @@ func correctionEntrySubAccounts(input ledger.TransactionInput) (string, string,
627538 return fboSubAccountID , receivableSubAccountID , nil
628539}
629540
630- func (s * service ) persistCommittedVoidRecords (ctx context.Context , pending []PendingRecord , group ledger.TransactionGroup ) error {
541+ func (s * service ) persistCommittedVoidRecords (ctx context.Context , pending []pendingVoidRecord , group ledger.TransactionGroup ) error {
631542 if len (pending ) == 0 {
632543 return nil
633544 }
634545 if group == nil {
635546 return errors .New ("transaction group is required" )
636547 }
637548
638- pendingByID := make (map [string ]PendingRecord , len (pending ))
549+ pendingByID := make (map [string ]pendingVoidRecord , len (pending ))
639550 for _ , item := range pending {
640551 pendingByID [item .ID .ID ] = item
641552 }
@@ -653,10 +564,7 @@ func (s *service) persistCommittedVoidRecords(ctx context.Context, pending []Pen
653564 return fmt .Errorf ("committed void transaction %s has unknown record id %s" , tx .ID ().ID , recordID )
654565 }
655566
656- record := pendingRecord .Record
657- record .VoidTransactionGroupID = groupID
658- record .VoidTransactionID = tx .ID ().ID
659- record .Annotations = tx .Annotations ()
567+ record := pendingRecord .committed (groupID , tx .ID ().ID , tx .Annotations ())
660568
661569 records = append (records , record )
662570 delete (pendingByID , recordID )
0 commit comments