Skip to content

Commit

Permalink
Fix bad parsing of multisig keys reliant on strings, move to codec in…
Browse files Browse the repository at this point in the history
…terface registry validation and parsing based on underlying type
  • Loading branch information
pharr117 committed Apr 10, 2024
1 parent 90793a3 commit a1bba48
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func processBlock(cl *client.ChainClient, dbConn *gorm.DB, failedBlockHandler fu
}
}
} else {
txDBWrappers, blockTime, err = core.ProcessRPCTXs(dbConn, txsEventResp)
txDBWrappers, blockTime, err = core.ProcessRPCTXs(dbConn, cl, txsEventResp)
if err != nil {
config.Log.Error("ProcessRpcTxs: unhandled error", err)
failedBlockHandler(blockToProcess, core.UnprocessableTxError, err)
Expand Down
32 changes: 21 additions & 11 deletions core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func ProcessRPCBlockByHeightTXs(db *gorm.DB, cl *client.ChainClient, blockResult
indexerMergedTx.Tx = indexerTx
indexerMergedTx.Tx.AuthInfo = *txFull.AuthInfo

processedTx, _, err := ProcessTx(db, indexerMergedTx)
processedTx, _, err := ProcessTx(cl, db, indexerMergedTx)
if err != nil {
return currTxDbWrappers, blockTime, err
}
Expand All @@ -330,7 +330,7 @@ func ProcessRPCBlockByHeightTXs(db *gorm.DB, cl *client.ChainClient, blockResult
}

// ProcessRPCTXs - Given an RPC response, build out the more specific data used by the parser.
func ProcessRPCTXs(db *gorm.DB, txEventResp *cosmosTx.GetTxsEventResponse) ([]dbTypes.TxDBWrapper, *time.Time, error) {
func ProcessRPCTXs(db *gorm.DB, cl *client.ChainClient, txEventResp *cosmosTx.GetTxsEventResponse) ([]dbTypes.TxDBWrapper, *time.Time, error) {
currTxDbWrappers := make([]dbTypes.TxDBWrapper, len(txEventResp.Txs))
var blockTime *time.Time

Expand Down Expand Up @@ -386,7 +386,7 @@ func ProcessRPCTXs(db *gorm.DB, txEventResp *cosmosTx.GetTxsEventResponse) ([]db
indexerMergedTx.Tx = indexerTx
indexerMergedTx.Tx.AuthInfo = *currTx.AuthInfo

processedTx, txTime, err := ProcessTx(db, indexerMergedTx)
processedTx, txTime, err := ProcessTx(cl, db, indexerMergedTx)
if err != nil {
return currTxDbWrappers, blockTime, err
}
Expand Down Expand Up @@ -430,7 +430,7 @@ func AnalyzeSwaps() {
fmt.Printf("Profit (OSMO): %.10f, days: %f\n", profit, latestTime.Sub(earliestTime).Hours()/24)
}

func ProcessTx(db *gorm.DB, tx txtypes.MergedTx) (txDBWapper dbTypes.TxDBWrapper, txTime time.Time, err error) {
func ProcessTx(cl *client.ChainClient, db *gorm.DB, tx txtypes.MergedTx) (txDBWapper dbTypes.TxDBWrapper, txTime time.Time, err error) {
txTime, err = time.Parse(time.RFC3339, tx.TxResponse.TimeStamp)
if err != nil {
config.Log.Error("Error parsing tx timestamp.", err)
Expand Down Expand Up @@ -535,7 +535,7 @@ func ProcessTx(db *gorm.DB, tx txtypes.MergedTx) (txDBWapper dbTypes.TxDBWrapper
}
}

fees, err := ProcessFees(db, tx.Tx.AuthInfo, tx.Tx.Signers)
fees, err := ProcessFees(cl, db, tx.Tx.AuthInfo, tx.Tx.Signers)
if err != nil {
return txDBWapper, txTime, err
}
Expand All @@ -547,7 +547,7 @@ func ProcessTx(db *gorm.DB, tx txtypes.MergedTx) (txDBWapper dbTypes.TxDBWrapper
}

// ProcessFees returns a comma delimited list of fee amount/denoms
func ProcessFees(db *gorm.DB, authInfo cosmosTx.AuthInfo, signers []types.AccAddress) ([]dbTypes.Fee, error) {
func ProcessFees(cl *client.ChainClient, db *gorm.DB, authInfo cosmosTx.AuthInfo, signers []types.AccAddress) ([]dbTypes.Fee, error) {
feeCoins := authInfo.Fee.Amount
payer := authInfo.Fee.GetPayer()
fees := []dbTypes.Fee{}
Expand Down Expand Up @@ -576,14 +576,24 @@ func ProcessFees(db *gorm.DB, authInfo cosmosTx.AuthInfo, signers []types.AccAdd
payerAddr.Address = signers[0].String()
} else {
var pubKey cryptoTypes.PubKey
cpk := authInfo.SignerInfos[0].PublicKey.GetCachedValue()

// if this is a multisig msg, handle it specially
if strings.Contains(authInfo.SignerInfos[0].ModeInfo.GetMulti().String(), "mode:SIGN_MODE_LEGACY_AMINO_JSON") {
pubKey = cpk.(*multisig.LegacyAminoPubKey).GetPubKeys()[0]
pubKeyType, err := cl.Codec.InterfaceRegistry.Resolve(authInfo.SignerInfos[0].PublicKey.TypeUrl)
if err != nil {
return nil, err
}
err = cl.Codec.InterfaceRegistry.UnpackAny(authInfo.SignerInfos[0].PublicKey, &pubKeyType)
if err != nil {
return nil, err
}

multisigKey, ok := pubKeyType.(*multisig.LegacyAminoPubKey)

if ok {
pubKey = multisigKey.GetPubKeys()[0]
} else {
pubKey = cpk.(cryptoTypes.PubKey)
pubKey = pubKeyType.(cryptoTypes.PubKey)
}

hexPub := hex.EncodeToString(pubKey.Bytes())
bechAddr, err := ParseSignerAddress(hexPub, "")
if err != nil {
Expand Down

0 comments on commit a1bba48

Please sign in to comment.