Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
41 lines
1,018 B
Go
41 lines
1,018 B
Go
package cosmosclient
|
|
|
|
import (
|
|
"context"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/types/query"
|
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
|
|
"github.com/ignite/cli/v29/ignite/pkg/cosmosaccount"
|
|
)
|
|
|
|
func (c Client) BankBalances(ctx context.Context, address string, pagination *query.PageRequest) (sdk.Coins, error) {
|
|
defer c.lockBech32Prefix()()
|
|
|
|
req := &banktypes.QueryAllBalancesRequest{
|
|
Address: address,
|
|
Pagination: pagination,
|
|
}
|
|
|
|
resp, err := c.bankQueryClient.AllBalances(ctx, req)
|
|
if err != nil {
|
|
return nil, rpcError(c.nodeAddress, err)
|
|
}
|
|
return resp.Balances, nil
|
|
}
|
|
|
|
func (c Client) BankSendTx(ctx context.Context, fromAccount cosmosaccount.Account, toAddress string, amount sdk.Coins) (TxService, error) {
|
|
addr, err := fromAccount.Address(c.bech32Prefix)
|
|
if err != nil {
|
|
return TxService{}, err
|
|
}
|
|
|
|
msg := &banktypes.MsgSend{
|
|
FromAddress: addr,
|
|
ToAddress: toAddress,
|
|
Amount: amount,
|
|
}
|
|
|
|
return c.CreateTx(ctx, fromAccount, msg)
|
|
}
|