Skip to content

Commit b08a9b7

Browse files
committed
Remove deprecated balance methods
1 parent 2d9c28d commit b08a9b7

File tree

2 files changed

+0
-119
lines changed

2 files changed

+0
-119
lines changed

pkg/code/balance/calculator.go

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"github.com/pkg/errors"
88
"github.com/sirupsen/logrus"
99

10-
commonpb "github.com/code-payments/code-protobuf-api/generated/go/common/v1"
11-
1210
"github.com/code-payments/code-server/pkg/code/common"
1311
code_data "github.com/code-payments/code-server/pkg/code/data"
1412
"github.com/code-payments/code-server/pkg/code/data/balance"
@@ -402,61 +400,6 @@ func FundingFromExternalDepositsBatch(ctx context.Context, data code_data.Provid
402400
}
403401
}
404402

405-
// GetPrivateBalance gets an owner account's total private balance.
406-
//
407-
// Note: Assumes all private accounts have the same mint
408-
func GetPrivateBalance(ctx context.Context, data code_data.Provider, owner *common.Account) (uint64, error) {
409-
log := logrus.StandardLogger().WithFields(logrus.Fields{
410-
"method": "GetPrivateBalance",
411-
"owner": owner.PublicKey().ToBase58(),
412-
})
413-
414-
tracer := metrics.TraceMethodCall(ctx, metricsPackageName, "GetPrivateBalance")
415-
tracer.AddAttribute("owner", owner.PublicKey().ToBase58())
416-
defer tracer.End()
417-
418-
accountRecordsByType, err := common.GetLatestTokenAccountRecordsForOwner(ctx, data, owner)
419-
if err != nil {
420-
log.WithError(err).Warn("failure getting latest token account records")
421-
tracer.OnError(err)
422-
return 0, err
423-
}
424-
425-
if len(accountRecordsByType) == 0 {
426-
tracer.OnError(ErrNotManagedByCode)
427-
return 0, ErrNotManagedByCode
428-
}
429-
430-
var accountRecordsBatch []*common.AccountRecords
431-
for _, accountRecords := range accountRecordsByType {
432-
switch accountRecords[0].General.AccountType {
433-
case commonpb.AccountType_PRIMARY,
434-
commonpb.AccountType_LEGACY_PRIMARY_2022,
435-
commonpb.AccountType_REMOTE_SEND_GIFT_CARD,
436-
commonpb.AccountType_RELATIONSHIP,
437-
commonpb.AccountType_SWAP:
438-
continue
439-
}
440-
441-
accountRecordsBatch = append(accountRecordsBatch, accountRecords...)
442-
}
443-
444-
balanceByAccount, err := BatchCalculateFromCacheWithAccountRecords(ctx, data, accountRecordsBatch...)
445-
if err != nil {
446-
log.WithError(err).Warn("failure getting balances")
447-
tracer.OnError(err)
448-
return 0, err
449-
}
450-
451-
var total uint64
452-
for _, batchRecords := range accountRecordsByType {
453-
for _, records := range batchRecords {
454-
total += balanceByAccount[records.General.TokenAccount]
455-
}
456-
}
457-
return total, nil
458-
}
459-
460403
func (s Source) String() string {
461404
switch s {
462405
case UnknownSource:

pkg/code/balance/calculator_test.go

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package balance
33
import (
44
"context"
55
"fmt"
6-
"math"
76
"testing"
87
"time"
98

@@ -19,7 +18,6 @@ import (
1918
"github.com/code-payments/code-server/pkg/code/data/deposit"
2019
"github.com/code-payments/code-server/pkg/code/data/intent"
2120
"github.com/code-payments/code-server/pkg/code/data/transaction"
22-
"github.com/code-payments/code-server/pkg/pointer"
2321
timelock_token_v1 "github.com/code-payments/code-server/pkg/solana/timelock/v1"
2422
"github.com/code-payments/code-server/pkg/testutil"
2523
)
@@ -347,66 +345,6 @@ func TestDefaultCalculation_ExternalAccount(t *testing.T) {
347345
// Note: not possible with batch method, since we wouldn't have account records
348346
}
349347

350-
func TestGetAggregatedBalances(t *testing.T) {
351-
env := setupBalanceTestEnv(t)
352-
353-
vmAccount := testutil.NewRandomAccount(t)
354-
owner := testutil.NewRandomAccount(t)
355-
356-
_, err := GetPrivateBalance(env.ctx, env.data, owner)
357-
assert.Equal(t, ErrNotManagedByCode, err)
358-
359-
var expectedTotalBalance, expectedPrivateBalance uint64
360-
for i, accountType := range account.AllAccountTypes {
361-
if accountType == commonpb.AccountType_REMOTE_SEND_GIFT_CARD || accountType == commonpb.AccountType_SWAP {
362-
continue
363-
}
364-
365-
authority := testutil.NewRandomAccount(t)
366-
if accountType == commonpb.AccountType_PRIMARY {
367-
authority = owner
368-
}
369-
370-
balance := uint64(math.Pow10(i))
371-
expectedTotalBalance += balance
372-
if accountType != commonpb.AccountType_PRIMARY && accountType != commonpb.AccountType_RELATIONSHIP {
373-
expectedPrivateBalance += balance
374-
}
375-
376-
timelockAccounts, err := authority.GetTimelockAccounts(vmAccount, common.CoreMintAccount)
377-
require.NoError(t, err)
378-
379-
timelockRecord := timelockAccounts.ToDBRecord()
380-
require.NoError(t, env.data.SaveTimelock(env.ctx, timelockRecord))
381-
382-
accountInfoRecord := account.Record{
383-
OwnerAccount: owner.PublicKey().ToBase58(),
384-
AuthorityAccount: authority.PublicKey().ToBase58(),
385-
TokenAccount: timelockRecord.VaultAddress,
386-
MintAccount: common.CoreMintAccount.PublicKey().ToBase58(),
387-
AccountType: accountType,
388-
}
389-
if accountType == commonpb.AccountType_RELATIONSHIP {
390-
accountInfoRecord.RelationshipTo = pointer.String("example.com")
391-
}
392-
require.NoError(t, env.data.CreateAccountInfo(env.ctx, &accountInfoRecord))
393-
394-
actionRecord := action.Record{
395-
Intent: testutil.NewRandomAccount(t).PublicKey().ToBase58(),
396-
IntentType: intent.SendPrivatePayment,
397-
ActionType: action.PrivateTransfer,
398-
Source: testutil.NewRandomAccount(t).PublicKey().ToBase58(),
399-
Destination: &accountInfoRecord.TokenAccount,
400-
Quantity: &balance,
401-
}
402-
require.NoError(t, env.data.PutAllActions(env.ctx, &actionRecord))
403-
}
404-
405-
balance, err := GetPrivateBalance(env.ctx, env.data, owner)
406-
require.NoError(t, err)
407-
assert.EqualValues(t, expectedPrivateBalance, balance)
408-
}
409-
410348
type balanceTestEnv struct {
411349
ctx context.Context
412350
data code_data.Provider

0 commit comments

Comments
 (0)