diff --git a/grpc/convert.go b/grpc/convert.go index bcde1e1..7a51ef0 100644 --- a/grpc/convert.go +++ b/grpc/convert.go @@ -110,3 +110,15 @@ func HexStringToUint128(hex string) (*types.Uint128, error) { return &res, nil } + +func ResultsToReply(results []types.TransferEventResult, transfers []types.Transfer, err error) (replies []*proto.CreateTransfersReplyItem) { + replies = make([]*proto.CreateTransfersReplyItem, len(results)) + for _, r := range results { + replies = append(replies, &proto.CreateTransfersReplyItem{ + Index: int32(r.Index), + Result: proto.CreateTransferResult(r.Result), + Id: transfers[r.Index].ID.String(), + }) + } + return +} diff --git a/grpc/routes.go b/grpc/routes.go index eff1e99..4b68d41 100644 --- a/grpc/routes.go +++ b/grpc/routes.go @@ -21,7 +21,7 @@ var ( ) type TimedPayloadResponse struct { - Results []types.TransferEventResult + Replies []*proto.CreateTransfersReplyItem Error error } type TimedPayload struct { @@ -94,8 +94,9 @@ func NewApp() *App { metrics.TotalCreateTransferTx.Add(float64(len(transfers))) results, err := tigerbeetle_go.CreateTransfers(transfers) + replies := ResultsToReply(results, transfers, err) res := TimedPayloadResponse{ - Results: results, + Replies: replies, Error: err, } for _, payload := range payloads { @@ -225,8 +226,8 @@ func (s *App) CreateTransfers(ctx context.Context, in *proto.CreateTransfersRequ }) } - var results []types.TransferEventResult var err error + replies := []*proto.CreateTransfersReplyItem{} if Config.IsBuffered { buf := s.getRandomTBuf() c := make(chan TimedPayloadResponse) @@ -236,24 +237,20 @@ func (s *App) CreateTransfers(ctx context.Context, in *proto.CreateTransfersRequ Transfers: transfers, }) res := <-c - results = res.Results + replies = res.Replies err = res.Error } else { + var results []types.TransferEventResult results, err = s.TB.CreateTransfers(transfers) + replies = ResultsToReply(results, transfers, err) } if err != nil { return nil, err } - resArr := []*proto.CreateTransfersReplyItem{} - for _, r := range results { - resArr = append(resArr, &proto.CreateTransfersReplyItem{ - Index: int32(r.Index), - Result: proto.CreateTransferResult(r.Result), - }) - } + return &proto.CreateTransfersReply{ - Results: resArr, + Results: replies, }, nil } diff --git a/proto/tigerbeetle.pb.go b/proto/tigerbeetle.pb.go index 042ba20..0164b73 100644 --- a/proto/tigerbeetle.pb.go +++ b/proto/tigerbeetle.pb.go @@ -709,6 +709,7 @@ type CreateTransfersReplyItem struct { Index int32 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` Result CreateTransferResult `protobuf:"varint,2,opt,name=result,proto3,enum=proto.CreateTransferResult" json:"result,omitempty"` + Id string `protobuf:"bytes,3,opt,name=id,proto3" json:"id,omitempty"` } func (x *CreateTransfersReplyItem) Reset() { @@ -755,6 +756,13 @@ func (x *CreateTransfersReplyItem) GetResult() CreateTransferResult { return CreateTransferResult_TransferOK } +func (x *CreateTransfersReplyItem) GetId() string { + if x != nil { + return x.Id + } + return "" +} + type LookupAccountsRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1785,13 +1793,14 @@ var file_proto_tigerbeetle_proto_rawDesc = []byte{ 0x73, 0x75, 0x6c, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x07, 0x72, 0x65, - 0x73, 0x75, 0x6c, 0x74, 0x73, 0x22, 0x65, 0x0a, 0x18, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, + 0x73, 0x75, 0x6c, 0x74, 0x73, 0x22, 0x75, 0x0a, 0x18, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x49, 0x74, 0x65, 0x6d, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x12, 0x33, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x52, 0x65, - 0x73, 0x75, 0x6c, 0x74, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x38, 0x0a, 0x15, + 0x73, 0x75, 0x6c, 0x74, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x0e, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x38, 0x0a, 0x15, 0x4c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x63, 0x63, 0x6f, diff --git a/proto/tigerbeetle.proto b/proto/tigerbeetle.proto index cfa3c7e..f2a775b 100644 --- a/proto/tigerbeetle.proto +++ b/proto/tigerbeetle.proto @@ -42,6 +42,7 @@ message CreateTransfersReply { message CreateTransfersReplyItem { int32 index = 1; CreateTransferResult result = 2; + string id = 3; } message LookupAccountsRequest { repeated string account_ids = 1; diff --git a/suite_e2e_test.go b/suite_e2e_test.go index eb2b48d..8fe7b76 100644 --- a/suite_e2e_test.go +++ b/suite_e2e_test.go @@ -109,18 +109,10 @@ func (s *MyTestSuite) TestCalls() { _, resultFunc := MockGinContext(s.router, http.MethodPost, "/accounts/create", &gin.H{ "accounts": []gin.H{ { - "user_data_128": nil, - "user_data_64": nil, - "user_data_32": nil, - "id": accountID1, - "debits_pending": 0, - "debits_posted": 0, - "credits_pending": 0, - "credits_posted": 0, - "ledger": LEDGER, - "code": 1, + "id": accountID1, + "ledger": LEDGER, + "code": 1, "flags": gin.H{ - "linked": false, "credits_must_not_exceed_debits": creditsMustNotExceedDebits, "debits_must_not_exceed_credits": debitsMustNotExceedCredits, "history": true,