From 912932165a0b95a953deee7ed643ca03f0e72894 Mon Sep 17 00:00:00 2001 From: nomvd Date: Tue, 23 Jan 2024 00:36:35 +0200 Subject: [PATCH 1/4] implemented ExportOutputs and ExportKeyImages requests, fixed test for address validation --- wallet/models.go | 24 ++++++++++++++++++++++++ wallet/wallet.go | 16 ++++++++++------ wallet/wallet_test.go | 6 +++--- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/wallet/models.go b/wallet/models.go index c0619a6..952cde4 100644 --- a/wallet/models.go +++ b/wallet/models.go @@ -997,6 +997,18 @@ type VerifyResponse struct { Good bool `json:"good"` } +// ExportOutputsRequest represents the response model for ExportOutputs +type ExportOutputsRequest struct { + // If true, export all outputs. Otherwise, export outputs since the last export. (default = false) + All bool `json:"all"` +} + +// ExportOutputsResponse represents the response model for ExportOutputs +type ExportOutputsResponse struct { + // Wallet outputs in hex format. + OutputsDataHex string `json:"outputs_data_hex"` +} + // ImportOutputsRequest represents the request model for ImportOutputs type ImportOutputsRequest struct { // Wallet outputs in hex format. @@ -1015,6 +1027,18 @@ type SignedImage struct { Signature string `json:"signature"` } +// ExportKeyImagesRequest represent the response model for ExportKeyImages +type ExportKeyImagesRequest struct { + // If true, export all key images. Otherwise, export key images since the last export. (default = false) + All bool `json:"all"` +} + +// ExportKeyImagesResponse represent the response model for ExportKeyImages +type ExportKeyImagesResponse struct { + // Array of signed key images: + SignedKeyImages []SignedImage `json:"signed_key_images"` +} + // ImportKeyImagesRequest represents the request model for ImportKeyImages type ImportKeyImagesRequest struct { // Array of signed key images: diff --git a/wallet/wallet.go b/wallet/wallet.go index 7eb7690..9bb16e7 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -104,11 +104,11 @@ type Wallet interface { // Verify a signature on a string. Verify(req *VerifyRequest) (*VerifyResponse, error) // ExportOutputs Export all outputs in hex format. - ExportOutputs() error + ExportOutputs(req *ExportOutputsRequest) (*ExportOutputsResponse, error) // ImportOutputs Import outputs in hex format. ImportOutputs(req *ImportOutputsRequest) (*ImportOutputsResponse, error) // ExportKeyImages Export a signed set of key images. - ExportKeyImages() error + ExportKeyImages(req *ExportKeyImagesRequest) (*ExportKeyImagesResponse, error) // ImportKeyImages Import signed key images list and verify their spent status. ImportKeyImages(req *ImportKeyImagesRequest) (*ImportKeyImagesResponse, error) // MakeURI Create a payment URI using the official URI spec. @@ -456,8 +456,10 @@ func (w *wallet) Verify(req *VerifyRequest) (*VerifyResponse, error) { return res, err } -func (w *wallet) ExportOutputs() error { - return w.client.Do("export_outputs", nil, nil) +func (w *wallet) ExportOutputs(req *ExportOutputsRequest) (*ExportOutputsResponse, error) { + res := new(ExportOutputsResponse) + err := w.client.Do("export_outputs", req, res) + return res, err } func (w *wallet) ImportOutputs(req *ImportOutputsRequest) (*ImportOutputsResponse, error) { @@ -466,8 +468,10 @@ func (w *wallet) ImportOutputs(req *ImportOutputsRequest) (*ImportOutputsRespons return res, err } -func (w *wallet) ExportKeyImages() error { - return w.client.Do("export_key_images", nil, nil) +func (w *wallet) ExportKeyImages(req *ExportKeyImagesRequest) (*ExportKeyImagesResponse, error) { + res := new(ExportKeyImagesResponse) + err := w.client.Do("export_key_images", req, res) + return res, err } func (w *wallet) ImportKeyImages(req *ImportKeyImagesRequest) (*ImportKeyImagesResponse, error) { diff --git a/wallet/wallet_test.go b/wallet/wallet_test.go index 5a8cf12..5a759e1 100644 --- a/wallet/wallet_test.go +++ b/wallet/wallet_test.go @@ -240,7 +240,7 @@ func TestWalletValidateAddress(t *testing.T) { "integrated": false, "subaddress": false, "nettype": "mainnet", - "openalias_address": false + "openalias_address": "" } }` server := setupServer(t, "validate_address", output) @@ -1325,7 +1325,7 @@ func TestWalletExportOutputs(t *testing.T) { w := New(getClient(server.URL, server.Client())) - err := w.ExportOutputs() + _, err := w.ExportOutputs(&ExportOutputsRequest{}) if err != nil { t.Error(err) } @@ -1369,7 +1369,7 @@ func TestWalletExportKeyImages(t *testing.T) { w := New(getClient(server.URL, server.Client())) - err := w.ExportKeyImages() + _, err := w.ExportKeyImages(&ExportKeyImagesRequest{}) if err != nil { t.Error(err) } From f6ba8314b0f0ed737c6607dd34b7ceaafb2a25ee Mon Sep 17 00:00:00 2001 From: nomvd Date: Tue, 23 Jan 2024 00:40:47 +0200 Subject: [PATCH 2/4] comment fix --- wallet/models.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wallet/models.go b/wallet/models.go index 952cde4..ec2fd02 100644 --- a/wallet/models.go +++ b/wallet/models.go @@ -997,7 +997,7 @@ type VerifyResponse struct { Good bool `json:"good"` } -// ExportOutputsRequest represents the response model for ExportOutputs +// ExportOutputsRequest represents the request model for ExportOutputs type ExportOutputsRequest struct { // If true, export all outputs. Otherwise, export outputs since the last export. (default = false) All bool `json:"all"` From 4023352aea25095676103d1d6ab516e4fb337635 Mon Sep 17 00:00:00 2001 From: nomvd Date: Tue, 23 Jan 2024 00:43:24 +0200 Subject: [PATCH 3/4] comment fix --- wallet/models.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wallet/models.go b/wallet/models.go index ec2fd02..2f65b0e 100644 --- a/wallet/models.go +++ b/wallet/models.go @@ -1027,7 +1027,7 @@ type SignedImage struct { Signature string `json:"signature"` } -// ExportKeyImagesRequest represent the response model for ExportKeyImages +// ExportKeyImagesRequest represent the request model for ExportKeyImages type ExportKeyImagesRequest struct { // If true, export all key images. Otherwise, export key images since the last export. (default = false) All bool `json:"all"` From 96c9e3056911744d4762f65565ef9c937f102304 Mon Sep 17 00:00:00 2001 From: nomvd Date: Tue, 23 Jan 2024 00:52:15 +0200 Subject: [PATCH 4/4] readme update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e8921fa..b517928 100644 --- a/README.md +++ b/README.md @@ -164,11 +164,11 @@ type Wallet interface { // Verify a signature on a string. Verify(req *VerifyRequest) (*VerifyResponse, error) // ExportOutputs Export all outputs in hex format. - ExportOutputs() error + ExportOutputs(req *ExportOutputsRequest) (*ExportOutputsResponse, error) // ImportOutputs Import outputs in hex format. ImportOutputs(req *ImportOutputsRequest) (*ImportOutputsResponse, error) // ExportKeyImages Export a signed set of key images. - ExportKeyImages() error + ExportKeyImages(req *ExportKeyImagesRequest) (*ExportKeyImagesResponse, error) // ImportKeyImages Import signed key images list and verify their spent status. ImportKeyImages(req *ImportKeyImagesRequest) (*ImportKeyImagesResponse, error) // MakeURI Create a payment URI using the official URI spec.