Skip to content

Commit

Permalink
clio and utility methods
Browse files Browse the repository at this point in the history
  • Loading branch information
CreatureDev committed Apr 11, 2023
1 parent 3e677bb commit 0f8ef40
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 0 deletions.
55 changes: 55 additions & 0 deletions model/client/clio/ledger_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package clio

import (
"encoding/json"

"github.com/xyield/xrpl-go/model/client/common"
)

type LedgerRequest struct {
LedgerHash common.LedgerHash `json:"ledger_hash"`
LedgerIndex common.LedgerSpecifier `json:"ledger_index"`
Transactions bool `json:"transactions"`
Expand bool `json:"expand"`
OwnerFunds bool `json:"owner_funds"`
Binary bool `json:"binary"`
Queue bool `json:"queue"`
Diff bool `json:"diff"`
}

func (*LedgerRequest) Method() string {
return "ledger"
}

func (r *LedgerRequest) UnmarshalJSON(data []byte) error {
type lrHelper struct {
LedgerHash common.LedgerHash `json:"ledger_hash"`
LedgerIndex json.RawMessage `json:"ledger_index"`
Transactions bool `json:"transactions"`
Expand bool `json:"expand"`
OwnerFunds bool `json:"owner_funds"`
Binary bool `json:"binary"`
Queue bool `json:"queue"`
Diff bool `json:"diff"`
}
var h lrHelper
err := json.Unmarshal(data, &h)
if err != nil {
return err
}
*r = LedgerRequest{
LedgerHash: h.LedgerHash,
Transactions: h.Transactions,
Expand: h.Expand,
OwnerFunds: h.OwnerFunds,
Binary: h.Binary,
Queue: h.Queue,
Diff: h.Diff,
}
r.LedgerIndex, err = common.UnmarshalLedgerSpecifier(data)
if err != nil {
return err
}

return nil
}
86 changes: 86 additions & 0 deletions model/client/clio/ledger_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package clio

import (
"encoding/json"

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

type LedgerResponse struct {
Ledger ClioLedger `json:"ledger"`
}

type ClioLedger struct {
AccountHash string `json:"account_hash"`
AccountState []ledger.LedgerObject `json:"accountState,omitempty"`
CloseFlags int `json:"close_flags"`
CloseTime uint `json:"close_time"`
CloseTimeHuman string `json:"close_time_human"`
CloseTimeResolution int `json:"close_time_resolution"`
Closed bool `json:"closed"`
LedgerHash common.LedgerHash `json:"ledger_hash"`
LedgerIndex string `json:"ledger_index"`
ParentCloseTime uint `json:"parent_close_time"`
ParentHash string `json:"parent_hash"`
TotalCoins types.XRPCurrencyAmount `json:"total_coins"`
TransactionHash string `json:"transaction_hash"`
Transactions []transactions.Tx `json:"transactions"`
}

func (l *ClioLedger) UnmarshalJSON(data []byte) error {
type clHelper struct {
AccountHash string `json:"account_hash"`
AccountState []json.RawMessage `json:"accountState,omitempty"`
CloseFlags int `json:"close_flags"`
CloseTime uint `json:"close_time"`
CloseTimeHuman string `json:"close_time_human"`
CloseTimeResolution int `json:"close_time_resolution"`
Closed bool `json:"closed"`
LedgerHash common.LedgerHash `json:"ledger_hash"`
LedgerIndex string `json:"ledger_index"`
ParentCloseTime uint `json:"parent_close_time"`
ParentHash string `json:"parent_hash"`
TotalCoins types.XRPCurrencyAmount `json:"total_coins"`
TransactionHash string `json:"transaction_hash"`
Transactions []json.RawMessage `json:"transactions"`
}
var h clHelper
err := json.Unmarshal(data, &h)
if err != nil {
return err
}
*l = ClioLedger{
AccountHash: h.AccountHash,
CloseFlags: h.CloseFlags,
CloseTime: h.CloseTime,
CloseTimeHuman: h.CloseTimeHuman,
Closed: h.Closed,
LedgerHash: h.LedgerHash,
LedgerIndex: h.LedgerIndex,
ParentCloseTime: h.ParentCloseTime,
ParentHash: h.ParentHash,
TotalCoins: h.TotalCoins,
TransactionHash: h.TransactionHash,
}

for _, state := range h.AccountState {
obj, err := ledger.UnmarshalLedgerObject(state)
if err != nil {
return err
}
l.AccountState = append(l.AccountState, obj)
}

for _, tx := range h.Transactions {
tx, err := transactions.UnmarshalTx(tx)
if err != nil {
return err
}
l.Transactions = append(l.Transactions, tx)
}

return nil
}
37 changes: 37 additions & 0 deletions model/client/clio/nft_info_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package clio

import (
"encoding/json"

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

type NFTInfoRequest struct {
NFTokenID types.NFTokenID `json:"nft_id"`
LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"`
LedgerIndex common.LedgerSpecifier `json:"ledger_index,omitempty"`
}

func (*NFTInfoRequest) Method() string {
return "nft_info"
}

func (r *NFTInfoRequest) UnmarshalJSON(data []byte) error {
type nirHelper struct {
NFTokenID types.NFTokenID `json:"nft_id"`
LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"`
LedgerIndex json.RawMessage `json:"ledger_index,omitempty"`
}
var h nirHelper
err := json.Unmarshal(data, &h)
if err != nil {
return err
}
*r = NFTInfoRequest{
NFTokenID: h.NFTokenID,
LedgerHash: h.LedgerHash,
}
r.LedgerIndex, err = common.UnmarshalLedgerSpecifier(h.LedgerIndex)
return err
}
19 changes: 19 additions & 0 deletions model/client/clio/nft_info_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package clio

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

type NFTInfoResponse struct {
NFTokenID types.NFTokenID `json:"nft_id"`
LedgerIndex common.LedgerIndex `json:"ledger_index"`
Owner types.Address `json:"owner"`
IsBurned bool `json:"is_burned"`
Flags uint `json:"flags"`
TransferFee uint `json:"transfer_fee"`
Issuer types.Address `json:"issuer"`
NFTokenTaxon uint `json:"nft_taxon"`
NFTokenSequence uint `json:"nft_sequence"`
URI types.NFTokenURI `json:"uri,omitempty"`
}
7 changes: 7 additions & 0 deletions model/client/utility/ping_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package utility

type PingRequest struct{}

func (*PingRequest) Method() string {
return "ping"
}
3 changes: 3 additions & 0 deletions model/client/utility/ping_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package utility

type PingResponse struct{}
7 changes: 7 additions & 0 deletions model/client/utility/random_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package utility

type RandomRequest struct{}

func (*RandomRequest) Method() string {
return "random"
}
7 changes: 7 additions & 0 deletions model/client/utility/random_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package utility

import "github.com/xyield/xrpl-go/binary-codec/types"

type RandomResponse struct {
Random types.Hash256 `json:"random"`
}

0 comments on commit 0f8ef40

Please sign in to comment.