Skip to content

Commit 06c3916

Browse files
committed
Fixes for pool accounts
1 parent c94e52f commit 06c3916

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

pkg/code/async/sequencer/fulfillment_handler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ func (h *InitializeLockedTimelockAccountFulfillmentHandler) CanSubmitToBlockchai
8585
return false, errors.New("invalid fulfillment type")
8686
}
8787

88+
// todo: Fix unlock state detection for Timelock accounts that won't be
89+
// initialized immediately
90+
return true, nil
91+
8892
accountInfoRecord, err := h.data.GetAccountInfoByTokenAddress(ctx, fulfillmentRecord.Source)
8993
if err != nil {
9094
return false, err

pkg/code/common/owner.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ func GetLatestTokenAccountRecordsForOwner(ctx context.Context, data code_data.Pr
145145
}
146146
}
147147

148+
// Filter out account records for accounts that have completed their
149+
// full lifecycle
150+
//
151+
// todo: This needs tests
152+
switch generalRecord.AccountType {
153+
case commonpb.AccountType_POOL:
154+
if timelockRecord.IsClosed() {
155+
continue
156+
}
157+
}
158+
148159
res[generalRecord.AccountType] = append(res[generalRecord.AccountType], &AccountRecords{
149160
General: generalRecord,
150161
Timelock: timelockRecord,

pkg/code/server/account/server.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/code-payments/code-server/pkg/code/balance"
2222
"github.com/code-payments/code-server/pkg/code/common"
2323
code_data "github.com/code-payments/code-server/pkg/code/data"
24+
"github.com/code-payments/code-server/pkg/code/data/account"
2425
"github.com/code-payments/code-server/pkg/code/data/action"
2526
"github.com/code-payments/code-server/pkg/grpc/client"
2627
timelock_token_v1 "github.com/code-payments/code-server/pkg/solana/timelock/v1"
@@ -160,26 +161,16 @@ func (s *server) GetTokenAccountInfos(ctx context.Context, req *accountpb.GetTok
160161
return nil, status.Error(codes.Internal, "")
161162
}
162163

163-
nextPoolIndex := len(recordsByType[commonpb.AccountType_POOL])
164-
165-
// Filter out account records for accounts that have completed their full
166-
// lifecycle
167-
//
168-
// todo: This needs tests
169-
for accountType, batchRecords := range recordsByType {
170-
switch accountType {
171-
case commonpb.AccountType_POOL:
172-
default:
173-
continue
174-
}
175-
176-
var filtered []*common.AccountRecords
177-
for _, records := range batchRecords {
178-
if records.IsTimelock() && !records.Timelock.IsClosed() {
179-
filtered = append(filtered, records)
180-
}
181-
}
182-
recordsByType[accountType] = filtered
164+
var nextPoolIndex uint64
165+
latestPoolAccountInfoRecord, err := s.data.GetLatestAccountInfoByOwnerAddressAndType(ctx, owner.PublicKey().ToBase58(), commonpb.AccountType_POOL)
166+
switch err {
167+
case nil:
168+
nextPoolIndex = latestPoolAccountInfoRecord.Index + 1
169+
case account.ErrAccountInfoNotFound:
170+
nextPoolIndex = 0
171+
default:
172+
log.WithError(err).Warn("failure getting latest pool account record")
173+
return nil, status.Error(codes.Internal, "")
183174
}
184175

185176
// Trigger a deposit sync with the blockchain for the primary account, if it exists

pkg/code/server/transaction/intent_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func (h *OpenAccountsIntentHandler) validateActions(
258258
return NewActionValidationErrorf(openAction, "account type must be %s", expectedAccountToOpen.Type)
259259
}
260260

261-
if openAction.GetOpenAccount().Index != 0 {
261+
if openAction.GetOpenAccount().Index != expectedAccountToOpen.Index {
262262
return NewActionValidationErrorf(openAction, "index must be %d", expectedAccountToOpen.Index)
263263
}
264264

@@ -1142,7 +1142,7 @@ func (h *PublicDistributionIntentHandler) IsNoop(ctx context.Context, intentReco
11421142
}
11431143

11441144
func (h *PublicDistributionIntentHandler) GetBalanceLocks(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata) ([]*intentBalanceLock, error) {
1145-
poolVault, err := common.NewAccountFromPublicKeyString(intentRecord.ReceivePaymentsPubliclyMetadata.Source)
1145+
poolVault, err := common.NewAccountFromPublicKeyString(intentRecord.PublicDistributionMetadata.Source)
11461146
if err != nil {
11471147
return nil, err
11481148
}

0 commit comments

Comments
 (0)