Skip to content

Commit

Permalink
Merge pull request #19 from blinklabs-io/feat/txmanager
Browse files Browse the repository at this point in the history
feat: support /txmanager endpoints
  • Loading branch information
Vardominator authored Sep 23, 2023
2 parents 5439f00 + c0e6377 commit 603c2be
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
68 changes: 68 additions & 0 deletions client/txmanager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package client

import (
"encoding/json"
"fmt"

"github.com/maestro-org/go-sdk/models"
)

func (c *Client) TxManagerHistory() (*[]models.TxManagerState, error) {
url := "/txmanager/history"
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var txManagerStates []models.TxManagerState
err = json.NewDecoder(resp.Body).Decode(&txManagerStates)
if err != nil {
return nil, err
}
return &txManagerStates, nil
}

func (c *Client) TxManagerSubmit(cbor string) (models.BasicResponse, error) {
url := "/txmanager"
resp, err := c.post(url, cbor)
if err != nil {
return models.BasicResponse{}, err
}
defer resp.Body.Close()
var submitTx models.BasicResponse
err = json.NewDecoder(resp.Body).Decode(&submitTx)
if err != nil {
return models.BasicResponse{}, err
}
return submitTx, nil
}

func (c *Client) TxManagerSubmitTurbo(cbor string) (models.BasicResponse, error) {
url := "/txmanager/turbosubmit"
resp, err := c.post(url, cbor)
if err != nil {
return models.BasicResponse{}, err
}
defer resp.Body.Close()
var submitTx models.BasicResponse
err = json.NewDecoder(resp.Body).Decode(&submitTx)
if err != nil {
return models.BasicResponse{}, err
}
return submitTx, nil
}

func (c *Client) TxManagerState(txHash string) (*models.TxManagerState, error) {
url := fmt.Sprintf("/txmanager/%s/state", txHash)
resp, err := c.get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var txManagerState models.TxManagerState
err = json.NewDecoder(resp.Body).Decode(&txManagerState)
if err != nil {
return nil, err
}
return &txManagerState, nil
}
2 changes: 2 additions & 0 deletions models/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ type Certificates struct {
StakeDeregistrations []any `json:"stake_deregistrations"`
StakeRegistrationsReserves []any `json:"stake_registrations_reserves"`
}

type Redeemers struct {
Certificates []any `json:"certificates"`
Mints []any `json:"mints"`
Spends []any `json:"spends"`
Withdrawals []any `json:"withdrawals"`
}

type TransactionDetail struct {
AdditionalSigners []string `json:"additional_signers"`
BlockAbsoluteSlot int64 `json:"block_absolute_slot"`
Expand Down
8 changes: 8 additions & 0 deletions models/txmanager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package models

type TxManagerState struct {
Block string `json:"block"` // Block number
State string `json:"state"` // Transaction state
Timestamp string `json:"timestamp"` // Timestamp of last state change
TransactionHash string `json:"transaction_hash"` // Transaction hash
}

0 comments on commit 603c2be

Please sign in to comment.