@@ -2,6 +2,7 @@ package mixins
22
33import (
44 "context"
5+ "encoding/json"
56 "fmt"
67 "strings"
78 "time"
@@ -309,11 +310,12 @@ func (pt *PastelHandler) ValidateBurnTxID(ctx context.Context, burnTxnID string,
309310
310311 confirmationChn := pt .WaitConfirmation (ctx , burnTxnID ,
311312 burnTxnConfirmations , 15 * time .Second , true , estimatedFee , burnTxnPercentage )
312- log . WithContext ( ctx ). Debug ( "waiting for confirmation" )
313+
313314 select {
314315 case retErr := <- confirmationChn :
315316 if retErr != nil {
316- log .WithContext (ctx ).WithError (retErr ).Errorf ("validate preburn transaction validation" )
317+ log .WithContext (ctx ).WithError (retErr ).WithField ("txn-id" , burnTxnID ).WithField ("fee" , estimatedFee ).
318+ WithField ("percentage" , burnTxnPercentage ).Error ("validate preburn transaction validation" )
317319 err = errors .Errorf ("validate preburn transaction validation :%w" , retErr )
318320 return err
319321 }
@@ -359,27 +361,30 @@ func (pt *PastelHandler) verifyTxn(ctx context.Context,
359361 }
360362
361363 log .WithContext (ctx ).Debug ("Verifying Burn Txn" )
362- isTxnAmountOk := false
363364 isTxnAddressOk := false
364365
365366 reqBurnAmount := totalAmt * percent / 100
366367 for _ , vout := range txn .Vout {
367- if inRange (vout .Value , reqBurnAmount , 2.0 ) {
368- isTxnAmountOk = true
369- for _ , addr := range vout .ScriptPubKey .Addresses {
370- if addr == pt .GetBurnAddress () {
371- isTxnAddressOk = true
372- }
368+ for _ , addr := range vout .ScriptPubKey .Addresses {
369+ if addr == pt .GetBurnAddress () {
370+ isTxnAddressOk = true
373371 }
374372 }
375- }
376373
377- if ! isTxnAmountOk {
378- return fmt .Errorf ("invalid txn amount: %v, required amount: %f" , txn .Vout , reqBurnAmount )
374+ if isTxnAddressOk {
375+ if ! inRange (vout .Value , reqBurnAmount , 2.0 ) {
376+ data , _ := json .Marshal (txn )
377+ return fmt .Errorf ("invalid transaction amount: %v, required minimum amount: %f - raw transaction details: %s" , vout .Value , reqBurnAmount , string (data ))
378+ }
379+
380+ break
381+ }
379382 }
380383
381384 if ! isTxnAddressOk {
382- return fmt .Errorf ("invalid txn address %s" , pt .GetBurnAddress ())
385+ data , _ := json .Marshal (txn )
386+ return fmt .Errorf ("invalid txn address -- correct address: %s - rawTxnData: %s - total-amount: %f - req-burn-amount: %f" ,
387+ pt .GetBurnAddress (), string (data ), totalAmt , reqBurnAmount )
383388 }
384389
385390 return nil
@@ -422,7 +427,7 @@ func (pt *PastelHandler) WaitConfirmation(ctx context.Context, txid string, minC
422427 if txResult .Confirmations >= minConfirmation {
423428 if verifyBurnAmt {
424429 if err := pt .verifyTxn (ctx , txResult , totalAmt , percent ); err != nil {
425- log .WithContext (ctx ).WithError (err ).Error ("txn verification failed" )
430+ log .WithContext (ctx ).WithField ( "txid" , txid ). WithError (err ).Error ("txn verification failed" )
426431 ch <- err
427432 return
428433 }
0 commit comments