Skip to content

Commit

Permalink
feat: add support for multiple accounts (backport) (#3504)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmwaters committed May 29, 2024
1 parent 39cc28d commit 6157752
Show file tree
Hide file tree
Showing 7 changed files with 1,467 additions and 463 deletions.
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

0 comments on commit 6157752

Please sign in to comment.