ration/pkg/pb/cardissuance/card_issuance_grpc.pb.go
caelum0x 5bb6bc92f2 fix(card-issuance): persist card metadata — a restart silently lost every issued card forever
cardsvc.Service's own `cards map[string]*cardissuancepb.Card` was the
only place this repo stores Card metadata (ledger-core's proto has no
Card message), and it was pure in-memory state with zero durability.
A card-issuance restart lost every issued card's id/cardholder/limit/
status while the ledger HOLD backing its limit lived on in ledger-core
forever, unreachable by GetCard/AdjustCardLimit/CloseCard ever again
(all three look the card up by id first). card_issuance.proto's own
service comment also claimed this service was "stateless... safe to
run as N replicas" — false given this in-memory map; corrected.

Adds a file-backed store (services/card-issuance/internal/cardsvc/
store.go): atomic write-then-fsync-then-rename JSON file, loaded on
startup via a new EnablePersistence(path) method (opt-in, so existing
unit tests that never call it are unaffected) and written after every
IssueCard/AdjustCardLimit/CloseCard. New RATION_CARD_ISSUANCE_DATA_DIR
env var (default ./data, same convention as RATION_AUDIT_LOG_DATA_DIR),
wired in main.go.

Verified live against the real bare-metal stack: issued a card,
confirmed data/cards.json held it, killed and restarted card-issuance,
and confirmed `ration card get`/`ration status` still found the card
(pre-fix this would have been NotFound). go build/vet/test clean for
card-issuance (0 regressions), full `make build` clean.

Does not make this service safe to run as N replicas (each replica
would still load/save its own independent copy of the file) — that
needs a real shared store, the same class of gap already named and
left open for services/auth's apikey.Store; documented, not attempted,
in this round.
2026-10-29 13:53:46 +03:00

372 lines
16 KiB
Go

// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.6.2
// - protoc v6.33.4
// source: card_issuance.proto
package cardissuance
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
CardIssuance_IssueCard_FullMethodName = "/ration.cardissuance.v1.CardIssuance/IssueCard"
CardIssuance_AdjustCardLimit_FullMethodName = "/ration.cardissuance.v1.CardIssuance/AdjustCardLimit"
CardIssuance_GetCard_FullMethodName = "/ration.cardissuance.v1.CardIssuance/GetCard"
CardIssuance_ListCards_FullMethodName = "/ration.cardissuance.v1.CardIssuance/ListCards"
CardIssuance_CloseCard_FullMethodName = "/ration.cardissuance.v1.CardIssuance/CloseCard"
CardIssuance_RationBridgeFunding_FullMethodName = "/ration.cardissuance.v1.CardIssuance/RationBridgeFunding"
)
// CardIssuanceClient is the client API for CardIssuance service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
//
// CardIssuance is an internal-only service (docs/SCALE-EXPANSION.md
// section 1): a direct extraction of services/gateway's old
// internal/card (Airwallex issuing-card management) and internal/bridge
// (the rationing/bridge-funding math) — the highest-value service in the
// system per docs/adr/0004, since this is where real money decisions
// happen. Money-moving correctness under concurrent calls for one
// tenant rests on ledger-core's idempotent, reserve-floor-checked
// ApplyEntry, not on any lock here. That is NOT the same as "safe to
// run as N replicas" — this service's own internal/cardsvc owns the
// only copy of each Card's metadata (id, cardholder, limit, status;
// ledger-core's proto has no Card message), persisted to a single
// local file per process (cardsvc.Service.EnablePersistence). Two
// replicas behind a load balancer would each load/save their own
// independent copy of that file and can genuinely diverge — a card
// IssueCard creates on replica A is invisible to GetCard/ListCards on
// replica B. Multi-replica safety for this service needs a real shared
// store, not a local file; see docs/THREAT-MODEL.md for the write-up
// of what IS fixed (durability across a single process's own restart)
// versus what still requires that bigger, intentionally out-of-scope
// change.
//
// gateway.proto (the one public surface the TUI/CLI/agent dial) is
// unchanged by this split — services/gateway is the thin BFF that calls
// this service's RPCs and republishes their results on its own
// activity bus.
type CardIssuanceClient interface {
IssueCard(ctx context.Context, in *IssueCardRequest, opts ...grpc.CallOption) (*Card, error)
AdjustCardLimit(ctx context.Context, in *AdjustCardLimitRequest, opts ...grpc.CallOption) (*Card, error)
GetCard(ctx context.Context, in *GetCardRequest, opts ...grpc.CallOption) (*Card, error)
ListCards(ctx context.Context, in *ListCardsRequest, opts ...grpc.CallOption) (*ListCardsResponse, error)
// CloseCard permanently closes a card: releases its full remaining
// ledger hold back to the tenant's available balance and marks the
// card CARD_STATUS_CLOSED via Airwallex. Idempotent — closing an
// already-closed card returns it unchanged rather than erroring.
CloseCard(ctx context.Context, in *CloseCardRequest, opts ...grpc.CallOption) (*Card, error)
RationBridgeFunding(ctx context.Context, in *RationBridgeFundingRequest, opts ...grpc.CallOption) (*RationBridgeFundingResponse, error)
}
type cardIssuanceClient struct {
cc grpc.ClientConnInterface
}
func NewCardIssuanceClient(cc grpc.ClientConnInterface) CardIssuanceClient {
return &cardIssuanceClient{cc}
}
func (c *cardIssuanceClient) IssueCard(ctx context.Context, in *IssueCardRequest, opts ...grpc.CallOption) (*Card, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Card)
err := c.cc.Invoke(ctx, CardIssuance_IssueCard_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *cardIssuanceClient) AdjustCardLimit(ctx context.Context, in *AdjustCardLimitRequest, opts ...grpc.CallOption) (*Card, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Card)
err := c.cc.Invoke(ctx, CardIssuance_AdjustCardLimit_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *cardIssuanceClient) GetCard(ctx context.Context, in *GetCardRequest, opts ...grpc.CallOption) (*Card, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Card)
err := c.cc.Invoke(ctx, CardIssuance_GetCard_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *cardIssuanceClient) ListCards(ctx context.Context, in *ListCardsRequest, opts ...grpc.CallOption) (*ListCardsResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ListCardsResponse)
err := c.cc.Invoke(ctx, CardIssuance_ListCards_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *cardIssuanceClient) CloseCard(ctx context.Context, in *CloseCardRequest, opts ...grpc.CallOption) (*Card, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Card)
err := c.cc.Invoke(ctx, CardIssuance_CloseCard_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *cardIssuanceClient) RationBridgeFunding(ctx context.Context, in *RationBridgeFundingRequest, opts ...grpc.CallOption) (*RationBridgeFundingResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(RationBridgeFundingResponse)
err := c.cc.Invoke(ctx, CardIssuance_RationBridgeFunding_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// CardIssuanceServer is the server API for CardIssuance service.
// All implementations must embed UnimplementedCardIssuanceServer
// for forward compatibility.
//
// CardIssuance is an internal-only service (docs/SCALE-EXPANSION.md
// section 1): a direct extraction of services/gateway's old
// internal/card (Airwallex issuing-card management) and internal/bridge
// (the rationing/bridge-funding math) — the highest-value service in the
// system per docs/adr/0004, since this is where real money decisions
// happen. Money-moving correctness under concurrent calls for one
// tenant rests on ledger-core's idempotent, reserve-floor-checked
// ApplyEntry, not on any lock here. That is NOT the same as "safe to
// run as N replicas" — this service's own internal/cardsvc owns the
// only copy of each Card's metadata (id, cardholder, limit, status;
// ledger-core's proto has no Card message), persisted to a single
// local file per process (cardsvc.Service.EnablePersistence). Two
// replicas behind a load balancer would each load/save their own
// independent copy of that file and can genuinely diverge — a card
// IssueCard creates on replica A is invisible to GetCard/ListCards on
// replica B. Multi-replica safety for this service needs a real shared
// store, not a local file; see docs/THREAT-MODEL.md for the write-up
// of what IS fixed (durability across a single process's own restart)
// versus what still requires that bigger, intentionally out-of-scope
// change.
//
// gateway.proto (the one public surface the TUI/CLI/agent dial) is
// unchanged by this split — services/gateway is the thin BFF that calls
// this service's RPCs and republishes their results on its own
// activity bus.
type CardIssuanceServer interface {
IssueCard(context.Context, *IssueCardRequest) (*Card, error)
AdjustCardLimit(context.Context, *AdjustCardLimitRequest) (*Card, error)
GetCard(context.Context, *GetCardRequest) (*Card, error)
ListCards(context.Context, *ListCardsRequest) (*ListCardsResponse, error)
// CloseCard permanently closes a card: releases its full remaining
// ledger hold back to the tenant's available balance and marks the
// card CARD_STATUS_CLOSED via Airwallex. Idempotent — closing an
// already-closed card returns it unchanged rather than erroring.
CloseCard(context.Context, *CloseCardRequest) (*Card, error)
RationBridgeFunding(context.Context, *RationBridgeFundingRequest) (*RationBridgeFundingResponse, error)
mustEmbedUnimplementedCardIssuanceServer()
}
// UnimplementedCardIssuanceServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedCardIssuanceServer struct{}
func (UnimplementedCardIssuanceServer) IssueCard(context.Context, *IssueCardRequest) (*Card, error) {
return nil, status.Error(codes.Unimplemented, "method IssueCard not implemented")
}
func (UnimplementedCardIssuanceServer) AdjustCardLimit(context.Context, *AdjustCardLimitRequest) (*Card, error) {
return nil, status.Error(codes.Unimplemented, "method AdjustCardLimit not implemented")
}
func (UnimplementedCardIssuanceServer) GetCard(context.Context, *GetCardRequest) (*Card, error) {
return nil, status.Error(codes.Unimplemented, "method GetCard not implemented")
}
func (UnimplementedCardIssuanceServer) ListCards(context.Context, *ListCardsRequest) (*ListCardsResponse, error) {
return nil, status.Error(codes.Unimplemented, "method ListCards not implemented")
}
func (UnimplementedCardIssuanceServer) CloseCard(context.Context, *CloseCardRequest) (*Card, error) {
return nil, status.Error(codes.Unimplemented, "method CloseCard not implemented")
}
func (UnimplementedCardIssuanceServer) RationBridgeFunding(context.Context, *RationBridgeFundingRequest) (*RationBridgeFundingResponse, error) {
return nil, status.Error(codes.Unimplemented, "method RationBridgeFunding not implemented")
}
func (UnimplementedCardIssuanceServer) mustEmbedUnimplementedCardIssuanceServer() {}
func (UnimplementedCardIssuanceServer) testEmbeddedByValue() {}
// UnsafeCardIssuanceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to CardIssuanceServer will
// result in compilation errors.
type UnsafeCardIssuanceServer interface {
mustEmbedUnimplementedCardIssuanceServer()
}
func RegisterCardIssuanceServer(s grpc.ServiceRegistrar, srv CardIssuanceServer) {
// If the following call panics, it indicates UnimplementedCardIssuanceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&CardIssuance_ServiceDesc, srv)
}
func _CardIssuance_IssueCard_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(IssueCardRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CardIssuanceServer).IssueCard(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CardIssuance_IssueCard_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CardIssuanceServer).IssueCard(ctx, req.(*IssueCardRequest))
}
return interceptor(ctx, in, info, handler)
}
func _CardIssuance_AdjustCardLimit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AdjustCardLimitRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CardIssuanceServer).AdjustCardLimit(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CardIssuance_AdjustCardLimit_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CardIssuanceServer).AdjustCardLimit(ctx, req.(*AdjustCardLimitRequest))
}
return interceptor(ctx, in, info, handler)
}
func _CardIssuance_GetCard_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetCardRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CardIssuanceServer).GetCard(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CardIssuance_GetCard_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CardIssuanceServer).GetCard(ctx, req.(*GetCardRequest))
}
return interceptor(ctx, in, info, handler)
}
func _CardIssuance_ListCards_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListCardsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CardIssuanceServer).ListCards(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CardIssuance_ListCards_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CardIssuanceServer).ListCards(ctx, req.(*ListCardsRequest))
}
return interceptor(ctx, in, info, handler)
}
func _CardIssuance_CloseCard_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CloseCardRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CardIssuanceServer).CloseCard(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CardIssuance_CloseCard_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CardIssuanceServer).CloseCard(ctx, req.(*CloseCardRequest))
}
return interceptor(ctx, in, info, handler)
}
func _CardIssuance_RationBridgeFunding_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RationBridgeFundingRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CardIssuanceServer).RationBridgeFunding(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CardIssuance_RationBridgeFunding_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CardIssuanceServer).RationBridgeFunding(ctx, req.(*RationBridgeFundingRequest))
}
return interceptor(ctx, in, info, handler)
}
// CardIssuance_ServiceDesc is the grpc.ServiceDesc for CardIssuance service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var CardIssuance_ServiceDesc = grpc.ServiceDesc{
ServiceName: "ration.cardissuance.v1.CardIssuance",
HandlerType: (*CardIssuanceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "IssueCard",
Handler: _CardIssuance_IssueCard_Handler,
},
{
MethodName: "AdjustCardLimit",
Handler: _CardIssuance_AdjustCardLimit_Handler,
},
{
MethodName: "GetCard",
Handler: _CardIssuance_GetCard_Handler,
},
{
MethodName: "ListCards",
Handler: _CardIssuance_ListCards_Handler,
},
{
MethodName: "CloseCard",
Handler: _CardIssuance_CloseCard_Handler,
},
{
MethodName: "RationBridgeFunding",
Handler: _CardIssuance_RationBridgeFunding_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "card_issuance.proto",
}