Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTERNAL] /transaction/{transactionhash} returns TSSResponse #108

Merged
merged 9 commits into from
Jan 24, 2025
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ you can set it to any value. For production, you should set it to a secure passp
3. Start the containers:

```bash
docker-compose up
docker compose up
```

If things are set up correctly, you will see 4 containers started under the wallet-backend docker service: `api`, `db`,
Expand Down
18 changes: 14 additions & 4 deletions internal/serve/httphandler/tss_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package httphandler

import (
"fmt"
"net/http"

"github.com/stellar/go/support/log"
Expand Down Expand Up @@ -155,9 +156,18 @@ func (t *TSSHandler) GetTransaction(w http.ResponseWriter, r *http.Request) {
httperror.NotFound.Render(w)
}

httpjson.Render(w, GetTransactionResponse{
Hash: tx.Hash,
XDR: tx.XDR,
Status: tx.Status,
tssTry, err := t.Store.GetLatestTry(ctx, tx.Hash)
if err != nil {
httperror.InternalServerError(ctx, "unable to get tx try "+tx.Hash, err, nil, t.AppTracker).Render(w)
return
}

httpjson.Render(w, tss.TSSResponse{
TransactionHash: tx.Hash,
TransactionResultCode: fmt.Sprint(tssTry.Code),
Status: tx.Status,
CreatedAt: tx.CreatedAt.Unix(),
EnvelopeXDR: tssTry.XDR,
ResultXDR: tssTry.ResultXDR,
}, httpjson.JSON)
}
13 changes: 7 additions & 6 deletions internal/serve/httphandler/tss_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,13 @@ func TestGetTransaction(t *testing.T) {
resp := rw.Result()
respBody, err := io.ReadAll(resp.Body)
require.NoError(t, err)
var getTxResp GetTransactionResponse
var getTxResp tss.TSSResponse
_ = json.Unmarshal(respBody, &getTxResp)
fmt.Printf("%+v\n", getTxResp)

assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "hash", getTxResp.Hash)
assert.Equal(t, "xdr", getTxResp.XDR)
assert.Equal(t, "hash", getTxResp.TransactionHash)
assert.Equal(t, "0", getTxResp.TransactionResultCode)
assert.Equal(t, "NEW", getTxResp.Status)

clearTransactions(ctx)
Expand All @@ -290,12 +291,12 @@ func TestGetTransaction(t *testing.T) {
resp := rw.Result()
respBody, err := io.ReadAll(resp.Body)
require.NoError(t, err)
var getTxResp GetTransactionResponse
var getTxResp tss.TSSResponse
_ = json.Unmarshal(respBody, &getTxResp)

assert.Equal(t, http.StatusNotFound, resp.StatusCode)
assert.Empty(t, getTxResp.Hash)
assert.Empty(t, getTxResp.XDR)
assert.Empty(t, getTxResp.TransactionHash)
assert.Empty(t, getTxResp.EnvelopeXDR)
assert.Empty(t, getTxResp.Status)

})
Expand Down
Loading