1syntax = "proto3";
2
3option go_package = "main";
4
5import "google/protobuf/empty.proto";
6import "google/protobuf/timestamp.proto";
7
8// Bank provides operations for interacting with bank accounts. All
9// operations operate for the authenticated user (identified via an
10// "authorization" request header, where the type is "token" and the
11// credential is the customer's ID).
12service Bank {
13    // OpenAccount creates an account with the type and given initial deposit
14    // as its balance.
15    rpc OpenAccount(OpenAccountRequest) returns (Account);
16    // CloseAccount closes the indicated account. An account can only be
17    // closed if its balance is zero.
18    rpc CloseAccount(CloseAccountRequest) returns (google.protobuf.Empty);
19    // GetAccounts lists all accounts for the current customer.
20    rpc GetAccounts(google.protobuf.Empty) returns (GetAccountsResponse);
21    // GetTransactions streams all transactions that match the given criteria.
22    // If the given start date is not specified, transactions since beginning
23    // of time are included. Similarly, if the given end date is not specified,
24    // transactions all the way to the presnet are included.
25    rpc GetTransactions(GetTransactionsRequest) returns (stream Transaction);
26    // Deposit increases the balance of an account by depositing funds into it.
27    rpc Deposit(DepositRequest) returns (BalanceResponse);
28    // Withdraw decreases the balance of an account by withdrawing funds from it.
29    rpc Withdraw(WithdrawRequest) returns (BalanceResponse);
30    // Transfer moves money from one account to another. The source and destination
31    // accounts can be with this bank (e.g. "local" account numbers) or can be
32    // external accounts, identified by their ACH routing and account numbers.
33    rpc Transfer(TransferRequest) returns (TransferResponse);
34}
35
36message OpenAccountRequest {
37    int32 initial_deposit_cents = 1;
38    Account.Type type = 2;
39}
40
41message CloseAccountRequest {
42    uint64 account_number = 1;
43}
44
45message GetAccountsResponse {
46    repeated Account accounts = 1;
47}
48
49message Account {
50    uint64 account_number = 1;
51    enum Type {
52        UNKNOWN = 0;
53        CHECKING = 1;
54        SAVING = 2;
55        MONEY_MARKET = 3;
56        LINE_OF_CREDIT = 4;
57        LOAN = 5;
58        EQUITIES = 6;
59    }
60    Type type = 2;
61    int32 balance_cents = 3;
62}
63
64message GetTransactionsRequest {
65    uint64 account_number = 1;
66    google.protobuf.Timestamp start = 2;
67    google.protobuf.Timestamp end = 3;
68}
69
70message Transaction {
71    uint64 account_number = 1;
72    uint64 seq_number = 2;
73    google.protobuf.Timestamp date = 3;
74    int32 amount_cents = 4;
75    string desc = 5;
76}
77
78message DepositRequest {
79    uint64 account_number = 1;
80    int32 amount_cents = 2;
81    enum Source {
82        UNKNOWN = 0;
83        CASH = 1;
84        CHECK = 2;
85        ACH = 3;
86        WIRE = 4;
87    }
88    Source source = 3;
89    string desc = 4;
90}
91
92message BalanceResponse {
93    uint64 account_number = 1;
94    int32 balance_cents = 2;
95}
96
97message WithdrawRequest {
98    uint64 account_number = 1;
99    int32 amount_cents = 2;
100    string desc = 3;
101}
102
103message TransferRequest {
104    message ExternalAccount {
105        uint64 ach_routing_number = 1;
106        uint64 ach_account_number = 2;
107    }
108    oneof source {
109        uint64 source_account_number = 1;
110        ExternalAccount external_source = 2;
111    }
112    oneof dest {
113        uint64 dest_account_number = 3;
114        ExternalAccount external_dest = 4;
115    }
116    int32 amount_cents = 5;
117    string desc = 6;
118}
119
120message TransferResponse {
121    uint64 src_account_number = 1;
122    int32 src_balance_cents = 2;
123    uint64 dest_account_number = 3;
124    int32 dest_balance_cents = 4;
125}
126