Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of broadcast mode sync in broadcaster.go #388

Merged
merged 1 commit into from
Jan 31, 2023
Merged
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
24 changes: 13 additions & 11 deletions chain/cosmos/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type FactoryOpt func(factory tx.Factory) tx.Factory
type User interface {
KeyName() string
FormattedAddress() string
FormattedAddressWithPrefix(prefix string) string
}

type Broadcaster struct {
Expand Down Expand Up @@ -80,7 +79,7 @@ func (b *Broadcaster) GetFactory(ctx context.Context, user User) (tx.Factory, er
return tx.Factory{}, err
}

sdkAdd, err := sdk.AccAddressFromBech32(user.FormattedAddressWithPrefix(b.chain.Config().Bech32Prefix))
sdkAdd, err := sdk.AccAddressFromBech32(user.FormattedAddress())
if err != nil {
return tx.Factory{}, err
}
Expand Down Expand Up @@ -115,7 +114,7 @@ func (b *Broadcaster) GetClientContext(ctx context.Context, user User) (client.C
b.keyrings[user] = kr
}

sdkAdd, err := sdk.AccAddressFromBech32(user.FormattedAddressWithPrefix(chain.Config().Bech32Prefix))
sdkAdd, err := sdk.AccAddressFromBech32(user.FormattedAddress())
if err != nil {
return client.Context{}, err
}
Expand Down Expand Up @@ -153,7 +152,7 @@ func (b *Broadcaster) defaultClientContext(fromUser User, sdkAdd sdk.AccAddress)
cn := b.chain.getFullNode()
return cn.CliContext().
WithOutput(b.buf).
WithFrom(fromUser.FormattedAddressWithPrefix(b.chain.Config().Bech32Prefix)).
WithFrom(fromUser.FormattedAddress()).
WithFromAddress(sdkAdd).
WithFromName(fromUser.KeyName()).
WithSkipConfirmation(true).
Expand Down Expand Up @@ -206,7 +205,9 @@ func BroadcastTx(ctx context.Context, broadcaster *Broadcaster, broadcastingUser
}

err = testutil.WaitForCondition(time.Second*30, time.Second*5, func() (bool, error) {
_, err := broadcaster.GetTxResponseBytes(ctx, broadcastingUser)
var err error
txBytes, err = broadcaster.GetTxResponseBytes(ctx, broadcastingUser)

if err != nil {
return false, nil
}
Expand All @@ -217,19 +218,20 @@ func BroadcastTx(ctx context.Context, broadcaster *Broadcaster, broadcastingUser
return sdk.TxResponse{}, err
}

txBytes, err = broadcaster.GetTxResponseBytes(ctx, broadcastingUser)
if err != nil {
return sdk.TxResponse{}, err
}

respWithTxHash, err := broadcaster.UnmarshalTxResponseBytes(ctx, txBytes)
if err != nil {
return sdk.TxResponse{}, err
}

resp, err := authTx.QueryTx(cc, respWithTxHash.TxHash)
if err != nil {
return sdk.TxResponse{}, err
// if we fail to query the tx, it means an error occurred with the original message broadcast.
// we should return this instead.
originalResp, err := broadcaster.UnmarshalTxResponseBytes(ctx, txBytes)
if err != nil {
return sdk.TxResponse{}, err
}
return originalResp, nil
}

return *resp, nil
Expand Down
1 change: 1 addition & 0 deletions chain/cosmos/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

var _ ibc.Wallet = &CosmosWallet{}
var _ User = &CosmosWallet{}

type CosmosWallet struct {
mnemonic string
Expand Down