Skip to content
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
filippo.io/edwards25519 v1.1.0
github.com/aws/aws-sdk-go-v2 v0.17.0
github.com/code-payments/code-vm-indexer v1.2.0
github.com/code-payments/ocp-protobuf-api v0.2.1
github.com/code-payments/ocp-protobuf-api v0.3.0
github.com/emirpasic/gods v1.12.0
github.com/envoyproxy/protoc-gen-validate v1.2.1
github.com/golang/protobuf v1.5.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/code-payments/code-vm-indexer v1.2.0 h1:rSHpBMiT9BKgmKcXg/VIoi/h0t7jNxGx07Qz59m+6Q0=
github.com/code-payments/code-vm-indexer v1.2.0/go.mod h1:vn91YN2qNqb+gGJeZe2+l+TNxVmEEiRHXXnIn2Y40h8=
github.com/code-payments/ocp-protobuf-api v0.2.1 h1:w/S9t8sfQ1e7Ziw1K9gVvE7WchwC1D3AWD3E8ZQg8Ts=
github.com/code-payments/ocp-protobuf-api v0.2.1/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8=
github.com/code-payments/ocp-protobuf-api v0.3.0 h1:44o1+BMFz1eq5H7tsivp8p/rleuHMeetxEL3tUIRV0I=
github.com/code-payments/ocp-protobuf-api v0.3.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
Expand Down
8 changes: 4 additions & 4 deletions ocp/common/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type OwnerManagementState uint8

const (
OwnerManagementStateUnknown OwnerManagementState = iota
OwnerManagementStateCodeAccount
OwnerManagementStateOcpAccount
OwnerManagementStateNotFound
OwnerManagementStateUnlocked
)
Expand Down Expand Up @@ -110,7 +110,7 @@ func GetOwnerManagementState(ctx context.Context, data ocp_data.Provider, owner
}
}

return OwnerManagementStateCodeAccount, nil
return OwnerManagementStateOcpAccount, nil
}

// GetLatestTokenAccountRecordsForOwner gets DB records for the latest set of
Expand Down Expand Up @@ -228,8 +228,8 @@ func (t OwnerManagementState) String() string {
return "not_found"
case OwnerManagementStateUnlocked:
return "unlocked"
case OwnerManagementStateCodeAccount:
return "code_account"
case OwnerManagementStateOcpAccount:
return "ocp_account"
}
return "unknown"
}
6 changes: 3 additions & 3 deletions ocp/common/owner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestGetOwnerMetadata_User12Words(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, actual.Account.PublicKey().ToBase58(), owner.PublicKey().ToBase58())
assert.Equal(t, OwnerTypeUser12Words, actual.Type)
assert.Equal(t, OwnerManagementStateCodeAccount, actual.State)
assert.Equal(t, OwnerManagementStateOcpAccount, actual.State)

// Add swap account

Expand All @@ -68,7 +68,7 @@ func TestGetOwnerMetadata_User12Words(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, actual.Account.PublicKey().ToBase58(), owner.PublicKey().ToBase58())
assert.Equal(t, OwnerTypeUser12Words, actual.Type)
assert.Equal(t, OwnerManagementStateCodeAccount, actual.State)
assert.Equal(t, OwnerManagementStateOcpAccount, actual.State)

// Unlock a Timelock account

Expand Down Expand Up @@ -113,7 +113,7 @@ func TestGetOwnerMetadata_RemoteSendGiftCard(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, actual.Account.PublicKey().ToBase58(), owner.PublicKey().ToBase58())
assert.Equal(t, OwnerTypeRemoteSendGiftCard, actual.Type)
assert.Equal(t, OwnerManagementStateCodeAccount, actual.State)
assert.Equal(t, OwnerManagementStateOcpAccount, actual.State)
}

func TestGetLatestTokenAccountRecordsForOwner(t *testing.T) {
Expand Down
24 changes: 12 additions & 12 deletions ocp/rpc/account/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func NewAccountServer(log *zap.Logger, data ocp_data.Provider) accountpb.Account
}
}

func (s *server) IsCodeAccount(ctx context.Context, req *accountpb.IsCodeAccountRequest) (*accountpb.IsCodeAccountResponse, error) {
log := s.log.With(zap.String("method", "IsCodeAccount"))
func (s *server) IsOcpAccount(ctx context.Context, req *accountpb.IsOcpAccountRequest) (*accountpb.IsOcpAccountResponse, error) {
log := s.log.With(zap.String("method", "IsOcpAccount"))
log = client.InjectLoggingMetadata(ctx, log)

owner, err := common.NewAccountFromProto(req.Owner)
Expand All @@ -70,34 +70,34 @@ func (s *server) IsCodeAccount(ctx context.Context, req *accountpb.IsCodeAccount

ownerMetadata, err := common.GetOwnerMetadata(ctx, s.data, owner)
if err == common.ErrOwnerNotFound {
return &accountpb.IsCodeAccountResponse{
Result: accountpb.IsCodeAccountResponse_NOT_FOUND,
return &accountpb.IsOcpAccountResponse{
Result: accountpb.IsOcpAccountResponse_NOT_FOUND,
}, nil
} else if err != nil {
log.With(zap.Error(err)).Warn("failure getting owner management state")
return nil, status.Error(codes.Internal, "")
}

if ownerMetadata.Type != common.OwnerTypeUser12Words {
return &accountpb.IsCodeAccountResponse{
Result: accountpb.IsCodeAccountResponse_NOT_FOUND,
return &accountpb.IsOcpAccountResponse{
Result: accountpb.IsOcpAccountResponse_NOT_FOUND,
}, nil
}

var result accountpb.IsCodeAccountResponse_Result
var result accountpb.IsOcpAccountResponse_Result
switch ownerMetadata.State {
case common.OwnerManagementStateCodeAccount:
result = accountpb.IsCodeAccountResponse_OK
case common.OwnerManagementStateOcpAccount:
result = accountpb.IsOcpAccountResponse_OK
case common.OwnerManagementStateNotFound:
result = accountpb.IsCodeAccountResponse_NOT_FOUND
result = accountpb.IsOcpAccountResponse_NOT_FOUND
case common.OwnerManagementStateUnlocked:
result = accountpb.IsCodeAccountResponse_UNLOCKED_TIMELOCK_ACCOUNT
result = accountpb.IsOcpAccountResponse_UNLOCKED_TIMELOCK_ACCOUNT
case common.OwnerManagementStateUnknown:
log.Warn("unknown owner management state")
return nil, status.Error(codes.Internal, "")
}

return &accountpb.IsCodeAccountResponse{
return &accountpb.IsOcpAccountResponse{
Result: result,
}, nil
}
Expand Down
32 changes: 16 additions & 16 deletions ocp/rpc/account/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func setup(t *testing.T) (env testEnv, cleanup func()) {
return env, cleanup
}

func TestIsCodeAccount_HappyPath(t *testing.T) {
func TestIsOcpAccount_HappyPath(t *testing.T) {
env, cleanup := setup(t)
defer cleanup()

Expand All @@ -73,7 +73,7 @@ func TestIsCodeAccount_HappyPath(t *testing.T) {
ownerAccount := testutil.NewRandomAccount(t)
swapAuthorityAccount := testutil.NewRandomAccount(t)

req := &accountpb.IsCodeAccountRequest{
req := &accountpb.IsOcpAccountRequest{
Owner: ownerAccount.ToProto(),
}
reqBytes, err := proto.Marshal(req)
Expand All @@ -82,21 +82,21 @@ func TestIsCodeAccount_HappyPath(t *testing.T) {
Value: ed25519.Sign(ownerAccount.PrivateKey().ToBytes(), reqBytes),
}

resp, err := env.client.IsCodeAccount(env.ctx, req)
resp, err := env.client.IsOcpAccount(env.ctx, req)
require.NoError(t, err)
assert.Equal(t, accountpb.IsCodeAccountResponse_NOT_FOUND, resp.Result)
assert.Equal(t, accountpb.IsOcpAccountResponse_NOT_FOUND, resp.Result)

// Technically an invalid reality, but SubmitIntent guarantees all or no accounts
// are opened, which allows IsCodeAccount to do lazy checking.
setupAccountRecords(t, env, ownerAccount, ownerAccount, coreVmConfig, 0, commonpb.AccountType_PRIMARY)
setupAccountRecords(t, env, ownerAccount, swapAuthorityAccount, swapVmConfig, 0, commonpb.AccountType_SWAP)

resp, err = env.client.IsCodeAccount(env.ctx, req)
resp, err = env.client.IsOcpAccount(env.ctx, req)
require.NoError(t, err)
assert.Equal(t, accountpb.IsCodeAccountResponse_OK, resp.Result)
assert.Equal(t, accountpb.IsOcpAccountResponse_OK, resp.Result)
}

func TestIsCodeAccount_NotManagedByCode(t *testing.T) {
func TestIsOcpAccount_NotManagedByCode(t *testing.T) {
for _, unmanagedState := range []timelock_token_v1.TimelockState{
timelock_token_v1.StateWaitingForTimeout,
timelock_token_v1.StateUnlocked,
Expand All @@ -108,7 +108,7 @@ func TestIsCodeAccount_NotManagedByCode(t *testing.T) {

ownerAccount := testutil.NewRandomAccount(t)

req := &accountpb.IsCodeAccountRequest{
req := &accountpb.IsOcpAccountRequest{
Owner: ownerAccount.ToProto(),
}
reqBytes, err := proto.Marshal(req)
Expand All @@ -117,24 +117,24 @@ func TestIsCodeAccount_NotManagedByCode(t *testing.T) {
Value: ed25519.Sign(ownerAccount.PrivateKey().ToBytes(), reqBytes),
}

resp, err := env.client.IsCodeAccount(env.ctx, req)
resp, err := env.client.IsOcpAccount(env.ctx, req)
require.NoError(t, err)
assert.Equal(t, accountpb.IsCodeAccountResponse_NOT_FOUND, resp.Result)
assert.Equal(t, accountpb.IsOcpAccountResponse_NOT_FOUND, resp.Result)

var allAccountRecords []*common.AccountRecords
allAccountRecords = append(allAccountRecords, setupAccountRecords(t, env, ownerAccount, ownerAccount, coreVmConfig, 0, commonpb.AccountType_PRIMARY))

resp, err = env.client.IsCodeAccount(env.ctx, req)
resp, err = env.client.IsOcpAccount(env.ctx, req)
require.NoError(t, err)
assert.Equal(t, accountpb.IsCodeAccountResponse_OK, resp.Result)
assert.Equal(t, accountpb.IsOcpAccountResponse_OK, resp.Result)

allAccountRecords[0].Timelock.VaultState = unmanagedState
allAccountRecords[0].Timelock.Block += 1
require.NoError(t, env.data.SaveTimelock(env.ctx, allAccountRecords[0].Timelock))

resp, err = env.client.IsCodeAccount(env.ctx, req)
resp, err = env.client.IsOcpAccount(env.ctx, req)
require.NoError(t, err)
assert.Equal(t, accountpb.IsCodeAccountResponse_UNLOCKED_TIMELOCK_ACCOUNT, resp.Result)
assert.Equal(t, accountpb.IsOcpAccountResponse_UNLOCKED_TIMELOCK_ACCOUNT, resp.Result)
}
}

Expand Down Expand Up @@ -669,7 +669,7 @@ func TestUnauthenticatedRPC(t *testing.T) {
requestingOwnerAccount := testutil.NewRandomAccount(t)
maliciousAccount := testutil.NewRandomAccount(t)

isCodeAccountReq := &accountpb.IsCodeAccountRequest{
isCodeAccountReq := &accountpb.IsOcpAccountRequest{
Owner: ownerAccount.ToProto(),
}
reqBytes, err := proto.Marshal(isCodeAccountReq)
Expand All @@ -678,7 +678,7 @@ func TestUnauthenticatedRPC(t *testing.T) {
Value: ed25519.Sign(maliciousAccount.PrivateKey().ToBytes(), reqBytes),
}

_, err = env.client.IsCodeAccount(env.ctx, isCodeAccountReq)
_, err = env.client.IsOcpAccount(env.ctx, isCodeAccountReq)
testutil.AssertStatusErrorWithCode(t, err, codes.Unauthenticated)

getTokenAccountInfosReq := &accountpb.GetTokenAccountInfosRequest{
Expand Down
4 changes: 2 additions & 2 deletions ocp/rpc/transaction/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func (s *transactionServer) StartSwap(streamer transactionpb.Transaction_StartSw
log.With(zap.Error(err)).Warn("failure getting owner management state")
return handleStartSwapError(streamer, err)
}
if ownerManagemntState != common.OwnerManagementStateCodeAccount {
return handleStartSwapError(streamer, NewSwapDeniedError("not a code account"))
if ownerManagemntState != common.OwnerManagementStateOcpAccount {
return handleStartSwapError(streamer, NewSwapDeniedError("not an ocp account"))
}

allow, err := s.antispamGuard.AllowSwap(ctx, owner, fromMint, toMint)
Expand Down
Loading