Skip to content

Commit

Permalink
Merge pull request #20 from aemet93/master
Browse files Browse the repository at this point in the history
ExportOutputs and ExportKeyImages implementations
  • Loading branch information
MarinX authored Jan 25, 2024
2 parents 1befe13 + 96c9e30 commit ee5d819
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions wallet/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,18 @@ type VerifyResponse struct {
Good bool `json:"good"`
}

// 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"`
}

// 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.
Expand All @@ -1015,6 +1027,18 @@ type SignedImage struct {
Signature string `json:"signature"`
}

// 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"`
}

// 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:
Expand Down
16 changes: 10 additions & 6 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit ee5d819

Please sign in to comment.