@@ -70,7 +70,7 @@ func (p *EventsProcessor) EventsFromLedger(lcm xdr.LedgerCloseMeta) ([]*TokenTra
70
70
}
71
71
txEvents , err = p .EventsFromTransaction (tx )
72
72
if err != nil {
73
- return nil , fmt . Errorf ( "error processing token transfer events from transaction: %w" , err )
73
+ return nil , err
74
74
}
75
75
events = append (events , txEvents ... )
76
76
}
@@ -105,8 +105,7 @@ func (p *EventsProcessor) EventsFromTransaction(tx ingest.LedgerTransaction) ([]
105
105
// Process the operation and collect events
106
106
opEvents , err := p .EventsFromOperation (tx , uint32 (i ), op , opResult )
107
107
if err != nil {
108
- return nil ,
109
- fmt .Errorf ("error processing token transfer events from operation, index: %d, %s: %w" , i , op .Body .Type .String (), err )
108
+ return nil , err
110
109
}
111
110
112
111
events = append (events , opEvents ... )
@@ -167,7 +166,7 @@ func (p *EventsProcessor) EventsFromOperation(tx ingest.LedgerTransaction, opInd
167
166
}
168
167
169
168
if err != nil {
170
- return nil , err
169
+ return nil , formatError ( err , tx , opIndex , op )
171
170
}
172
171
173
172
// DO not run this reconciliation check for ledgers with protocol version >= 8
@@ -178,7 +177,7 @@ func (p *EventsProcessor) EventsFromOperation(tx ingest.LedgerTransaction, opInd
178
177
// Run reconciliation for all operations except InvokeHostFunction
179
178
reconciliationEvent , err := p .generateXlmReconciliationEvents (tx , opIndex , op , events )
180
179
if err != nil {
181
- return nil , fmt .Errorf ("error generating reconciliation events: %w" , err )
180
+ return nil , formatError ( fmt .Errorf ("error generating reconciliation events: %w" , err ), tx , opIndex , op )
182
181
}
183
182
184
183
if reconciliationEvent != nil {
@@ -189,7 +188,7 @@ func (p *EventsProcessor) EventsFromOperation(tx ingest.LedgerTransaction, opInd
189
188
// If it is a burn, put the burn event at the end of the list of other events for this operation
190
189
events = append (events , reconciliationEvent )
191
190
} else {
192
- return nil , fmt .Errorf ("invalid reconciliation event type: %v. reconciliation event type can be only mint or burn" , reconciliationEvent .GetEventType ())
191
+ return nil , formatError ( fmt .Errorf ("invalid reconciliation event type: %v. reconciliation event type can be only mint or burn" , reconciliationEvent .GetEventType ()), tx , opIndex , op )
193
192
}
194
193
}
195
194
@@ -210,16 +209,15 @@ Those 2 will call the underlying proto function for clawback
210
209
*/
211
210
func (p * EventsProcessor ) mintOrBurnOrTransferEvent (tx ingest.LedgerTransaction , opIndex * uint32 , asset xdr.Asset , from addressWrapper , to addressWrapper , amt string ) (* TokenTransferEvent , error ) {
212
211
var fromAddress , toAddress string
213
- // no need to have a separate flag for transferEvent. if neither burn nor mint, then it is regular transfer
214
- var isMintEvent , isBurnEvent bool
212
+ var isFromIssuer , isToIssuer bool
215
213
216
214
assetIssuerAccountId , _ := asset .GetIssuerAccountId ()
217
215
218
216
// Checking 'from' address
219
217
if from .account != nil {
220
218
fromAddress = protoAddressFromAccount (* from .account )
221
219
if ! asset .IsNative () && assetIssuerAccountId .Equals (from .account .ToAccountId ()) {
222
- isMintEvent = true
220
+ isFromIssuer = true
223
221
}
224
222
} else if from .liquidityPoolId != nil {
225
223
fromAddress = lpIdToStrkey (* from .liquidityPoolId )
@@ -231,7 +229,7 @@ func (p *EventsProcessor) mintOrBurnOrTransferEvent(tx ingest.LedgerTransaction,
231
229
if to .account != nil {
232
230
toAddress = protoAddressFromAccount (* to .account )
233
231
if ! asset .IsNative () && assetIssuerAccountId .Equals (to .account .ToAccountId ()) {
234
- isBurnEvent = true
232
+ isToIssuer = true
235
233
}
236
234
} else if to .liquidityPoolId != nil {
237
235
toAddress = lpIdToStrkey (* to .liquidityPoolId )
@@ -245,18 +243,18 @@ func (p *EventsProcessor) mintOrBurnOrTransferEvent(tx ingest.LedgerTransaction,
245
243
// This means that the payment is a wierd one, where the src == dest AND in addition, the src/dest address is the issuer of the asset
246
244
// Check this section out in CAP-67 https://github.com/stellar/stellar-protocol/blob/master/core/cap-0067.md#payment
247
245
// We need to issue a TRANSFER event for this.
248
- // Keep in mind though that this wont show up in opeartionMeta as a balance change
246
+ // Keep in mind though that this wont show up in operationMeta as a balance change
249
247
// This has happened in ledgerSequence: 4522126 on pubnet
250
- if isMintEvent && isBurnEvent {
248
+ if isFromIssuer && isToIssuer {
251
249
return NewTransferEvent (meta , fromAddress , toAddress , amt , protoAsset ), nil
252
- } else if isMintEvent {
250
+ } else if isFromIssuer {
253
251
254
252
// Check for Mint Event
255
253
if toAddress == "" {
256
254
return nil , NewEventError ("mint event error: to address is nil" )
257
255
}
258
256
return NewMintEvent (meta , toAddress , amt , protoAsset ), nil
259
- } else if isBurnEvent {
257
+ } else if isToIssuer {
260
258
261
259
// Check for Burn Event
262
260
if fromAddress == "" {
@@ -265,6 +263,12 @@ func (p *EventsProcessor) mintOrBurnOrTransferEvent(tx ingest.LedgerTransaction,
265
263
return NewBurnEvent (meta , fromAddress , amt , protoAsset ), nil
266
264
}
267
265
266
+ if fromAddress == "" {
267
+ return nil , NewEventError ("transfer event error: from address is nil" )
268
+ }
269
+ if toAddress == "" {
270
+ return nil , NewEventError ("transfer event error: to address is nil" )
271
+ }
268
272
// Create transfer event
269
273
return NewTransferEvent (meta , fromAddress , toAddress , amt , protoAsset ), nil
270
274
}
@@ -598,11 +602,11 @@ func (p *EventsProcessor) liquidityPoolDepositEvents(tx ingest.LedgerTransaction
598
602
amtA , amtB := delta .amountChangeForAssetA , delta .amountChangeForAssetB
599
603
if amtA <= 0 {
600
604
return nil ,
601
- fmt .Errorf ("deposited amount (%v) for asset: %v, cannot be zero or negative in LiquidityPool: %v" , amtA , assetA .String (), lpIdToStrkey (lpId ))
605
+ fmt .Errorf ("deposited amount (%v) for asset: %v, cannot be zero or negative for LiquidityPool: %v" , amtA , assetA .String (), lpIdToStrkey (lpId ))
602
606
}
603
607
if amtB <= 0 {
604
608
return nil ,
605
- fmt .Errorf ("deposited amount (%v) for asset: %v, cannot be zero or negative in LiquidityPool: %v" , amtB , assetB .String (), lpIdToStrkey (lpId ))
609
+ fmt .Errorf ("deposited amount (%v) for asset: %v, cannot be zero or negative for LiquidityPool: %v" , amtB , assetB .String (), lpIdToStrkey (lpId ))
606
610
}
607
611
608
612
opSrcAcc := operationSourceAccount (tx , op )
@@ -639,13 +643,19 @@ func (p *EventsProcessor) liquidityPoolWithdrawEvents(tx ingest.LedgerTransactio
639
643
lpId := delta .liquidityPoolId
640
644
assetA , assetB := delta .assetA , delta .assetB
641
645
amtA , amtB := delta .amountChangeForAssetA , delta .amountChangeForAssetB
642
- if amtA <= 0 {
646
+ /*
647
+ This is slightly different from the LpDeposit operation check. In LpDeposit, if amt <=0: then error
648
+ However, for LpWithdraw, the check is if amt < 0: then error.
649
+ This is because, the rounding on withdraw could result in nothing being withdrawn
650
+ Refer https://github.com/sisuresh/stellar-protocol/blob/unified/core/cap-0038.md#price-bounds-for-liquiditypoolwithdrawop
651
+ */
652
+ if amtA < 0 {
643
653
return nil ,
644
- fmt .Errorf ("deposited amount (%v) for asset: %v, cannot be zero or negative in LiquidityPool: %v" , amtA , assetA .String (), lpIdToStrkey (lpId ))
654
+ fmt .Errorf ("withdrawn amount (%v) for asset: %v, cannot be negative for LiquidityPool: %v" , amtA , assetA .String (), lpIdToStrkey (lpId ))
645
655
}
646
- if amtB <= 0 {
656
+ if amtB < 0 {
647
657
return nil ,
648
- fmt .Errorf ("deposited amount (%v) for asset: %v, cannot be zero or negative in LiquidityPool: %v" , amtB , assetB .String (), lpIdToStrkey (lpId ))
658
+ fmt .Errorf ("withdrawn amount (%v) for asset: %v, cannot be negative for LiquidityPool: %v" , amtB , assetB .String (), lpIdToStrkey (lpId ))
649
659
}
650
660
651
661
opSrcAcc := operationSourceAccount (tx , op )
0 commit comments