@@ -532,8 +532,6 @@ func (m *Client) TransferETHFromKey(ctx context.Context, fromKeyNum int, to stri
532532 fromKeyNum , m .Addresses [fromKeyNum ].Hex (), err )
533533 }
534534
535- ctx , sendCancel := context .WithTimeout (ctx , m .Cfg .Network .TxnTimeout .Duration ())
536- defer sendCancel ()
537535 err = m .Client .SendTransaction (ctx , signedTx )
538536 if err != nil {
539537 return fmt .Errorf ("failed to send transaction to network: %w\n " +
@@ -1345,12 +1343,13 @@ func (t TransactionLog) GetData() []byte {
13451343 return t .Data
13461344}
13471345
1348- func (m * Client ) decodeContractLogs (l zerolog.Logger , logs []types.Log , allABIs []* abi.ABI ) ([]DecodedTransactionLog , error ) {
1346+ func (m * Client ) decodeContractLogs (l zerolog.Logger , logs []types.Log , allABIs []* abi.ABI ) ([]DecodedTransactionLog , [] EventDecodingError , error ) {
13491347 l .Trace ().
13501348 Msg ("Decoding events" )
13511349 sigMap := buildEventSignatureMap (allABIs )
13521350
13531351 var eventsParsed []DecodedTransactionLog
1352+ var decodeErrors []EventDecodingError
13541353 for _ , lo := range logs {
13551354 if len (lo .Topics ) == 0 {
13561355 l .Debug ().
@@ -1384,6 +1383,7 @@ func (m *Client) decodeContractLogs(l zerolog.Logger, logs []types.Log, allABIs
13841383
13851384 // Iterate over possible events with the same signature
13861385 matched := false
1386+ var decodeAttempts []ABIDecodingError
13871387 for _ , evWithABI := range possibleEvents {
13881388 evSpec := evWithABI .EventSpec
13891389 contractABI := evWithABI .ContractABI
@@ -1421,19 +1421,28 @@ func (m *Client) decodeContractLogs(l zerolog.Logger, logs []types.Log, allABIs
14211421 }
14221422
14231423 // Proceed to decode the event
1424+ // Find ABI name for this contract ABI
1425+ abiName := m .findABIName (contractABI )
14241426 d := TransactionLog {lo .Topics , lo .Data }
14251427 l .Trace ().
14261428 Str ("Name" , evSpec .RawName ).
14271429 Str ("Signature" , evSpec .Sig ).
1430+ Str ("ABI" , abiName ).
14281431 Msg ("Unpacking event" )
14291432
14301433 eventsMap , topicsMap , err := decodeEventFromLog (l , * contractABI , * evSpec , d )
14311434 if err != nil {
1432- l .Error ().
1435+ l .Debug ().
14331436 Err (err ).
14341437 Str ("Event" , evSpec .Name ).
1435- Msg ("Failed to decode event; skipping" )
1436- continue // Skip this event instead of returning an error
1438+ Str ("ABI" , abiName ).
1439+ Msg ("Failed to decode event; trying next ABI" )
1440+ decodeAttempts = append (decodeAttempts , ABIDecodingError {
1441+ ABIName : abiName ,
1442+ EventName : evSpec .Name ,
1443+ Error : err .Error (),
1444+ })
1445+ continue // Try next ABI instead of giving up
14371446 }
14381447
14391448 parsedEvent := decodedLogFromMaps (& DecodedTransactionLog {}, eventsMap , topicsMap )
@@ -1455,12 +1464,36 @@ func (m *Client) decodeContractLogs(l zerolog.Logger, logs []types.Log, allABIs
14551464 }
14561465
14571466 if ! matched {
1467+ // Record the decode failure
1468+ topics := make ([]string , len (lo .Topics ))
1469+ for i , topic := range lo .Topics {
1470+ topics [i ] = topic .Hex ()
1471+ }
1472+
1473+ decodeError := EventDecodingError {
1474+ Signature : eventSig ,
1475+ LogIndex : lo .Index ,
1476+ Address : lo .Address .Hex (),
1477+ Topics : topics ,
1478+ Errors : decodeAttempts ,
1479+ }
1480+ decodeErrors = append (decodeErrors , decodeError )
1481+
1482+ abiNames := make ([]string , len (decodeAttempts ))
1483+ for i , attempt := range decodeAttempts {
1484+ abiNames [i ] = attempt .ABIName
1485+ }
1486+
14581487 l .Warn ().
14591488 Str ("Signature" , eventSig ).
1460- Msg ("No matching event with valid indexed parameter count found for log" )
1489+ Uint ("LogIndex" , lo .Index ).
1490+ Str ("Address" , lo .Address .Hex ()).
1491+ Strs ("AttemptedABIs" , abiNames ).
1492+ Int ("FailedAttempts" , len (decodeAttempts )).
1493+ Msg ("Failed to decode event log" )
14611494 }
14621495 }
1463- return eventsParsed , nil
1496+ return eventsParsed , decodeErrors , nil
14641497}
14651498
14661499type eventWithABI struct {
@@ -1484,6 +1517,21 @@ func buildEventSignatureMap(allABIs []*abi.ABI) map[string][]*eventWithABI {
14841517 return sigMap
14851518}
14861519
1520+ // findABIName finds the name of the ABI in the ContractStore, returns "unknown" if not found
1521+ func (m * Client ) findABIName (targetABI * abi.ABI ) string {
1522+ if m .ContractStore == nil {
1523+ return "unknown"
1524+ }
1525+
1526+ for name , storedABI := range m .ContractStore .ABIs {
1527+ if reflect .DeepEqual (storedABI , * targetABI ) {
1528+ return strings .TrimSuffix (name , ".abi" )
1529+ }
1530+ }
1531+
1532+ return "unknown"
1533+ }
1534+
14871535// WaitUntilNoPendingTxForRootKey waits until there's no pending transaction for root key. If after timeout there are still pending transactions, it returns error.
14881536func (m * Client ) WaitUntilNoPendingTxForRootKey (timeout time.Duration ) error {
14891537 return m .WaitUntilNoPendingTx (m .MustGetRootKeyAddress (), timeout )
0 commit comments