From ad2dfeb7c8820d713bd1ff45909550459cebbabe Mon Sep 17 00:00:00 2001 From: Niraj Pathak Date: Tue, 26 Apr 2022 15:36:45 -0600 Subject: [PATCH 1/4] add cat transaction to wallet --- .gitignore | 1 + pkg/rpc/wallet.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/.gitignore b/.gitignore index b267ba7..283d75a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ main.go main bin/ +.idea/* diff --git a/pkg/rpc/wallet.go b/pkg/rpc/wallet.go index 757d4b5..d6d3a8a 100644 --- a/pkg/rpc/wallet.go +++ b/pkg/rpc/wallet.go @@ -258,3 +258,34 @@ func (s *WalletService) SendTransaction(opts *SendTransactionOptions) (*SendTran return r, resp, nil } + +// SendCatTransactionOptions represents the options for send_transaction +type SendCatTransactionOptions struct { + WalletID uint32 `json:"wallet_id"` + Amount uint64 `json:"amount"` + Address string `json:"inner_address"` + Fee uint64 `json:"fee"` +} + +// SendCatTransactionResponse represents the response from send_transaction +type SendCatTransactionResponse struct { + Success bool `json:"success"` + TransactionID string `json:"transaction_id"` + Transaction types.TransactionRecord `json:"transaction"` +} + +// SendCatTransaction sends a transaction +func (s *WalletService) SendCatTransaction(opts *SendTransactionOptions) (*SendTransactionResponse, *http.Response, error) { + request, err := s.NewRequest("send_transaction", opts) + if err != nil { + return nil, nil, err + } + + r := &SendTransactionResponse{} + resp, err := s.Do(request, r) + if err != nil { + return nil, resp, err + } + + return r, resp, nil +} From b42331cab655dfada3e331f38ad30ba68f1501ce Mon Sep 17 00:00:00 2001 From: Niraj Pathak Date: Thu, 28 Apr 2022 15:29:02 -0600 Subject: [PATCH 2/4] update endpoint and function parameters --- pkg/rpc/wallet.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/rpc/wallet.go b/pkg/rpc/wallet.go index d6d3a8a..5ce13d9 100644 --- a/pkg/rpc/wallet.go +++ b/pkg/rpc/wallet.go @@ -275,13 +275,13 @@ type SendCatTransactionResponse struct { } // SendCatTransaction sends a transaction -func (s *WalletService) SendCatTransaction(opts *SendTransactionOptions) (*SendTransactionResponse, *http.Response, error) { - request, err := s.NewRequest("send_transaction", opts) +func (s *WalletService) SendCatTransaction(opts *SendCatTransactionOptions) (*SendCatTransactionResponse, *http.Response, error) { + request, err := s.NewRequest("cat_spend", opts) if err != nil { return nil, nil, err } - r := &SendTransactionResponse{} + r := &SendCatTransactionResponse{} resp, err := s.Do(request, r) if err != nil { return nil, resp, err From 1b8be463d06ca01685408bf3cad858d8d2c072f8 Mon Sep 17 00:00:00 2001 From: Niraj Pathak Date: Thu, 28 Apr 2022 16:28:25 -0600 Subject: [PATCH 3/4] rename functions and structs to match existing naming conventions --- pkg/rpc/wallet.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/rpc/wallet.go b/pkg/rpc/wallet.go index 5ce13d9..385d434 100644 --- a/pkg/rpc/wallet.go +++ b/pkg/rpc/wallet.go @@ -259,29 +259,29 @@ func (s *WalletService) SendTransaction(opts *SendTransactionOptions) (*SendTran return r, resp, nil } -// SendCatTransactionOptions represents the options for send_transaction -type SendCatTransactionOptions struct { +// CatSpendOptions represents the options for send_transaction +type CatSpendOptions struct { WalletID uint32 `json:"wallet_id"` Amount uint64 `json:"amount"` Address string `json:"inner_address"` Fee uint64 `json:"fee"` } -// SendCatTransactionResponse represents the response from send_transaction -type SendCatTransactionResponse struct { +// CatSpendResponse represents the response from send_transaction +type CatSpendResponse struct { Success bool `json:"success"` TransactionID string `json:"transaction_id"` Transaction types.TransactionRecord `json:"transaction"` } -// SendCatTransaction sends a transaction -func (s *WalletService) SendCatTransaction(opts *SendCatTransactionOptions) (*SendCatTransactionResponse, *http.Response, error) { +// CatSpend sends a transaction +func (s *WalletService) CatSpend(opts *CatSpendOptions) (*CatSpendResponse, *http.Response, error) { request, err := s.NewRequest("cat_spend", opts) if err != nil { return nil, nil, err } - r := &SendCatTransactionResponse{} + r := &CatSpendResponse{} resp, err := s.Do(request, r) if err != nil { return nil, resp, err From 3a1d4ea2c9c6539f413664194112b21845d1c61d Mon Sep 17 00:00:00 2001 From: Niraj Pathak Date: Thu, 28 Apr 2022 17:30:11 -0600 Subject: [PATCH 4/4] more accurate comments --- pkg/rpc/wallet.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/rpc/wallet.go b/pkg/rpc/wallet.go index 385d434..6bc1cd1 100644 --- a/pkg/rpc/wallet.go +++ b/pkg/rpc/wallet.go @@ -259,7 +259,7 @@ func (s *WalletService) SendTransaction(opts *SendTransactionOptions) (*SendTran return r, resp, nil } -// CatSpendOptions represents the options for send_transaction +// CatSpendOptions represents the options for cat_spend type CatSpendOptions struct { WalletID uint32 `json:"wallet_id"` Amount uint64 `json:"amount"` @@ -267,7 +267,7 @@ type CatSpendOptions struct { Fee uint64 `json:"fee"` } -// CatSpendResponse represents the response from send_transaction +// CatSpendResponse represents the response from cat_spend type CatSpendResponse struct { Success bool `json:"success"` TransactionID string `json:"transaction_id"`