From 0565c169f7637910a477910fa65aa4b6a500160f Mon Sep 17 00:00:00 2001 From: PR Date: Sat, 21 Oct 2023 14:33:47 -0700 Subject: [PATCH] complete client impl --- client/accounts.go | 92 +++++++++++++++++- client/channels.go | 40 ++++++++ client/ledgers.go | 82 ++++++++++++++++ client/path.go | 94 +++++++++++++++++++ client/server.go | 66 +++++++++++++ client/subscriptions.go | 40 ++++++++ client/transactions.go | 68 ++++++++++++++ .../client/account/account_lines_response.go | 2 +- .../client/subscription/subscribe_request.go | 2 +- .../client/subscription/subscribe_response.go | 2 +- model/client/subscription/subscribe_test.go | 2 +- .../subscription/unsubscribe_request.go | 2 +- .../subscription/unsubscribe_response.go | 2 +- model/client/subscription/unsubscribe_test.go | 2 +- 14 files changed, 485 insertions(+), 11 deletions(-) create mode 100644 client/channels.go create mode 100644 client/ledgers.go create mode 100644 client/path.go create mode 100644 client/server.go create mode 100644 client/subscriptions.go create mode 100644 client/transactions.go diff --git a/client/accounts.go b/client/accounts.go index 438e8cc5..76154482 100644 --- a/client/accounts.go +++ b/client/accounts.go @@ -5,15 +5,21 @@ import ( ) type Account interface { - GetAccountChannels(req *account.AccountChannelsRequest) (*account.AccountChannelsResponse, XRPLResponse, error) - GetAccountInfo(req *account.AccountInfoRequest) (*account.AccountInfoResponse, XRPLResponse, error) + AccountChannels(req *account.AccountChannelsRequest) (*account.AccountChannelsResponse, XRPLResponse, error) + AccountCurrencies(req *account.AccountInfoRequest) (*account.AccountInfoResponse, XRPLResponse, error) + AccountInfo(req *account.AccountInfoRequest) (*account.AccountInfoResponse, XRPLResponse, error) + AccountLines(req *account.AccountLinesRequest) (*account.AccountLinesResponse, XRPLResponse, error) + AccountNFTs(req *account.AccountNFTsRequest) (*account.AccountNFTsResponse, XRPLResponse, error) + AccountObjects(req *account.AccountObjectsRequest) (*account.AccountObjectsResponse, XRPLResponse, error) + AccountOffers(req *account.AccountOffersRequest) (*account.AccountOffersResponse, XRPLResponse, error) + AccountTransactions(req *account.AccountTransactionsRequest) (*account.AccountTransactionsResponse, XRPLResponse, error) } type accountImpl struct { client Client } -func (a *accountImpl) GetAccountChannels(req *account.AccountChannelsRequest) (*account.AccountChannelsResponse, XRPLResponse, error) { +func (a *accountImpl) AccountChannels(req *account.AccountChannelsRequest) (*account.AccountChannelsResponse, XRPLResponse, error) { res, err := a.client.SendRequest(req) if err != nil { return nil, nil, err @@ -26,7 +32,20 @@ func (a *accountImpl) GetAccountChannels(req *account.AccountChannelsRequest) (* return &acr, res, nil } -func (a *accountImpl) GetAccountInfo(req *account.AccountInfoRequest) (*account.AccountInfoResponse, XRPLResponse, error) { +func (a *accountImpl) AccountCurrencies(req *account.AccountCurrenciesRequest) (*account.AccountCurrenciesResponse, XRPLResponse, error) { + res, err := a.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var acr account.AccountCurrenciesResponse + err = res.GetResult(&acr) + if err != nil { + return nil, nil, err + } + return &acr, res, nil +} + +func (a *accountImpl) AccountInfo(req *account.AccountInfoRequest) (*account.AccountInfoResponse, XRPLResponse, error) { res, err := a.client.SendRequest(req) if err != nil { return nil, nil, err @@ -38,3 +57,68 @@ func (a *accountImpl) GetAccountInfo(req *account.AccountInfoRequest) (*account. } return &air, res, nil } + +func (a *accountImpl) AccountLines(req *account.AccountLinesRequest) (*account.AccountLinesResponse, XRPLResponse, error) { + res, err := a.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var alr account.AccountLinesResponse + err = res.GetResult(&alr) + if err != nil { + return nil, nil, err + } + return &alr, res, nil +} + +func (a *accountImpl) AccountNFTs(req *account.AccountNFTsRequest) (*account.AccountNFTsResponse, XRPLResponse, error) { + res, err := a.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var anr account.AccountNFTsResponse + err = res.GetResult(&anr) + if err != nil { + return nil, nil, err + } + return &anr, res, nil +} + +func (a *accountImpl) AccountObjects(req *account.AccountObjectsRequest) (*account.AccountObjectsResponse, XRPLResponse, error) { + res, err := a.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var aor account.AccountObjectsResponse + err = res.GetResult(&aor) + if err != nil { + return nil, nil, err + } + return &aor, res, nil +} + +func (a *accountImpl) AccountOffers(req *account.AccountOffersRequest) (*account.AccountOffersResponse, XRPLResponse, error) { + res, err := a.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var aor account.AccountOffersResponse + err = res.GetResult(&aor) + if err != nil { + return nil, nil, err + } + return &aor, res, nil +} + +func (a *accountImpl) AccountTransactions(req *account.AccountTransactionsRequest) (*account.AccountTransactionsResponse, XRPLResponse, error) { + res, err := a.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var atr account.AccountTransactionsResponse + err = res.GetResult(&atr) + if err != nil { + return nil, nil, err + } + return &atr, res, nil +} diff --git a/client/channels.go b/client/channels.go new file mode 100644 index 00000000..108e5ce6 --- /dev/null +++ b/client/channels.go @@ -0,0 +1,40 @@ +package client + +import ( + "github.com/xyield/xrpl-go/model/client/channel" +) + +type Channel interface { + ChannelAuthorize(req *channel.ChannelAuthorizeRequest) (*channel.ChannelAuthorizeRequest, XRPLResponse, error) + ChannelVerify(req *channel.ChannelVerifyRequest) (*channel.ChannelVerifyResponse, XRPLResponse, error) +} + +type channelImpl struct { + client Client +} + +func (c *channelImpl) ChannelAuthorize(req *channel.ChannelAuthorizeRequest) (*channel.ChannelAuthorizeResponse, XRPLResponse, error) { + res, err := c.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var car channel.ChannelAuthorizeResponse + err = res.GetResult(&car) + if err != nil { + return nil, nil, err + } + return &car, res, nil +} + +func (c *channelImpl) ChannelVerify(req *channel.ChannelVerifyRequest) (*channel.ChannelVerifyResponse, XRPLResponse, error) { + res, err := c.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var cvr channel.ChannelVerifyResponse + err = res.GetResult(&cvr) + if err != nil { + return nil, nil, err + } + return &cvr, res, nil +} diff --git a/client/ledgers.go b/client/ledgers.go new file mode 100644 index 00000000..16a26444 --- /dev/null +++ b/client/ledgers.go @@ -0,0 +1,82 @@ +package client + +import ( + "github.com/xyield/xrpl-go/model/client/ledger" +) + +type Ledger interface { + LedgerClosed(req *ledger.LedgerClosedRequest) (*ledger.LedgerClosedRequest, XRPLResponse, error) + LedgerCurrent(req *ledger.LedgerCurrentRequest) (*ledger.LedgerCurrentRequest, XRPLResponse, error) + LedgerData(req *ledger.LedgerDataRequest) (*ledger.LedgerDataRequest, XRPLResponse, error) + LedgerEntry(req *ledger.LedgerEntryRequest) (*ledger.LedgerEntryRequest, XRPLResponse, error) + Ledger(req *ledger.LedgerRequest) (*ledger.LedgerRequest, XRPLResponse, error) +} + +type ledgerImpl struct { + client Client +} + +func (l *ledgerImpl) LedgerClosed(req *ledger.LedgerClosedRequest) (*ledger.LedgerClosedResponse, XRPLResponse, error) { + res, err := l.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var lcr ledger.LedgerClosedResponse + err = res.GetResult(&lcr) + if err != nil { + return nil, nil, err + } + return &lcr, res, nil +} + +func (l *ledgerImpl) LedgerCurrent(req *ledger.LedgerCurrentRequest) (*ledger.LedgerCurrentResponse, XRPLResponse, error) { + res, err := l.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var lcr ledger.LedgerCurrentResponse + err = res.GetResult(&lcr) + if err != nil { + return nil, nil, err + } + return &lcr, res, nil +} + +func (l *ledgerImpl) LedgerData(req *ledger.LedgerDataRequest) (*ledger.LedgerDataResponse, XRPLResponse, error) { + res, err := l.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var ldr ledger.LedgerDataResponse + err = res.GetResult(&ldr) + if err != nil { + return nil, nil, err + } + return &ldr, res, nil +} + +func (l *ledgerImpl) LedgerEntry(req *ledger.LedgerEntryRequest) (*ledger.LedgerEntryResponse, XRPLResponse, error) { + res, err := l.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var ler ledger.LedgerEntryResponse + err = res.GetResult(&ler) + if err != nil { + return nil, nil, err + } + return &ler, res, nil +} + +func (l *ledgerImpl) Ledger(req *ledger.LedgerRequest) (*ledger.LedgerResponse, XRPLResponse, error) { + res, err := l.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var lr ledger.LedgerResponse + err = res.GetResult(&lr) + if err != nil { + return nil, nil, err + } + return &lr, res, nil +} diff --git a/client/path.go b/client/path.go new file mode 100644 index 00000000..fbb0e5cc --- /dev/null +++ b/client/path.go @@ -0,0 +1,94 @@ +package client + +import "github.com/xyield/xrpl-go/model/client/path" + +type PathBook interface { + BookOffers(req *path.BookOffersRequest) (*path.BookOffersResponse, XRPLResponse, error) + DepositAuthorized(req *path.DepositAuthorizedRequest) (*path.DepositAuthorizedResponse, XRPLResponse, error) + NFTokenBuyOffers(req *path.NFTokenBuyOffersRequest) (*path.NFTokenBuyOffersResponse, XRPLResponse, error) + NFTokenSellOffers(req *path.NFTokenSellOffersRequest) (*path.NFTokenSellOffersResponse, XRPLResponse, error) + PathFind(req *path.PathFindRequest) (*path.PathFindResponse, XRPLResponse, error) + RipplePathFind(req *path.RipplePathFindRequest) (*path.RipplePathFindResponse, XRPLResponse, error) +} + +type pathImpl struct { + client Client +} + +func (p *pathImpl) BookOffers(req *path.BookOffersRequest) (*path.BookOffersResponse, XRPLResponse, error) { + res, err := p.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var bor path.BookOffersResponse + err = res.GetResult(&bor) + if err != nil { + return nil, nil, err + } + return &bor, res, nil +} + +func (p *pathImpl) DepositAuthorized(req *path.DepositAuthorizedRequest) (*path.DepositAuthorizedResponse, XRPLResponse, error) { + res, err := p.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var dar path.DepositAuthorizedResponse + err = res.GetResult(&dar) + if err != nil { + return nil, nil, err + } + return &dar, res, nil +} + +func (p *pathImpl) NFTBuyOffers(req *path.NFTokenBuyOffersRequest) (*path.NFTokenBuyOffersResponse, XRPLResponse, error) { + res, err := p.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var nbr path.NFTokenBuyOffersResponse + err = res.GetResult(&nbr) + if err != nil { + return nil, nil, err + } + return &nbr, res, nil +} + +func (p *pathImpl) NFTokenSellOffers(req *path.NFTokenSellOffersRequest) (*path.NFTokenSellOffersResponse, XRPLResponse, error) { + res, err := p.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var nsr path.NFTokenSellOffersResponse + err = res.GetResult(&nsr) + if err != nil { + return nil, nil, err + } + return &nsr, res, nil +} + +func (p *pathImpl) PathFind(req *path.PathFindRequest) (*path.PathFindResponse, XRPLResponse, error) { + res, err := p.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var pfr path.PathFindResponse + err = res.GetResult(&pfr) + if err != nil { + return nil, nil, err + } + return &pfr, res, nil +} + +func (p *pathImpl) RipplePathFind(req *path.RipplePathFindRequest) (*path.RipplePathFindResponse, XRPLResponse, error) { + res, err := p.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var rpfr path.RipplePathFindResponse + err = res.GetResult(&rpfr) + if err != nil { + return nil, nil, err + } + return &rpfr, res, nil +} diff --git a/client/server.go b/client/server.go new file mode 100644 index 00000000..27bef12b --- /dev/null +++ b/client/server.go @@ -0,0 +1,66 @@ +package client + +import "github.com/xyield/xrpl-go/model/client/server" + +type Server interface { + Fee(*server.FeeRequest) (*server.FeeResponse, XRPLResponse, error) + Manifest(*server.ManifestRequest) (*server.ManifestResponse, XRPLResponse, error) + ServerInfo(*server.ServerInfoRequest) (*server.ServerInfoResponse, XRPLResponse, error) + ServerState(*server.ServerStateRequest) (*server.ServerStateRequest, XRPLResponse, error) +} + +type serverImpl struct { + client Client +} + +func (s *serverImpl) Fee(req *server.FeeRequest) (*server.FeeResponse, XRPLResponse, error) { + res, err := s.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var fr server.FeeResponse + err = res.GetResult(&fr) + if err != nil { + return nil, nil, err + } + return &fr, res, nil +} + +func (s *serverImpl) Manifest(req *server.ManifestRequest) (*server.ManifestResponse, XRPLResponse, error) { + res, err := s.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var mr server.ManifestResponse + err = res.GetResult(&mr) + if err != nil { + return nil, nil, err + } + return &mr, res, nil +} + +func (s *serverImpl) ServerInfo(req *server.ServerInfoRequest) (*server.ServerInfoResponse, XRPLResponse, error) { + res, err := s.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var sir server.ServerInfoResponse + err = res.GetResult(&sir) + if err != nil { + return nil, nil, err + } + return &sir, res, nil +} + +func (s *serverImpl) ServerState(req *server.ServerStateRequest) (*server.ServerStateResponse, XRPLResponse, error) { + res, err := s.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var ssr server.ServerStateResponse + err = res.GetResult(&ssr) + if err != nil { + return nil, nil, err + } + return &ssr, res, nil +} diff --git a/client/subscriptions.go b/client/subscriptions.go new file mode 100644 index 00000000..4e33eb82 --- /dev/null +++ b/client/subscriptions.go @@ -0,0 +1,40 @@ +package client + +import ( + "github.com/xyield/xrpl-go/model/client/subscription" +) + +type Subscription interface { + Subscribe(*subscription.SubscribeRequest) (*subscription.SubscribeResponse, XRPLResponse, error) + Unsubscribe(*subscription.UnsubscribeRequest) (*subscription.UnsubscribeResponse, XRPLResponse, error) +} + +type subscriptionImpl struct { + client Client +} + +func (s *subscriptionImpl) Subscribe(req *subscription.SubscribeRequest) (*subscription.SubscribeResponse, XRPLResponse, error) { + res, err := s.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var sr subscription.SubscribeResponse + err = res.GetResult(&sr) + if err != nil { + return nil, nil, err + } + return &sr, res, nil +} + +func (s *subscriptionImpl) Unsubscribe(req *subscription.UnsubscribeRequest) (*subscription.UnsubscribeResponse, XRPLResponse, error) { + res, err := s.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var ur subscription.UnsubscribeResponse + err = res.GetResult(&ur) + if err != nil { + return nil, nil, err + } + return &ur, res, nil +} diff --git a/client/transactions.go b/client/transactions.go new file mode 100644 index 00000000..8aaacf44 --- /dev/null +++ b/client/transactions.go @@ -0,0 +1,68 @@ +package client + +import ( + "github.com/xyield/xrpl-go/model/client/transactions" +) + +type Transaction interface { + SubmitMultisigned(*transactions.SubmitMultisignedRequest) (*transactions.SubmitMultisignedResponse, XRPLResponse, error) + Submit(*transactions.SubmitRequest) (*transactions.SubmitResponse, XRPLResponse, error) + TransactionEntry(*transactions.TransactionEntryRequest) (*transactions.TransactionEntryResponse, XRPLResponse, error) + Tx(*transactions.TxRequest) (*transactions.TxResponse, XRPLResponse, error) +} + +type transactionImpl struct { + client Client +} + +func (t *transactionImpl) SubmitMultisigned(req *transactions.SubmitMultisignedRequest) (*transactions.SubmitMultisignedResponse, XRPLResponse, error) { + res, err := t.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var smr transactions.SubmitMultisignedResponse + err = res.GetResult(&smr) + if err != nil { + return nil, nil, err + } + return &smr, res, nil +} + +func (t *transactionImpl) Submit(req *transactions.SubmitRequest) (*transactions.SubmitResponse, XRPLResponse, error) { + res, err := t.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var sr transactions.SubmitResponse + err = res.GetResult(&sr) + if err != nil { + return nil, nil, err + } + return &sr, res, nil +} + +func (t *transactionImpl) TransactionEntry(req *transactions.TransactionEntryRequest) (*transactions.TransactionEntryResponse, XRPLResponse, error) { + res, err := t.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var ter transactions.TransactionEntryResponse + err = res.GetResult(&ter) + if err != nil { + return nil, nil, err + } + return &ter, res, nil +} + +func (t *transactionImpl) Tx(req *transactions.TxRequest) (*transactions.TxResponse, XRPLResponse, error) { + res, err := t.client.SendRequest(req) + if err != nil { + return nil, nil, err + } + var tr transactions.TxResponse + err = res.GetResult(&tr) + if err != nil { + return nil, nil, err + } + return &tr, res, nil +} diff --git a/model/client/account/account_lines_response.go b/model/client/account/account_lines_response.go index d8c5c1a0..ed32acda 100644 --- a/model/client/account/account_lines_response.go +++ b/model/client/account/account_lines_response.go @@ -5,7 +5,7 @@ import ( "github.com/xyield/xrpl-go/model/transactions/types" ) -type AccountLinesReponse struct { +type AccountLinesResponse struct { Account types.Address `json:"account"` Lines []TrustLine `json:"lines"` LedgerCurrentIndex common.LedgerIndex `json:"ledger_current_index,omitempty"` diff --git a/model/client/subscription/subscribe_request.go b/model/client/subscription/subscribe_request.go index 407723fa..29b51dcb 100644 --- a/model/client/subscription/subscribe_request.go +++ b/model/client/subscription/subscribe_request.go @@ -1,4 +1,4 @@ -package subscribe +package subscription import "github.com/xyield/xrpl-go/model/transactions/types" diff --git a/model/client/subscription/subscribe_response.go b/model/client/subscription/subscribe_response.go index 43905fce..d4f28501 100644 --- a/model/client/subscription/subscribe_response.go +++ b/model/client/subscription/subscribe_response.go @@ -1,4 +1,4 @@ -package subscribe +package subscription import ( "github.com/xyield/xrpl-go/model/client/common" diff --git a/model/client/subscription/subscribe_test.go b/model/client/subscription/subscribe_test.go index 04944560..f4ce14fc 100644 --- a/model/client/subscription/subscribe_test.go +++ b/model/client/subscription/subscribe_test.go @@ -1,4 +1,4 @@ -package subscribe +package subscription import ( "testing" diff --git a/model/client/subscription/unsubscribe_request.go b/model/client/subscription/unsubscribe_request.go index 2339a9d8..1715bdb9 100644 --- a/model/client/subscription/unsubscribe_request.go +++ b/model/client/subscription/unsubscribe_request.go @@ -1,4 +1,4 @@ -package subscribe +package subscription import "github.com/xyield/xrpl-go/model/transactions/types" diff --git a/model/client/subscription/unsubscribe_response.go b/model/client/subscription/unsubscribe_response.go index e3583a4b..b52c0706 100644 --- a/model/client/subscription/unsubscribe_response.go +++ b/model/client/subscription/unsubscribe_response.go @@ -1,4 +1,4 @@ -package subscribe +package subscription type UnsubscribeResponse struct { } diff --git a/model/client/subscription/unsubscribe_test.go b/model/client/subscription/unsubscribe_test.go index b0576cdf..297e4633 100644 --- a/model/client/subscription/unsubscribe_test.go +++ b/model/client/subscription/unsubscribe_test.go @@ -1,4 +1,4 @@ -package subscribe +package subscription import ( "testing"