Skip to content

Commit

Permalink
nft history + clio client
Browse files Browse the repository at this point in the history
  • Loading branch information
CreatureDev committed Feb 8, 2024
1 parent a7360f8 commit 456af3b
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type XRPLClient struct {
Path Path
Subscription Subscription
Transaction Transaction
Server Server
Clio Clio
}

type XRPLRequest interface {
Expand Down Expand Up @@ -39,6 +41,7 @@ func NewXRPLClient(cl Client) *XRPLClient {
Path: &pathImpl{client: cl},
Subscription: &subscriptionImpl{client: cl},
Transaction: &transactionImpl{client: cl},
Clio: &clioImpl{client: cl},
}
}

Expand Down
66 changes: 66 additions & 0 deletions client/clio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package client

import "github.com/CreatureDev/xrpl-go/model/client/clio"

type Clio interface {
ServerInfo(*clio.ServerInfoRequest) (*clio.ServerInfoResponse, XRPLResponse, error)
Ledger(*clio.LedgerRequest) (*clio.LedgerResponse, XRPLResponse, error)
NFTHistory(*clio.NFTHistoryRequest) (*clio.NFTHistoryResponse, XRPLResponse, error)
NFTInfo(*clio.NFTInfoRequest) (*clio.NFTInfoResponse, XRPLResponse, error)
}

type clioImpl struct {
client Client
}

func (c *clioImpl) ServerInfo(req *clio.ServerInfoRequest) (*clio.ServerInfoResponse, XRPLResponse, error) {
res, err := c.client.SendRequest(req)
if err != nil {
return nil, nil, err
}
var sr clio.ServerInfoResponse
err = res.GetResult(&sr)
if err != nil {
return nil, nil, err
}
return &sr, res, nil
}

func (c *clioImpl) Ledger(req *clio.LedgerRequest) (*clio.LedgerResponse, XRPLResponse, error) {
res, err := c.client.SendRequest(req)
if err != nil {
return nil, nil, err
}
var lr clio.LedgerResponse
err = res.GetResult(&lr)
if err != nil {
return nil, nil, err
}
return &lr, res, nil
}

func (c *clioImpl) NFTHistory(req *clio.NFTHistoryRequest) (*clio.NFTHistoryResponse, XRPLResponse, error) {
res, err := c.client.SendRequest(req)
if err != nil {
return nil, nil, err
}
var nr clio.NFTHistoryResponse
err = res.GetResult(&nr)
if err != nil {
return nil, nil, err
}
return &nr, res, nil
}

func (c *clioImpl) NFTInfo(req *clio.NFTInfoRequest) (*clio.NFTInfoResponse, XRPLResponse, error) {
res, err := c.client.SendRequest(req)
if err != nil {
return nil, nil, err
}
var nr clio.NFTInfoResponse
err = res.GetResult(&nr)
if err != nil {
return nil, nil, err
}
return &nr, res, nil
}
63 changes: 63 additions & 0 deletions model/client/clio/nft_history_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package clio

import (
"encoding/json"
"fmt"

"github.com/CreatureDev/xrpl-go/model/client/common"
"github.com/CreatureDev/xrpl-go/model/transactions/types"
)

type NFTHistoryRequest struct {
NFTokenID types.NFTokenID `json:"nft_id"`
LedgerIndexMin common.LedgerIndex `json:"ledger_index_min,omitempty"`
LedgerIndexMax common.LedgerIndex `json:"ledger_index_max,omitempty"`
LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"`
LedgerIndex common.LedgerSpecifier `json:"ledger_index,omitempty"`
Binary bool `json:"binary,omitempty"`
Forward bool `json:"forward,omitempty"`
Limit uint32 `json:"limit,omitempty"`
Marker any `json:"marker,omitempty"`
}

func (*NFTHistoryRequest) Method() string {
return "nft_history"
}

func (r *NFTHistoryRequest) Validate() error {
if err := r.NFTokenID.Validate(); err != nil {
return fmt.Errorf("nft history request: %w", err)
}
return nil
}

func (r *NFTHistoryRequest) UnmarshalJSON(data []byte) error {
type nhrHelper struct {
NFTokenID types.NFTokenID `json:"nft_id"`
LedgerIndexMin common.LedgerIndex `json:"ledger_index_min,omitempty"`
LedgerIndexMax common.LedgerIndex `json:"ledger_index_max,omitempty"`
LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"`
LedgerIndex json.RawMessage `json:"ledger_index,omitempty"`
Binary bool `json:"binary,omitempty"`
Forward bool `json:"forward,omitempty"`
Limit uint32 `json:"limit,omitempty"`
Marker any `json:"marker,omitempty"`
}
var h nhrHelper
err := json.Unmarshal(data, &h)
if err != nil {
return err
}
*r = NFTHistoryRequest{
NFTokenID: h.NFTokenID,
LedgerIndexMin: h.LedgerIndexMin,
LedgerIndexMax: h.LedgerIndexMax,
LedgerHash: h.LedgerHash,
Binary: h.Binary,
Forward: h.Forward,
Limit: h.Limit,
Marker: h.Marker,
}
r.LedgerIndex, err = common.UnmarshalLedgerSpecifier(h.LedgerIndex)
return err
}
17 changes: 17 additions & 0 deletions model/client/clio/nft_history_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package clio

import (
"github.com/CreatureDev/xrpl-go/model/client/account"
"github.com/CreatureDev/xrpl-go/model/client/common"
"github.com/CreatureDev/xrpl-go/model/transactions/types"
)

type NFTHistoryResponse struct {
NFTokenID types.NFTokenID `json:"nft_id"`
LedgerIndexMin common.LedgerIndex `json:"ledger_index_min"`
LedgerIndexMax common.LedgerIndex `json:"ledger_index_max"`
Limit uint `json:"limit"`
Marker any `json:"marker"`
Transactions []account.AccountTransaction `json:"transactions"`
Validated bool `json:"validated"`
}

0 comments on commit 456af3b

Please sign in to comment.