diff --git a/txcache/wrappedTransaction.go b/txcache/wrappedTransaction.go index 499c695e..d66ddb39 100644 --- a/txcache/wrappedTransaction.go +++ b/txcache/wrappedTransaction.go @@ -24,6 +24,7 @@ type WrappedTransaction struct { Fee *big.Int PricePerUnit uint64 TransferredValue *big.Int + FeePayer []byte } // precomputeFields computes (and caches) the (average) price per gas unit. @@ -36,6 +37,16 @@ func (wrappedTx *WrappedTransaction) precomputeFields(host MempoolHost) { } wrappedTx.TransferredValue = host.GetTransferredValue(wrappedTx.Tx) + wrappedTx.FeePayer = wrappedTx.decideFeePayer() +} + +func (wrappedTx *WrappedTransaction) decideFeePayer() []byte { + asRelayed, ok := wrappedTx.Tx.(data.RelayedTransactionHandler) + if ok && len(asRelayed.GetRelayerAddr()) > 0 { + return asRelayed.GetRelayerAddr() + } + + return wrappedTx.Tx.GetSndAddr() } // Equality is out of scope (not possible in our case). diff --git a/txcache/wrappedTransaction_test.go b/txcache/wrappedTransaction_test.go index 398c97b2..574960a9 100644 --- a/txcache/wrappedTransaction_test.go +++ b/txcache/wrappedTransaction_test.go @@ -19,6 +19,7 @@ func TestWrappedTransaction_precomputeFields(t *testing.T) { require.Equal(t, "51500000000000", tx.Fee.String()) require.Equal(t, oneBillion, int(tx.PricePerUnit)) require.Equal(t, "1000000000000000000", tx.TransferredValue.String()) + require.Equal(t, []byte("a"), tx.FeePayer) }) t.Run("move balance gas limit and execution gas limit (a)", func(t *testing.T) { @@ -29,6 +30,7 @@ func TestWrappedTransaction_precomputeFields(t *testing.T) { require.Equal(t, "51500010000000", tx.Fee.String()) require.Equal(t, 999_980_777, int(tx.PricePerUnit)) + require.Equal(t, []byte("b"), tx.FeePayer) }) t.Run("move balance gas limit and execution gas limit (b)", func(t *testing.T) { @@ -41,6 +43,7 @@ func TestWrappedTransaction_precomputeFields(t *testing.T) { require.Equal(t, "60985000000000", tx.Fee.String()) require.Equal(t, 60_985_000_000_000, actualFee) require.Equal(t, actualFee/oneMilion, int(tx.PricePerUnit)) + require.Equal(t, []byte("c"), tx.FeePayer) }) t.Run("with guardian", func(t *testing.T) { @@ -52,6 +55,7 @@ func TestWrappedTransaction_precomputeFields(t *testing.T) { require.Equal(t, "50000000000000", tx.Fee.String()) require.Equal(t, oneBillion, int(tx.PricePerUnit)) require.Equal(t, "1000000000000000000", tx.TransferredValue.String()) + require.Equal(t, []byte("a"), tx.FeePayer) }) t.Run("with nil transferred value", func(t *testing.T) { @@ -61,6 +65,7 @@ func TestWrappedTransaction_precomputeFields(t *testing.T) { tx.precomputeFields(host) require.Nil(t, tx.TransferredValue) + require.Equal(t, []byte("a"), tx.FeePayer) }) t.Run("queries host", func(t *testing.T) {