@@ -41,9 +41,9 @@ func (s *submitServiceServer) SubmitTx(
4141 ctx context.Context ,
4242 req * connect.Request [submit.SubmitTxRequest ],
4343) (* connect.Response [submit.SubmitTxResponse ], error ) {
44- // txRawList
45- txRawList := req .Msg .GetTx () // [] *AnyChainTx
46- log .Printf ("Got a SubmitTx request with %d transactions" , len ( txRawList ) )
44+ // txRaw
45+ txRaw := req .Msg .GetTx () // *AnyChainTx
46+ log .Printf ("Got a SubmitTx request with 1 transaction" )
4747 resp := & submit.SubmitTxResponse {}
4848
4949 // Connect to node
@@ -56,42 +56,27 @@ func (s *submitServiceServer) SubmitTx(
5656 oConn .Close ()
5757 }()
5858
59- // Loop through the transactions and submit each
60- errorList := make ([]error , len (txRawList ))
61- hasError := false
62- for i , txi := range txRawList {
63- txRawBytes := txi .GetRaw () // raw bytes
64- txType , err := ledger .DetermineTransactionType (txRawBytes )
65- placeholderRef := []byte {}
66- if err != nil {
67- resp .Ref = append (resp .Ref , placeholderRef )
68- errorList [i ] = err
69- hasError = true
70- continue
71- }
72- tx , err := ledger .NewTransactionFromCbor (txType , txRawBytes )
73- if err != nil {
74- resp .Ref = append (resp .Ref , placeholderRef )
75- errorList [i ] = err
76- hasError = true
77- continue
78- }
79- // Submit the transaction
80- err = oConn .LocalTxSubmission ().Client .SubmitTx (
81- uint16 (txType ), // #nosec G115
82- txRawBytes ,
83- )
84- if err != nil {
85- resp .Ref = append (resp .Ref , placeholderRef )
86- errorList [i ] = fmt .Errorf ("%s" , err .Error ())
87- hasError = true
88- continue
89- }
90- resp .Ref = append (resp .Ref , tx .Hash ().Bytes ())
59+ txRawBytes := txRaw .GetRaw () // raw bytes
60+ txType , err := ledger .DetermineTransactionType (txRawBytes )
61+ if err != nil {
62+ resp .Ref = []byte {}
63+ return connect .NewResponse (resp ), err
9164 }
92- if hasError {
93- return connect .NewResponse (resp ), fmt .Errorf ("%v" , errorList )
65+ tx , err := ledger .NewTransactionFromCbor (txType , txRawBytes )
66+ if err != nil {
67+ resp .Ref = []byte {}
68+ return connect .NewResponse (resp ), err
69+ }
70+ // Submit the transaction
71+ err = oConn .LocalTxSubmission ().Client .SubmitTx (
72+ uint16 (txType ), // #nosec G115
73+ txRawBytes ,
74+ )
75+ if err != nil {
76+ resp .Ref = []byte {}
77+ return connect .NewResponse (resp ), err
9478 }
79+ resp .Ref = tx .Hash ().Bytes ()
9580 return connect .NewResponse (resp ), nil
9681}
9782
0 commit comments