Skip to content

Commit

Permalink
feat(SPV-737) search&count models (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain authored Jun 3, 2024
1 parent f093136 commit 694123c
Show file tree
Hide file tree
Showing 12 changed files with 397 additions and 322 deletions.
2 changes: 1 addition & 1 deletion access_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestAccessKeys(t *testing.T) {
})

t.Run("GetAccessKeys", func(t *testing.T) {
accessKeys, err := client.GetAccessKeys(context.Background(), nil)
accessKeys, err := client.GetAccessKeys(context.Background(), nil, nil, nil)
require.NoError(t, err)
require.Equal(t, []*models.AccessKey{fixtures.AccessKey}, accessKeys)
})
Expand Down
8 changes: 0 additions & 8 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ type Recipients struct {
To string `json:"to"`
}

// QueryParams object to use when limiting and sorting database query results
type QueryParams struct {
Page int `json:"page,omitempty"`
PageSize int `json:"page_size,omitempty"`
OrderByField string `json:"order_by_field,omitempty"`
SortDirection string `json:"sort_direction,omitempty"`
}

const (
// FieldMetadata is the field name for metadata
FieldMetadata = "metadata"
Expand Down
3 changes: 2 additions & 1 deletion destinations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/bitcoin-sv/spv-wallet-go-client/fixtures"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/bitcoin-sv/spv-wallet/models/filter"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -63,7 +64,7 @@ func TestDestinations(t *testing.T) {
})

t.Run("GetDestinations", func(t *testing.T) {
destinations, err := client.GetDestinations(context.Background(), fixtures.TestMetadata)
destinations, err := client.GetDestinations(context.Background(), &filter.DestinationFilter{}, nil, nil)
require.NoError(t, err)
require.Equal(t, []*models.Destination{fixtures.Destination}, destinations)
})
Expand Down
4 changes: 1 addition & 3 deletions examples/register_xpub/register_xpub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"fmt"

"github.com/bitcoin-sv/spv-wallet/models"

walletclient "github.com/bitcoin-sv/spv-wallet-go-client"
"github.com/bitcoin-sv/spv-wallet-go-client/xpriv"
)
Expand All @@ -17,7 +15,7 @@ func main() {
// Create a client
wc := walletclient.NewWithXPriv("localhost:3003", keys.XPriv())
ctx := context.Background()
_ = wc.AdminNewXpub(ctx, keys.XPub().String(), &models.Metadata{"example_field": "example_data"})
_ = wc.AdminNewXpub(ctx, keys.XPub().String(), map[string]any{"example_field": "example_data"})

xpubKey, err := wc.GetXPub(ctx)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func MarshallForTestHandler(object any) string {
}

// TestMetadata model for metadata
var TestMetadata = &models.Metadata{"test-key": "test-value"}
var TestMetadata = map[string]any{"test-key": "test-value"}

// Xpub model for testing
var Xpub = &models.Xpub{
Model: common.Model{Metadata: *TestMetadata},
Model: common.Model{Metadata: TestMetadata},
ID: "cba0be1e753a7609e1a2f792d2e80ea6fce241be86f0690ec437377477809ccc",
CurrentBalance: 16680,
NextInternalNum: 2,
Expand All @@ -50,15 +50,15 @@ var Xpub = &models.Xpub{

// AccessKey model for testing
var AccessKey = &models.AccessKey{
Model: common.Model{Metadata: *TestMetadata},
Model: common.Model{Metadata: TestMetadata},
ID: "access-key-id",
XpubID: Xpub.ID,
Key: AccessKeyString,
}

// Destination model for testing
var Destination = &models.Destination{
Model: common.Model{Metadata: *TestMetadata},
Model: common.Model{Metadata: TestMetadata},
ID: "90d10acb85f37dd009238fe7ec61a1411725825c82099bd8432fcb47ad8326ce",
XpubID: Xpub.ID,
LockingScript: "76a9140e0eb4911d79e9b7683f268964f595b66fa3604588ac",
Expand All @@ -71,7 +71,7 @@ var Destination = &models.Destination{

// Transaction model for testing
var Transaction = &models.Transaction{
Model: common.Model{Metadata: *TestMetadata},
Model: common.Model{Metadata: TestMetadata},
ID: "caae6e799210dfea7591e3d55455437eb7e1091bb01463ae1e7ddf9e29c75eda",
Hex: "0100000001cf4faa628ce1abdd2cfc641c948898bb7a3dbe043999236c3ea4436a0c79f5dc000000006a47304402206aeca14175e4477031970c1cda0af4d9d1206289212019b54f8e1c9272b5bac2022067c4d32086146ca77640f02a989f51b3c6738ebfa24683c4a923f647cf7f1c624121036295a81525ba33e22c6497c0b758e6a84b60d97c2d8905aa603dd364915c3a0effffffff023e030000000000001976a914f7fc6e0b05e91c3610efd0ce3f04f6502e2ed93d88ac99030000000000001976a914550e06a3aa71ba7414b53922c13f96a882bf027988ac00000000",
XpubInIDs: []string{Xpub.ID},
Expand All @@ -91,7 +91,7 @@ var Transaction = &models.Transaction{

// DraftTx model for testing
var DraftTx = &models.DraftTransaction{
Model: common.Model{Metadata: *TestMetadata},
Model: common.Model{Metadata: TestMetadata},
ID: "3a0e1fdd9ac6046c0c82aa36b462e477a455880ceeb08d3aabb1bf031553d1df",
Hex: "010000000123462f14e60556718916a8cff9dbf2258195a928777c0373200dba1cee105bdb0100000000ffffffff020c000000000000001976a914c4b15e7f65e3e6a062c1d21b7f1d7d2cd3b18e8188ac0b000000000000001976a91455873fd2baa7b51a624f6416b1d824939d99151a88ac00000000",
XpubID: Xpub.ID,
Expand Down
2 changes: 1 addition & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 694123c

Please sign in to comment.