-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7360f8
commit 456af3b
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |