Skip to content

Commit 1ac9b04

Browse files
committed
Cleanup deprecated account types
1 parent 6051b87 commit 1ac9b04

File tree

15 files changed

+164
-484
lines changed

15 files changed

+164
-484
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
filippo.io/edwards25519 v1.1.0
77
github.com/aws/aws-sdk-go-v2 v0.17.0
88
github.com/bits-and-blooms/bloom/v3 v3.1.0
9-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250826182502-883828ea83bd
9+
github.com/code-payments/code-protobuf-api v1.19.1-0.20250827160012-3edaffb82d79
1010
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba
1111
github.com/emirpasic/gods v1.12.0
1212
github.com/envoyproxy/protoc-gen-validate v1.2.1

go.sum

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
8080
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
8181
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
8282
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
83-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250825171158-5f02a8a5924b h1:dwgr/zhcF7eZsBgRAX+AAjOhBdk9fEs1oO2csc0lI0U=
84-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250825171158-5f02a8a5924b/go.mod h1:ee6TzKbgMS42ZJgaFEMG3c4R3dGOiffHSu6MrY7WQvs=
85-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250825175528-dab522122ad6 h1:5OUwxIX95ReOieQGdeihVRiQajpZhmN5dsY6HgseZf8=
86-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250825175528-dab522122ad6/go.mod h1:ee6TzKbgMS42ZJgaFEMG3c4R3dGOiffHSu6MrY7WQvs=
87-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250825175844-b5a79ae87f0a h1:oVponiCqodzMIR/9gucEbxG4pCQSFwcUQnydJjPv01U=
88-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250825175844-b5a79ae87f0a/go.mod h1:ee6TzKbgMS42ZJgaFEMG3c4R3dGOiffHSu6MrY7WQvs=
89-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250826132123-e79bc35cff0f h1:ujiDkjcrsk4wZOUQuaYytSQowUnOpT2icmCi6tVc8eY=
90-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250826132123-e79bc35cff0f/go.mod h1:ee6TzKbgMS42ZJgaFEMG3c4R3dGOiffHSu6MrY7WQvs=
91-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250826182502-883828ea83bd h1:nK1+vHCOTtAL1ouC53yP0sYISKR0uuEsoaYJmZAg4uA=
92-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250826182502-883828ea83bd/go.mod h1:ee6TzKbgMS42ZJgaFEMG3c4R3dGOiffHSu6MrY7WQvs=
83+
github.com/code-payments/code-protobuf-api v1.19.1-0.20250827160012-3edaffb82d79 h1:Td/jOwNQCuSaTL6NZstWSMxgjcyVhkC1Q/BmVRqY6qo=
84+
github.com/code-payments/code-protobuf-api v1.19.1-0.20250827160012-3edaffb82d79/go.mod h1:ee6TzKbgMS42ZJgaFEMG3c4R3dGOiffHSu6MrY7WQvs=
9385
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba h1:Bkp+gmeb6Y2PWXfkSCTMBGWkb2P1BujRDSjWeI+0j5I=
9486
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba/go.mod h1:jSiifpiBpyBQ8q2R0MGEbkSgWC6sbdRTyDBntmW+j1E=
9587
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=

pkg/code/common/owner.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ func GetLatestTokenAccountRecordsForOwner(ctx context.Context, data code_data.Pr
163163
}
164164
}
165165

166-
// The record should never exist, but this is precautionary. Pre-privacy timelock
167-
// accounts should only be used in a migration.
168-
delete(res, commonpb.AccountType_LEGACY_PRIMARY_2022)
169-
170166
return res, nil
171167
}
172168

pkg/code/common/owner_test.go

Lines changed: 18 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,16 @@ func TestGetLatestTokenAccountRecordsForOwner(t *testing.T) {
131131
require.NoError(t, err)
132132
assert.Empty(t, actual)
133133

134-
authority1 := newRandomTestAccount(t)
134+
authority1 := owner
135135
authority2 := newRandomTestAccount(t)
136136
authority3 := newRandomTestAccount(t)
137137
authority4 := newRandomTestAccount(t)
138-
authority5 := newRandomTestAccount(t)
139-
authority6 := newRandomTestAccount(t)
140-
authority7 := newRandomTestAccount(t)
141138

142139
for _, authorityAndType := range []struct {
143140
account *Account
144141
accountType commonpb.AccountType
145142
}{
146-
{authority1, commonpb.AccountType_BUCKET_1_KIN},
147-
{authority2, commonpb.AccountType_BUCKET_10_KIN},
143+
{authority1, commonpb.AccountType_PRIMARY},
148144
} {
149145
timelockAccounts, err := authorityAndType.account.GetTimelockAccounts(vmAccount, coreMintAccount)
150146
require.NoError(t, err)
@@ -162,14 +158,11 @@ func TestGetLatestTokenAccountRecordsForOwner(t *testing.T) {
162158
require.NoError(t, data.CreateAccountInfo(ctx, accountInfoRecord))
163159
}
164160

165-
for _, authorityAndRelationship := range []struct {
166-
account *Account
167-
domain string
168-
}{
169-
{authority3, "app1.com"},
170-
{authority4, "app2.com"},
161+
for i, authority := range []*Account{
162+
authority2,
163+
authority3,
171164
} {
172-
timelockAccounts, err := authorityAndRelationship.account.GetTimelockAccounts(vmAccount, coreMintAccount)
165+
timelockAccounts, err := authority.GetTimelockAccounts(vmAccount, coreMintAccount)
173166
require.NoError(t, err)
174167

175168
timelockRecord := timelockAccounts.ToDBRecord()
@@ -180,101 +173,56 @@ func TestGetLatestTokenAccountRecordsForOwner(t *testing.T) {
180173
AuthorityAccount: timelockRecord.VaultOwner,
181174
TokenAccount: timelockRecord.VaultAddress,
182175
MintAccount: coreMintAccount.PublicKey().ToBase58(),
183-
AccountType: commonpb.AccountType_RELATIONSHIP,
184-
RelationshipTo: &authorityAndRelationship.domain,
176+
AccountType: commonpb.AccountType_POOL,
177+
Index: uint64(i),
185178
}
186179
require.NoError(t, data.CreateAccountInfo(ctx, accountInfoRecord))
187180
}
188181

189-
swapAta, err := owner.ToAssociatedTokenAccount(authority5)
182+
swapAta, err := owner.ToAssociatedTokenAccount(authority4)
190183
require.NoError(t, err)
191184
swapAccountInfoRecord := &account.Record{
192185
OwnerAccount: owner.PublicKey().ToBase58(),
193-
AuthorityAccount: authority5.PublicKey().ToBase58(),
186+
AuthorityAccount: authority4.PublicKey().ToBase58(),
194187
TokenAccount: swapAta.PublicKey().ToBase58(),
195188
MintAccount: swapMintAccount.PublicKey().ToBase58(),
196189
AccountType: commonpb.AccountType_SWAP,
197190
}
198191
require.NoError(t, data.CreateAccountInfo(ctx, swapAccountInfoRecord))
199192

200-
for i, authority := range []*Account{
201-
authority6,
202-
authority7,
203-
} {
204-
timelockAccounts, err := authority.GetTimelockAccounts(vmAccount, coreMintAccount)
205-
require.NoError(t, err)
206-
207-
timelockRecord := timelockAccounts.ToDBRecord()
208-
require.NoError(t, data.SaveTimelock(ctx, timelockRecord))
209-
210-
accountInfoRecord := &account.Record{
211-
OwnerAccount: owner.PublicKey().ToBase58(),
212-
AuthorityAccount: timelockRecord.VaultOwner,
213-
TokenAccount: timelockRecord.VaultAddress,
214-
MintAccount: coreMintAccount.PublicKey().ToBase58(),
215-
AccountType: commonpb.AccountType_POOL,
216-
Index: uint64(i),
217-
}
218-
require.NoError(t, data.CreateAccountInfo(ctx, accountInfoRecord))
219-
}
220-
221193
actual, err = GetLatestTokenAccountRecordsForOwner(ctx, data, owner)
222194
require.NoError(t, err)
223-
require.Len(t, actual, 5)
195+
require.Len(t, actual, 3)
224196

225-
records, ok := actual[commonpb.AccountType_BUCKET_1_KIN]
197+
records, ok := actual[commonpb.AccountType_PRIMARY]
226198
require.True(t, ok)
227199
require.Len(t, records, 1)
228200
assert.Equal(t, records[0].General.AuthorityAccount, authority1.PublicKey().ToBase58())
229-
assert.Equal(t, records[0].General.AccountType, commonpb.AccountType_BUCKET_1_KIN)
201+
assert.Equal(t, records[0].General.AccountType, commonpb.AccountType_PRIMARY)
230202
assert.Equal(t, records[0].Timelock.VaultOwner, authority1.PublicKey().ToBase58())
231203
assert.Equal(t, records[0].General.TokenAccount, records[0].Timelock.VaultAddress)
232204

233-
records, ok = actual[commonpb.AccountType_BUCKET_10_KIN]
234-
require.True(t, ok)
235-
require.Len(t, records, 1)
236-
assert.Equal(t, records[0].General.AuthorityAccount, authority2.PublicKey().ToBase58())
237-
assert.Equal(t, records[0].General.AccountType, commonpb.AccountType_BUCKET_10_KIN)
238-
assert.Equal(t, records[0].Timelock.VaultOwner, authority2.PublicKey().ToBase58())
239-
assert.Equal(t, records[0].General.TokenAccount, records[0].Timelock.VaultAddress)
240-
241-
records, ok = actual[commonpb.AccountType_RELATIONSHIP]
242-
require.True(t, ok)
243-
require.Len(t, records, 2)
244-
245-
assert.Equal(t, records[0].General.AuthorityAccount, authority3.PublicKey().ToBase58())
246-
assert.Equal(t, records[0].General.AccountType, commonpb.AccountType_RELATIONSHIP)
247-
assert.Equal(t, records[0].Timelock.VaultOwner, authority3.PublicKey().ToBase58())
248-
assert.Equal(t, records[0].General.TokenAccount, records[0].Timelock.VaultAddress)
249-
assert.Equal(t, *records[0].General.RelationshipTo, "app1.com")
250-
251-
assert.Equal(t, records[1].General.AuthorityAccount, authority4.PublicKey().ToBase58())
252-
assert.Equal(t, records[1].General.AccountType, commonpb.AccountType_RELATIONSHIP)
253-
assert.Equal(t, records[1].Timelock.VaultOwner, authority4.PublicKey().ToBase58())
254-
assert.Equal(t, records[1].General.TokenAccount, records[1].Timelock.VaultAddress)
255-
assert.Equal(t, *records[1].General.RelationshipTo, "app2.com")
256-
257205
records, ok = actual[commonpb.AccountType_SWAP]
258206
require.True(t, ok)
259207
require.Len(t, records, 1)
260208
assert.Nil(t, records[0].Timelock)
261-
assert.Equal(t, records[0].General.AuthorityAccount, authority5.PublicKey().ToBase58())
209+
assert.Equal(t, records[0].General.AuthorityAccount, authority4.PublicKey().ToBase58())
262210
assert.Equal(t, records[0].General.TokenAccount, swapAta.PublicKey().ToBase58())
263211
assert.Equal(t, records[0].General.AccountType, commonpb.AccountType_SWAP)
264212

265213
records, ok = actual[commonpb.AccountType_POOL]
266214
require.True(t, ok)
267215
require.Len(t, records, 2)
268216

269-
assert.Equal(t, records[0].General.AuthorityAccount, authority6.PublicKey().ToBase58())
217+
assert.Equal(t, records[0].General.AuthorityAccount, authority2.PublicKey().ToBase58())
270218
assert.Equal(t, records[0].General.AccountType, commonpb.AccountType_POOL)
271-
assert.Equal(t, records[0].Timelock.VaultOwner, authority6.PublicKey().ToBase58())
219+
assert.Equal(t, records[0].Timelock.VaultOwner, authority2.PublicKey().ToBase58())
272220
assert.Equal(t, records[0].General.TokenAccount, records[0].Timelock.VaultAddress)
273221
assert.EqualValues(t, records[0].General.Index, 0)
274222

275-
assert.Equal(t, records[1].General.AuthorityAccount, authority7.PublicKey().ToBase58())
223+
assert.Equal(t, records[1].General.AuthorityAccount, authority3.PublicKey().ToBase58())
276224
assert.Equal(t, records[1].General.AccountType, commonpb.AccountType_POOL)
277-
assert.Equal(t, records[1].Timelock.VaultOwner, authority7.PublicKey().ToBase58())
225+
assert.Equal(t, records[1].Timelock.VaultOwner, authority3.PublicKey().ToBase58())
278226
assert.Equal(t, records[1].General.TokenAccount, records[1].Timelock.VaultAddress)
279227
assert.EqualValues(t, records[1].General.Index, 1)
280228
}

pkg/code/data/account/acccount_info.go

Lines changed: 6 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,13 @@ import (
66
"github.com/pkg/errors"
77

88
commonpb "github.com/code-payments/code-protobuf-api/generated/go/common/v1"
9-
10-
"github.com/code-payments/code-server/pkg/pointer"
119
)
1210

1311
var AllAccountTypes = []commonpb.AccountType{
1412
commonpb.AccountType_PRIMARY,
15-
commonpb.AccountType_TEMPORARY_INCOMING,
16-
commonpb.AccountType_TEMPORARY_OUTGOING,
17-
commonpb.AccountType_BUCKET_1_KIN,
18-
commonpb.AccountType_BUCKET_10_KIN,
19-
commonpb.AccountType_BUCKET_100_KIN,
20-
commonpb.AccountType_BUCKET_1_000_KIN,
21-
commonpb.AccountType_BUCKET_10_000_KIN,
22-
commonpb.AccountType_BUCKET_100_000_KIN,
23-
commonpb.AccountType_BUCKET_1_000_000_KIN,
2413
commonpb.AccountType_REMOTE_SEND_GIFT_CARD,
25-
commonpb.AccountType_RELATIONSHIP,
26-
commonpb.AccountType_SWAP,
2714
commonpb.AccountType_POOL,
15+
commonpb.AccountType_SWAP,
2816
}
2917

3018
type Record struct {
@@ -35,9 +23,8 @@ type Record struct {
3523
TokenAccount string
3624
MintAccount string
3725

38-
AccountType commonpb.AccountType
39-
Index uint64
40-
RelationshipTo *string
26+
AccountType commonpb.AccountType
27+
Index uint64
4128

4229
RequiresDepositSync bool
4330
DepositsLastSyncedAt time.Time
@@ -50,21 +37,6 @@ type Record struct {
5037
CreatedAt time.Time
5138
}
5239

53-
func (r *Record) IsBucket() bool {
54-
switch r.AccountType {
55-
case commonpb.AccountType_BUCKET_1_KIN,
56-
commonpb.AccountType_BUCKET_10_KIN,
57-
commonpb.AccountType_BUCKET_100_KIN,
58-
commonpb.AccountType_BUCKET_1_000_KIN,
59-
commonpb.AccountType_BUCKET_10_000_KIN,
60-
commonpb.AccountType_BUCKET_100_000_KIN,
61-
commonpb.AccountType_BUCKET_1_000_000_KIN:
62-
return true
63-
}
64-
65-
return false
66-
}
67-
6840
func (r *Record) Clone() Record {
6941
return Record{
7042
Id: r.Id,
@@ -74,7 +46,6 @@ func (r *Record) Clone() Record {
7446
MintAccount: r.MintAccount,
7547
AccountType: r.AccountType,
7648
Index: r.Index,
77-
RelationshipTo: pointer.StringCopy(r.RelationshipTo),
7849
RequiresDepositSync: r.RequiresDepositSync,
7950
DepositsLastSyncedAt: r.DepositsLastSyncedAt,
8051
RequiresAutoReturnCheck: r.RequiresAutoReturnCheck,
@@ -92,7 +63,6 @@ func (r *Record) CopyTo(dst *Record) {
9263
dst.MintAccount = r.MintAccount
9364
dst.AccountType = r.AccountType
9465
dst.Index = r.Index
95-
dst.RelationshipTo = pointer.StringCopy(dst.RelationshipTo)
9666
dst.RequiresDepositSync = r.RequiresDepositSync
9767
dst.DepositsLastSyncedAt = r.DepositsLastSyncedAt
9868
dst.RequiresAutoReturnCheck = r.RequiresAutoReturnCheck
@@ -123,8 +93,6 @@ func (r *Record) Validate() error {
12393
}
12494

12595
switch r.AccountType {
126-
case commonpb.AccountType_LEGACY_PRIMARY_2022:
127-
return errors.New("cannot store legacy primary 2022 account")
12896
case commonpb.AccountType_PRIMARY:
12997
if r.Index != 0 {
13098
return errors.New("index must be 0 for primary account")
@@ -141,37 +109,9 @@ func (r *Record) Validate() error {
141109
if r.OwnerAccount != r.AuthorityAccount {
142110
return errors.New("owner must be authority of remote send gift card account")
143111
}
144-
case commonpb.AccountType_RELATIONSHIP:
145-
if r.Index != 0 {
146-
return errors.New("index must be 0 for relationship account")
147-
}
148-
149-
if r.OwnerAccount == r.AuthorityAccount {
150-
return errors.New("owner cannot be authority for relationship account")
151-
}
152-
153-
if r.RelationshipTo == nil || len(*r.RelationshipTo) == 0 {
154-
return errors.New("relationship metadata required for relationship account")
155-
}
156-
case commonpb.AccountType_BUCKET_1_KIN,
157-
commonpb.AccountType_BUCKET_10_KIN,
158-
commonpb.AccountType_BUCKET_100_KIN,
159-
commonpb.AccountType_BUCKET_1_000_KIN,
160-
commonpb.AccountType_BUCKET_10_000_KIN,
161-
commonpb.AccountType_BUCKET_100_000_KIN,
162-
commonpb.AccountType_BUCKET_1_000_000_KIN:
163-
164-
if r.Index != 0 {
165-
return errors.New("index must be 0 for bucket account")
166-
}
167-
168-
if r.OwnerAccount == r.AuthorityAccount {
169-
return errors.New("owner cannot be authority for bucket account")
170-
}
171-
case commonpb.AccountType_TEMPORARY_INCOMING,
172-
commonpb.AccountType_TEMPORARY_OUTGOING:
112+
case commonpb.AccountType_POOL:
173113
if r.OwnerAccount == r.AuthorityAccount {
174-
return errors.New("owner cannot be authority for temporary rotating account")
114+
return errors.New("owner cannot be authority pool account")
175115
}
176116
case commonpb.AccountType_SWAP:
177117
if r.Index != 0 {
@@ -181,12 +121,8 @@ func (r *Record) Validate() error {
181121
if r.OwnerAccount == r.AuthorityAccount {
182122
return errors.New("owner cannot be authority for swap account")
183123
}
184-
case commonpb.AccountType_POOL:
185-
if r.OwnerAccount == r.AuthorityAccount {
186-
return errors.New("owner cannot be authority pool account")
187-
}
188124
default:
189-
return errors.Errorf("unhandled account type: %s", r.AccountType.String())
125+
return errors.Errorf("unsupported account type: %s", r.AccountType.String())
190126
}
191127

192128
if r.TokenAccount == r.OwnerAccount || r.TokenAccount == r.AuthorityAccount {
@@ -201,10 +137,6 @@ func (r *Record) Validate() error {
201137
return errors.New("only swap accounts can require swap retries")
202138
}
203139

204-
if r.RelationshipTo != nil && r.AccountType != commonpb.AccountType_RELATIONSHIP {
205-
return errors.New("only relationship accounts can have a relationship metadata")
206-
}
207-
208140
return nil
209141
}
210142

0 commit comments

Comments
 (0)