Skip to content

Commit

Permalink
chore: align User interface with CosmosWallet and fix issue with broa…
Browse files Browse the repository at this point in the history
…dcast mode sync (#388)
  • Loading branch information
chatton authored Jan 31, 2023
1 parent 0fcd87d commit 91540a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
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

0 comments on commit 91540a4

Please sign in to comment.