diff --git a/ingest/ledger_transaction.go b/ingest/ledger_transaction.go index 6f62579318..18b2b53024 100644 --- a/ingest/ledger_transaction.go +++ b/ingest/ledger_transaction.go @@ -32,6 +32,10 @@ func (t *LedgerTransaction) txInternalError() bool { return t.Result.Result.Result.Code == xdr.TransactionResultCodeTxInternalError } +func (t *LedgerTransaction) FeeAccount() xdr.MuxedAccount { + return t.Envelope.FeeAccount() +} + // GetFeeChanges returns a developer friendly representation of LedgerEntryChanges // connected to fees. func (t *LedgerTransaction) GetFeeChanges() []Change { diff --git a/ingest/processors/token_transfer/token_transfer_processor.go b/ingest/processors/token_transfer/token_transfer_processor.go index 5bed32f59c..210c7123a6 100644 --- a/ingest/processors/token_transfer/token_transfer_processor.go +++ b/ingest/processors/token_transfer/token_transfer_processor.go @@ -108,22 +108,17 @@ func ProcessTokenTransferEventsFromOperation(tx ingest.LedgerTransaction, opInde } func generateFeeEvent(tx ingest.LedgerTransaction) ([]*TokenTransferEvent, error) { - var events []*TokenTransferEvent - feeChanges := tx.GetFeeChanges() - for _, change := range feeChanges { - if change.Type != xdr.LedgerEntryTypeAccount { - return nil, errors.Errorf("invalid ledgerEntryType for fee change: %s", change.Type.String()) - } - - // Do I need to do all this? Can I not simply use tx.Result.Result.FeeCharged - preBalance := change.Pre.Data.MustAccount().Balance - postBalance := change.Post.Data.MustAccount().Balance - accId := change.Pre.Data.MustAccount().AccountId - amt := amount.String(postBalance - preBalance) - event := NewFeeEvent(tx.Ledger.LedgerSequence(), tx.Ledger.ClosedAt(), tx.Hash.HexString(), protoAddressFromAccountId(accId), amt, assetProto.NewNativeAsset()) - events = append(events, event) - } - return events, nil + /* + For a feeBump transaction, this will be the outer transaction. + FeeAccount() gives the proper "muxed" account that paid the fees. + And we want the "muxed" Account, so that it can be passed directly to protoAddressFromAccount + */ + feeAccount := tx.FeeAccount() + // FeeCharged() takes care of a bug in an intermediate protocol release. So using that + feeAmt, _ := tx.FeeCharged() + + event := NewFeeEvent(tx.Ledger.LedgerSequence(), tx.Ledger.ClosedAt(), tx.Hash.HexString(), protoAddressFromAccount(feeAccount), amount.String(xdr.Int64(feeAmt)), assetProto.NewNativeAsset()) + return []*TokenTransferEvent{event}, nil } // Function stubs diff --git a/xdr/transaction_envelope.go b/xdr/transaction_envelope.go index 2cde059e5a..d48c052ea4 100644 --- a/xdr/transaction_envelope.go +++ b/xdr/transaction_envelope.go @@ -39,6 +39,15 @@ func (e TransactionEnvelope) SourceAccount() MuxedAccount { } } +func (e TransactionEnvelope) FeeAccount() MuxedAccount { + switch e.Type { + case EnvelopeTypeEnvelopeTypeTxFeeBump: + return e.FeeBumpAccount() + default: + return e.SourceAccount() + } +} + // Fee returns the fee defined for the transaction envelope // If the transaction envelope is for a fee bump transaction, Fee() // returns the fee defined in the inner transaction