Skip to content

Commit

Permalink
arc status
Browse files Browse the repository at this point in the history
  • Loading branch information
David Case committed Nov 27, 2024
1 parent 3ddd892 commit 641a2de
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions transaction/broadcaster/arc.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type ArcResponse struct {
Instance *string `json:"instance,omitempty"`
Txid string `json:"txid,omitempty"`
Detail *string `json:"detail,omitempty"`
MerklePath string `json:"merklePath,omitempty"`
}

func (a *Arc) Broadcast(t *transaction.Transaction) (*transaction.BroadcastSuccess, *transaction.BroadcastFailure) {
Expand Down Expand Up @@ -185,3 +186,47 @@ func (a *Arc) Broadcast(t *transaction.Transaction) (*transaction.BroadcastSucce
Description: response.Title,
}
}

func (a *Arc) Status(txid string) (*ArcResponse, error) {
ctx := context.Background()
req, err := http.NewRequestWithContext(
ctx,
"GET",
a.ApiUrl+"/tx/"+txid,
nil,
)
if err != nil {
return nil, err
}

if a.ApiKey != "" {
req.Header.Set("Authorization", "Bearer "+a.ApiKey)
}

if a.Client == nil {
a.Client = http.DefaultClient
}
resp, err := a.Client.Do(req)
if err != nil {
return nil, err
}
defer func() {
if cerr := resp.Body.Close(); cerr != nil {
// Handle or log the error if needed
// For example:
fmt.Println(cerr)
}
}()
msg, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

response := &ArcResponse{}
err = json.Unmarshal(msg, &response)
if err != nil {
return nil, err
}

return response, nil
}

0 comments on commit 641a2de

Please sign in to comment.