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

feat: add support for multiple accounts (backport) #3504

Merged
merged 2 commits into from
May 29, 2024
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ test-short:
## test-race: Run unit tests in race mode.
test-race:
@echo "--> Running tests in race mode"
@go test ./... -v -race -skip "TestPrepareProposalConsistency|TestIntegrationTestSuite|TestQGBRPCQueries|TestSquareSizeIntegrationTest|TestStandardSDKIntegrationTestSuite|TestTxsimCommandFlags|TestTxsimCommandEnvVar|TestMintIntegrationTestSuite|TestQGBCLI|TestUpgrade|TestMaliciousTestNode|TestMaxTotalBlobSizeSuite|TestQGBIntegrationSuite|TestSignerTestSuite|TestPriorityTestSuite|TestTimeInPrepareProposalContext|TestConcurrentTxSubmission"
@go test ./... -v -race -skip "TestPrepareProposalConsistency|TestIntegrationTestSuite|TestQGBRPCQueries|TestSquareSizeIntegrationTest|TestStandardSDKIntegrationTestSuite|TestTxsimCommandFlags|TestTxsimCommandEnvVar|TestMintIntegrationTestSuite|TestQGBCLI|TestUpgrade|TestMaliciousTestNode|TestMaxTotalBlobSizeSuite|TestQGBIntegrationSuite|TestSignerTestSuite|TestPriorityTestSuite|TestTimeInPrepareProposalContext|TestConcurrentTxSubmission|TestTxClientTestSuite"
.PHONY: test-race

## test-bench: Run unit tests in bench mode.
Expand Down
79 changes: 79 additions & 0 deletions pkg/user/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package user

import (
"context"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"google.golang.org/grpc"
)

type Account struct {
name string
address types.AccAddress
pubKey cryptotypes.PubKey
accountNumber uint64

// the signers local view of the sequence number
sequence uint64
}

func NewAccount(keyName string, accountNumber, sequenceNumber uint64) *Account {
return &Account{
name: keyName,
accountNumber: accountNumber,
sequence: sequenceNumber,
}
}

func (a Account) Name() string {
return a.name
}

func (a Account) Address() types.AccAddress {
return a.address
}

func (a Account) PubKey() cryptotypes.PubKey {
return a.pubKey
}

// Sequence returns the sequence number of the account.
// This is locally tracked
func (a Account) Sequence() uint64 {
return a.sequence
}

func (a *Account) Copy() *Account {
return &Account{
name: a.name,
address: a.address,
pubKey: a.pubKey,
accountNumber: a.accountNumber,
sequence: a.sequence,
}
}

// QueryAccountInfo fetches the account number and sequence number from the celestia-app node.
func QueryAccountInfo(ctx context.Context, conn *grpc.ClientConn, registry codectypes.InterfaceRegistry, address types.AccAddress) (accNum uint64, seqNum uint64, err error) {
qclient := authtypes.NewQueryClient(conn)
// TODO: ideally we add a way to prove that the accounts rather than simply trusting the full node we are connected with
resp, err := qclient.Account(
ctx,
&authtypes.QueryAccountRequest{Address: address.String()},
)
if err != nil {
return accNum, seqNum, err
}

var acc authtypes.AccountI
err = registry.UnpackAny(resp.Account, &acc)
if err != nil {
return accNum, seqNum, err
}

accNum, seqNum = acc.GetAccountNumber(), acc.GetSequence()
return accNum, seqNum, nil
}
Loading
Loading