Skip to content

Commit

Permalink
fix: filter contract address wasm (#117)
Browse files Browse the repository at this point in the history
* fix: filter wasm contract address

* fix: show balance of wallet address wasm

* fix: json file name

* chore: rename file name

* fix: allow query balance in icon

---------

Co-authored-by: izyak <[email protected]>
  • Loading branch information
viveksharmapoudel and izyak authored Jul 27, 2023
1 parent 6969342 commit bd7a02b
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ func newRootLogger(format string, debug bool) (*zap.Logger, error) {

ll := lumberjack.Logger{
Filename: path.Join(defaultHome, "relay.log"),
MaxSize: 50, //MB
MaxSize: 10, //MB
MaxBackups: 30,
MaxAge: 28, //days
Compress: true,
Compress: false,
}
zap.RegisterSink("lumberjack", func(*url.URL) (zap.Sink, error) {
return lumberjackSink{
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/configs/chains/ibc-wasm.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"timeout": "20s",
"output-format": "json",
"sign-mode": "direct",
"ibc-handler-address":"--",
"ibc-handler-address":"neutron1fde8lfydxgwg6p7xe9ugx5a6ysj37zfvn9m9z5rxt4mqvdcneczsczq2a4",
"broadcast-mode": "batch",
"block-timeout": "",
"start-height":0,
Expand Down
13 changes: 12 additions & 1 deletion relayer/chains/icon/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"cosmossdk.io/math"
"github.com/avast/retry-go/v4"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"
Expand Down Expand Up @@ -143,7 +144,17 @@ func (icp *IconProvider) QueryBalance(ctx context.Context, keyName string) (sdk.

// implementing is not required
func (icp *IconProvider) QueryBalanceWithAddress(ctx context.Context, addr string) (sdk.Coins, error) {
panic(fmt.Sprintf("%s%s", icp.ChainName(), NOT_IMPLEMENTED))
param := types.AddressParam{
Address: types.Address(addr),
}
balance, err := icp.client.GetBalance(&param)
if err != nil {
return nil, err
}
return sdk.Coins{sdk.Coin{
Denom: "ICX",
Amount: math.NewInt(balance.Int64()),
}}, nil
}

func (icp *IconProvider) QueryUnbondingPeriod(context.Context) (time.Duration, error) {
Expand Down
4 changes: 4 additions & 0 deletions relayer/chains/wasm/event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func parseIBCMessageFromEvent(
return nil
}

if !eventFromIBCContractAddress(event.Attributes[0], contractAddress) {
return nil
}

eventType := findEventType(event.Type)
attrs := event.Attributes[1:]
switch eventType {
Expand Down
33 changes: 31 additions & 2 deletions relayer/chains/wasm/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,37 @@ func (ap *WasmProvider) GetCommitmentPrefixFromContract(ctx context.Context) ([]

// ics 20 - transfer
func (ap *WasmProvider) QueryDenomTrace(ctx context.Context, denom string) (*transfertypes.DenomTrace, error) {
panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED))
transfers, err := transfertypes.NewQueryClient(ap).DenomTrace(ctx,
&transfertypes.QueryDenomTraceRequest{
Hash: denom,
})
if err != nil {
return nil, err
}
return transfers.DenomTrace, nil
}
func (ap *WasmProvider) QueryDenomTraces(ctx context.Context, offset, limit uint64, height int64) ([]transfertypes.DenomTrace, error) {
panic(fmt.Sprintf("%s%s", ap.ChainName(), NOT_IMPLEMENTED))
qc := transfertypes.NewQueryClient(ap)
p := DefaultPageRequest()
transfers := []transfertypes.DenomTrace{}
for {
res, err := qc.DenomTraces(ctx,
&transfertypes.QueryDenomTracesRequest{
Pagination: p,
})

if err != nil || res == nil {
return nil, err
}

transfers = append(transfers, res.DenomTraces...)
next := res.GetPagination().GetNextKey()
if len(next) == 0 {
break
}

time.Sleep(PaginationDelay)
p.Key = next
}
return transfers, nil
}
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion relayer/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
chantypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/cosmos/relayer/v2/relayer/common"
"github.com/cosmos/relayer/v2/relayer/provider"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -234,7 +235,7 @@ func QueryBalance(ctx context.Context, chain *Chain, address string, showDenoms
return nil, err
}

if showDenoms {
if showDenoms || chain.ChainProvider.Type() == common.IconModule {
return coins, nil
}

Expand Down

0 comments on commit bd7a02b

Please sign in to comment.