-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from DefiantLabs/feat/message-type-filters-and…
…-improving-message-parsing Feat/message type filters and improving message parsing
- Loading branch information
Showing
7 changed files
with
353 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package core | ||
|
||
import ( | ||
"errors" | ||
|
||
probeClient "github.com/DefiantLabs/probe/client" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/tx" | ||
) | ||
|
||
// Provides an in-app tx decoder. | ||
// The primary use-case for this function is to allow fallback decoding if a TX fails to decode after RPC requests. | ||
// This can happen in a number of scenarios, but mainly due to missing proto definitions. | ||
// We can attempt a personal decode of the TX, and see if we can continue indexing based on in-app conditions (such as message type filters). | ||
// This function skips a large chunk of decoding validations, and is not recommended for general use. Its main point is to skip errors that in | ||
// default Cosmos TX decoders would cause the entire decode to fail. | ||
func InAppTxDecoder(cdc probeClient.Codec) sdk.TxDecoder { | ||
return func(txBytes []byte) (sdk.Tx, error) { | ||
var raw tx.TxRaw | ||
var err error | ||
|
||
err = cdc.Marshaler.Unmarshal(txBytes, &raw) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var body tx.TxBody | ||
|
||
err = body.Unmarshal(raw.BodyBytes) | ||
if err != nil { | ||
return nil, errors.New("failed to unmarshal tx body") | ||
} | ||
|
||
for _, any := range body.Messages { | ||
var msg sdk.Msg | ||
// We deliberately ignore errors here to build up a | ||
// list of properly decoded messages for later analysis. | ||
cdc.Marshaler.UnpackAny(any, &msg) //nolint:errcheck | ||
} | ||
|
||
var authInfo tx.AuthInfo | ||
|
||
err = cdc.Marshaler.Unmarshal(raw.AuthInfoBytes, &authInfo) | ||
if err != nil { | ||
return nil, errors.New("failed to unmarshal auth info") | ||
} | ||
|
||
theTx := &tx.Tx{ | ||
Body: &body, | ||
AuthInfo: &authInfo, | ||
Signatures: raw.Signatures, | ||
} | ||
|
||
return theTx, nil | ||
} | ||
} |
Oops, something went wrong.