Skip to content

Commit

Permalink
Add id to each reply
Browse files Browse the repository at this point in the history
  • Loading branch information
lil5 committed Dec 17, 2024
1 parent 6d146e0 commit 2121bec
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
12 changes: 12 additions & 0 deletions grpc/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
21 changes: 9 additions & 12 deletions grpc/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
)

type TimedPayloadResponse struct {
Results []types.TransferEventResult
Replies []*proto.CreateTransfersReplyItem
Error error
}
type TimedPayload struct {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
13 changes: 11 additions & 2 deletions proto/tigerbeetle.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto/tigerbeetle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ message CreateTransfersReply {
message CreateTransfersReplyItem {
int32 index = 1;
CreateTransferResult result = 2;
string id = 3;
}
message LookupAccountsRequest {
repeated string account_ids = 1;
Expand Down
14 changes: 3 additions & 11 deletions suite_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2121bec

Please sign in to comment.