Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

fix error address #345

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions indexprotocol/accounts/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/iotexproject/iotex-analytics/indexprotocol"
"github.com/iotexproject/iotex-analytics/queryprotocol"
s "github.com/iotexproject/iotex-analytics/sql"
"github.com/iotexproject/iotex-analytics/utils"
)

const (
Expand Down Expand Up @@ -292,6 +293,14 @@ func (p *Protocol) updateBalanceHistory(
from string,
amount string,
) error {
if len(to) > 41 {
addr, err := utils.FixErrorAddress(to)
if err != nil {
to = "io1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc96xkxh5"
} else {
to = addr.String()
}
}
insertQuery := fmt.Sprintf(insertBalanceHistory,
BalanceHistoryTableName)
if _, err := tx.Exec(insertQuery, epochNumber, blockHeight, actionHash, actionType, from, to, amount); err != nil {
Expand Down
9 changes: 9 additions & 0 deletions indexprotocol/actions/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/iotexproject/iotex-analytics/indexprotocol"
"github.com/iotexproject/iotex-analytics/indexprotocol/blocks"
s "github.com/iotexproject/iotex-analytics/sql"
"github.com/iotexproject/iotex-analytics/utils"
)

const (
Expand Down Expand Up @@ -202,6 +203,14 @@ func (p *Protocol) HandleBlock(ctx context.Context, tx *sql.Tx, blk *block.Block
return err
}
dst, _ := selp.Destination()
if len(dst) > 41 {
addr, err := utils.FixErrorAddress(dst)
if err != nil {
dst = "io1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc96xkxh5"
} else {
dst = addr.String()
}
}
gasPrice := selp.GasPrice().String()
nonce := selp.Nonce()

Expand Down
20 changes: 20 additions & 0 deletions utils/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package utils

import (
"github.com/iotexproject/iotex-address/address"
"github.com/iotexproject/iotex-address/address/bech32"
)

func FixErrorAddress(addr string) (address.Address, error) {
_, grouped, err := bech32.Decode(addr)
if err != nil {
return nil, err
}
payload, err := bech32.ConvertBits(grouped, 5, 8, false)
if err != nil || len(payload) < 20 {
return nil, err
}

payload = payload[len(payload)-20:]
return address.FromBytes(payload)
}