@@ -59,6 +59,8 @@ type TxManager[CID chains.ID, HEAD chains.Head[BHASH], ADDR chains.Hashable, THA
5959 CountTransactionsByState (ctx context.Context , state txmgrtypes.TxState ) (count uint32 , err error )
6060 GetTransactionStatus (ctx context.Context , transactionID string ) (state commontypes.TransactionStatus , err error )
6161 GetTransactionFee (ctx context.Context , transactionID string ) (fee * evmtypes.TransactionFee , err error )
62+ GetTransactionReceipt (ctx context.Context , transactionID string ) (receipt * txmgrtypes.ChainReceipt [THASH , BHASH ], err error )
63+ CalculateFee (feeParts FeeParts ) * big.Int
6264}
6365
6466type TxmV2Wrapper [CID chains.ID , HEAD chains.Head [BHASH ], ADDR chains.Hashable , THASH chains.Hashable , BHASH chains.Hashable , SEQ chains.Sequence , FEE fees.Fee ] interface {
@@ -733,33 +735,53 @@ func (b *Txm[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) GetTransactionStatus(c
733735}
734736
735737func (b * Txm [CID , HEAD , ADDR , THASH , BHASH , R , SEQ , FEE ]) GetTransactionFee (ctx context.Context , transactionID string ) (fee * evmtypes.TransactionFee , err error ) {
736- receipt , err := b .txStore .FindReceiptWithIdempotencyKey (ctx , transactionID , b .chainID )
737- if err != nil {
738- return fee , fmt .Errorf ("failed to find receipt with IdempotencyKey %s: %w" , transactionID , err )
738+ receipt , err := b .GetTransactionReceipt (ctx , transactionID )
739+
740+ txFee := b .CalculateFee (FeeParts {
741+ GasUsed : receipt .GetFeeUsed (),
742+ EffectiveGasPrice : receipt .GetEffectiveGasPrice (),
743+ L1Fee : receipt .GetL1Fee (),
744+ })
745+
746+ fee = & evmtypes.TransactionFee {
747+ TransactionFee : txFee ,
739748 }
740749
750+ return fee , nil
751+ }
752+
753+ func (b * Txm [CID , HEAD , ADDR , THASH , BHASH , R , SEQ , FEE ]) GetTransactionReceipt (ctx context.Context , transactionID string ) (receipt txmgrtypes.ChainReceipt [THASH , BHASH ], err error ) {
754+ foundReceipt , err := b .txStore .FindReceiptWithIdempotencyKey (ctx , transactionID , b .chainID )
755+ if err != nil {
756+ return nil , fmt .Errorf ("failed to find receipt with IdempotencyKey %s: %w" , transactionID , err )
757+ }
741758 // This check is required since a no-rows error returns nil err
742- if receipt == nil {
743- return fee , fmt .Errorf ("failed to find receipt with IdempotencyKey %s" , transactionID )
759+ if foundReceipt == nil {
760+ return nil , fmt .Errorf ("failed to find receipt with IdempotencyKey %s" , transactionID )
744761 }
762+ return foundReceipt , nil
763+ }
745764
765+ type FeeParts struct {
766+ GasUsed uint64
767+ EffectiveGasPrice * big.Int
768+ L1Fee * big.Int
769+ }
770+
771+ func (b * Txm [CID , HEAD , ADDR , THASH , BHASH , R , SEQ , FEE ]) CalculateFee (feeParts FeeParts ) * big.Int {
746772 totalFee := new (big.Int )
747773
748- gasUsed := new (big.Int ).SetUint64 (receipt . GetFeeUsed () )
749- price := receipt . GetEffectiveGasPrice ()
774+ gasUsed := new (big.Int ).SetUint64 (feeParts . GasUsed )
775+ price := feeParts . EffectiveGasPrice
750776 if price != nil {
751777 totalFee .Mul (gasUsed , price )
752778 }
753- l1Fee := receipt . GetL1Fee ()
779+ l1Fee := feeParts . L1Fee
754780 if l1Fee != nil {
755781 totalFee .Add (totalFee , l1Fee )
756782 }
757783
758- fee = & evmtypes.TransactionFee {
759- TransactionFee : totalFee ,
760- }
761-
762- return fee , nil
784+ return totalFee
763785}
764786
765787// Deprecated: use txmgrtest.ErrTxManager
@@ -847,6 +869,14 @@ func (n *NullTxManager[CID, HEAD, ADDR, THASH, BHASH, SEQ, FEE]) GetTransactionF
847869 return
848870}
849871
872+ func (n * NullTxManager [CID , HEAD , ADDR , THASH , BHASH , SEQ , FEE ]) CalculateFee (feeParts FeeParts ) * big.Int {
873+ return nil
874+ }
875+
876+ func (n * NullTxManager [CID , HEAD , ADDR , THASH , BHASH , SEQ , FEE ]) GetTransactionReceipt (ctx context.Context , transactionID string ) (receipt * txmgrtypes.ChainReceipt [THASH , BHASH ], err error ) {
877+ return
878+ }
879+
850880func (b * Txm [CID , HEAD , ADDR , THASH , BHASH , R , SEQ , FEE ]) pruneQueueAndCreateTxn (
851881 ctx context.Context ,
852882 txRequest txmgrtypes.TxRequest [ADDR , THASH ],
0 commit comments