-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from xyield/pr/milestone-3
Remaining Public API
- Loading branch information
Showing
28 changed files
with
1,483 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package clio | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/xyield/xrpl-go/model/client/common" | ||
) | ||
|
||
type LedgerRequest struct { | ||
LedgerHash common.LedgerHash `json:"ledger_hash,omitempty"` | ||
LedgerIndex common.LedgerSpecifier `json:"ledger_index,omitempty"` | ||
Full bool `json:"full"` | ||
Accounts bool `json:"accounts"` | ||
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"` | ||
Full bool `json:"full"` | ||
Accounts bool `json:"accounts"` | ||
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, | ||
Accounts: h.Accounts, | ||
Full: h.Full, | ||
Transactions: h.Transactions, | ||
Expand: h.Expand, | ||
OwnerFunds: h.OwnerFunds, | ||
Binary: h.Binary, | ||
Queue: h.Queue, | ||
Diff: h.Diff, | ||
} | ||
r.LedgerIndex, err = common.UnmarshalLedgerSpecifier(h.LedgerIndex) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return 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,90 @@ | ||
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"` | ||
LedgerHash common.LedgerHash `json:"ledger_hash"` | ||
LedgerIndex common.LedgerIndex `json:"ledger_index"` | ||
Validated bool `json:"validated"` | ||
} | ||
|
||
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,omitempty"` | ||
} | ||
|
||
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, | ||
CloseTimeResolution: h.CloseTimeResolution, | ||
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 | ||
} |
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,75 @@ | ||
package clio | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/xyield/xrpl-go/model/client/common" | ||
"github.com/xyield/xrpl-go/test" | ||
) | ||
|
||
func TestLedgerRequest(t *testing.T) { | ||
s := LedgerRequest{ | ||
LedgerIndex: common.VALIDATED, | ||
} | ||
j := `{ | ||
"ledger_index": "validated", | ||
"full": false, | ||
"accounts": false, | ||
"transactions": false, | ||
"expand": false, | ||
"owner_funds": false, | ||
"binary": false, | ||
"queue": false, | ||
"diff": false | ||
}` | ||
|
||
if err := test.SerializeAndDeserialize(t, s, j); err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
|
||
func TestLedgerResponse(t *testing.T) { | ||
// TODO test AccountState | ||
s := LedgerResponse{ | ||
Ledger: ClioLedger{ | ||
AccountHash: "10EFE192F59B3DE2A2BE5BCE2CA5DC83D066105696FCFC24C055359AAEBD6941", | ||
CloseFlags: 0, | ||
CloseTime: 711134782, | ||
CloseTimeHuman: "2022-Jul-14 17:26:22.000000000 UTC", | ||
CloseTimeResolution: 10, | ||
Closed: true, | ||
LedgerHash: "D3878EF6C92B84678AE2FBADC40961A161A128EA54AE59C2775CE076C2AE7A85", | ||
LedgerIndex: "19977716", | ||
ParentCloseTime: 711134781, | ||
ParentHash: "D6DE54039FE5A22D86CD522F1A9B7794E487B74D9B6B8CBDE23F240F434B6749", | ||
TotalCoins: 99987079398940307, | ||
TransactionHash: "0000000000000000000000000000000000000000000000000000000000000000", | ||
}, | ||
LedgerHash: "D3878EF6C92B84678AE2FBADC40961A161A128EA54AE59C2775CE076C2AE7A85", | ||
LedgerIndex: 19977716, | ||
Validated: true, | ||
} | ||
j := `{ | ||
"ledger": { | ||
"account_hash": "10EFE192F59B3DE2A2BE5BCE2CA5DC83D066105696FCFC24C055359AAEBD6941", | ||
"close_flags": 0, | ||
"close_time": 711134782, | ||
"close_time_human": "2022-Jul-14 17:26:22.000000000 UTC", | ||
"close_time_resolution": 10, | ||
"closed": true, | ||
"ledger_hash": "D3878EF6C92B84678AE2FBADC40961A161A128EA54AE59C2775CE076C2AE7A85", | ||
"ledger_index": "19977716", | ||
"parent_close_time": 711134781, | ||
"parent_hash": "D6DE54039FE5A22D86CD522F1A9B7794E487B74D9B6B8CBDE23F240F434B6749", | ||
"total_coins": "99987079398940307", | ||
"transaction_hash": "0000000000000000000000000000000000000000000000000000000000000000" | ||
}, | ||
"ledger_hash": "D3878EF6C92B84678AE2FBADC40961A161A128EA54AE59C2775CE076C2AE7A85", | ||
"ledger_index": 19977716, | ||
"validated": true | ||
}` | ||
|
||
if err := test.SerializeAndDeserialize(t, s, j); err != nil { | ||
t.Error(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,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 | ||
} |
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,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"` | ||
} |
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,50 @@ | ||
package clio | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/xyield/xrpl-go/model/client/common" | ||
"github.com/xyield/xrpl-go/test" | ||
) | ||
|
||
func TestNFTInfoRequest(t *testing.T) { | ||
s := NFTInfoRequest{ | ||
NFTokenID: "00080000B4F4AFC5FBCBD76873F18006173D2193467D3EE70000099B00000000", | ||
LedgerIndex: common.VALIDATED, | ||
} | ||
|
||
j := `{ | ||
"nft_id": "00080000B4F4AFC5FBCBD76873F18006173D2193467D3EE70000099B00000000", | ||
"ledger_index": "validated" | ||
}` | ||
|
||
if err := test.SerializeAndDeserialize(t, s, j); err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
|
||
func TestNFTInfoResponse(t *testing.T) { | ||
s := NFTInfoResponse{ | ||
NFTokenID: "00080000B4F4AFC5FBCBD76873F18006173D2193467D3EE70000099B00000000", | ||
LedgerIndex: 270, | ||
Owner: "rG9gdNygQ6npA9JvDFWBoeXbiUcTYJnEnk", | ||
IsBurned: true, | ||
Flags: 8, | ||
TransferFee: 0, | ||
Issuer: "rHVokeuSnjPjz718qdb47bGXBBHNMP3KDQ", | ||
} | ||
j := `{ | ||
"nft_id": "00080000B4F4AFC5FBCBD76873F18006173D2193467D3EE70000099B00000000", | ||
"ledger_index": 270, | ||
"owner": "rG9gdNygQ6npA9JvDFWBoeXbiUcTYJnEnk", | ||
"is_burned": true, | ||
"flags": 8, | ||
"transfer_fee": 0, | ||
"issuer": "rHVokeuSnjPjz718qdb47bGXBBHNMP3KDQ", | ||
"nft_taxon": 0, | ||
"nft_sequence": 0 | ||
}` | ||
if err := test.SerializeAndDeserialize(t, s, j); err != nil { | ||
t.Error(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,8 @@ | ||
package clio | ||
|
||
type ServerInfoRequest struct { | ||
} | ||
|
||
func (*ServerInfoRequest) Method() string { | ||
return "server_info" | ||
} |
Oops, something went wrong.