diff --git a/go.mod b/go.mod index 1fabb7f..ec51333 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index b709580..2bddc33 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/ocp/common/owner.go b/ocp/common/owner.go index a4f9e62..8f74a5d 100644 --- a/ocp/common/owner.go +++ b/ocp/common/owner.go @@ -28,7 +28,7 @@ type OwnerManagementState uint8 const ( OwnerManagementStateUnknown OwnerManagementState = iota - OwnerManagementStateCodeAccount + OwnerManagementStateOcpAccount OwnerManagementStateNotFound OwnerManagementStateUnlocked ) @@ -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 @@ -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" } diff --git a/ocp/common/owner_test.go b/ocp/common/owner_test.go index b7ae5d4..6d55554 100644 --- a/ocp/common/owner_test.go +++ b/ocp/common/owner_test.go @@ -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 @@ -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 @@ -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) { diff --git a/ocp/rpc/account/server.go b/ocp/rpc/account/server.go index 413b5ea..4ed7603 100644 --- a/ocp/rpc/account/server.go +++ b/ocp/rpc/account/server.go @@ -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) @@ -70,8 +70,8 @@ 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") @@ -79,25 +79,25 @@ func (s *server) IsCodeAccount(ctx context.Context, req *accountpb.IsCodeAccount } 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 } diff --git a/ocp/rpc/account/server_test.go b/ocp/rpc/account/server_test.go index 1c9e864..065d037 100644 --- a/ocp/rpc/account/server_test.go +++ b/ocp/rpc/account/server_test.go @@ -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() @@ -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) @@ -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, @@ -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) @@ -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) } } @@ -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) @@ -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{ diff --git a/ocp/rpc/transaction/swap.go b/ocp/rpc/transaction/swap.go index 1fc6cd6..6647865 100644 --- a/ocp/rpc/transaction/swap.go +++ b/ocp/rpc/transaction/swap.go @@ -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)