2023-06-23 18:21:34 -07:00
|
|
|
package chains
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type algorandTransactionResponse struct {
|
|
|
|
Transaction struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Sender string `json:"sender"`
|
|
|
|
RoundTime int `json:"round-time"`
|
|
|
|
} `json:"transaction"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchAlgorandTx(
|
|
|
|
ctx context.Context,
|
2023-07-04 11:25:08 -07:00
|
|
|
rateLimiter *time.Ticker,
|
|
|
|
baseUrl string,
|
2023-06-23 18:21:34 -07:00
|
|
|
txHash string,
|
|
|
|
) (*TxDetail, error) {
|
|
|
|
|
2023-07-04 11:25:08 -07:00
|
|
|
// Call the transaction endpoint of the Algorand Indexer REST API
|
2023-06-23 18:21:34 -07:00
|
|
|
var response algorandTransactionResponse
|
2023-07-04 11:25:08 -07:00
|
|
|
{
|
|
|
|
// Perform the HTTP request
|
|
|
|
url := fmt.Sprintf("%s/v2/transactions/%s", baseUrl, txHash)
|
|
|
|
body, err := httpGet(ctx, rateLimiter, url)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("HTTP request to Algorand transactions endpoint failed: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode the response
|
|
|
|
if err := json.Unmarshal(body, &response); err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to decode Algorand transactions response as JSON: %w", err)
|
|
|
|
}
|
2023-06-23 18:21:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Populate the result struct and return
|
|
|
|
txDetail := TxDetail{
|
|
|
|
NativeTxHash: response.Transaction.ID,
|
|
|
|
From: response.Transaction.Sender,
|
|
|
|
}
|
|
|
|
return &txDetail, nil
|
|
|
|
}
|