Skip to content

Commit

Permalink
Add LCM and transaction info altogether in change entry
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikiyer56 committed Nov 21, 2024
1 parent 26780fa commit b168415
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
13 changes: 7 additions & 6 deletions ingest/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import (
// If an entry is removed: Pre is not nil and Post is nil.
// If this change is caused by a operation in a transaction, include the operation information. Wont work when changes are compacted
type Change struct {
Type xdr.LedgerEntryType
Pre *xdr.LedgerEntry
Post *xdr.LedgerEntry
reason LedgerEntryChangeReason
TransactionData *TransactionEnvelopeAndResult
operationInfo *OperationInfo
Type xdr.LedgerEntryType
Pre *xdr.LedgerEntry
Post *xdr.LedgerEntry
Reason LedgerEntryChangeReason
operationIdx uint32
tx *LedgerTransaction
lcm *xdr.LedgerCloseMeta
}

type LedgerEntryChangeReason uint16
Expand Down
6 changes: 4 additions & 2 deletions ingest/ledger_change_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ func (r *LedgerChangeReader) Read() (Change, error) {
Type: entry.Data.Type,
Pre: &entry,
Post: nil,
reason: Eviction,
Reason: Eviction,
lcm: &r.lcm,
}
}
sortChanges(changes)
Expand All @@ -202,7 +203,8 @@ func (r *LedgerChangeReader) Read() (Change, error) {
r.LedgerTransactionReader.lcm.UpgradesProcessing()[r.upgradeIndex].Changes,
)
for _, change := range changes {
change.reason = ProtocolUpgrade // Is there any other information that we can add here?
change.Reason = ProtocolUpgrade // Is there any other information that we can add here?
change.lcm = &r.lcm
}
r.pending = append(r.pending, changes...)
r.upgradeIndex++
Expand Down
33 changes: 12 additions & 21 deletions ingest/ledger_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type LedgerTransaction struct {
FeeChanges xdr.LedgerEntryChanges
UnsafeMeta xdr.TransactionMeta
LedgerVersion uint32
lcm *xdr.LedgerCloseMeta // This is read-only and not to be modified by downstream functions
}

func (t *LedgerTransaction) txInternalError() bool {
Expand All @@ -27,10 +28,10 @@ func (t *LedgerTransaction) txInternalError() bool {
// connected to fees.
func (t *LedgerTransaction) GetFeeChanges() []Change {
changes := GetChangesFromLedgerEntryChanges(t.FeeChanges)
txData := &TransactionEnvelopeAndResult{Envelope: &t.Envelope, Result: &t.Result}
for _, change := range changes {
change.reason = FeeChange
change.TransactionData = txData
change.Reason = FeeChange
change.tx = t
change.lcm = t.lcm
}
return changes
}
Expand All @@ -42,10 +43,10 @@ func (t *LedgerTransaction) GetFeeChanges() []Change {

func (t *LedgerTransaction) getTransactionChanges(ledgerEntryChanges xdr.LedgerEntryChanges) []Change {
changes := GetChangesFromLedgerEntryChanges(ledgerEntryChanges)
txData := &TransactionEnvelopeAndResult{Envelope: &t.Envelope, Result: &t.Result}
for _, change := range changes {
change.reason = Transaction
change.TransactionData = txData
change.Reason = Transaction
change.tx = t
change.lcm = t.lcm
}
return changes
}
Expand Down Expand Up @@ -169,24 +170,14 @@ func (t *LedgerTransaction) operationChanges(ops []xdr.OperationMeta, index uint

operationMeta := ops[index]
changes := GetChangesFromLedgerEntryChanges(operationMeta.Changes)
op, found := t.GetOperation(index)
operationInfo := &OperationInfo{
operationIdx: index,
operation: &op,
}
txData := &TransactionEnvelopeAndResult{Envelope: &t.Envelope, Result: &t.Result}

res := make([]Change, 0, len(changes))
for _, change := range changes {
if !found {
continue
}
change.operationInfo = operationInfo
change.reason = Operation
change.TransactionData = txData
res = append(res, change)
change.Reason = Operation
change.tx = t
change.operationIdx = index
change.lcm = t.lcm
}
return res
return changes
}

// GetDiagnosticEvents returns all contract events emitted by a given operation.
Expand Down
1 change: 1 addition & 0 deletions ingest/ledger_transaction_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (reader *LedgerTransactionReader) Read() (LedgerTransaction, error) {
UnsafeMeta: reader.lcm.TxApplyProcessing(i),
FeeChanges: reader.lcm.FeeProcessing(i),
LedgerVersion: uint32(reader.lcm.LedgerHeaderHistoryEntry().Header.LedgerVersion),
lcm: &reader.lcm,
}, nil
}

Expand Down

0 comments on commit b168415

Please sign in to comment.