Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(XXX): remove go-client models and replace them with spv-wallet ones for sync merkleroots #280

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/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 examples/go.sum

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

2 changes: 1 addition & 1 deletion examples/sync_merkleroots/sync_merkleroots.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

walletclient "github.com/bitcoin-sv/spv-wallet-go-client"
"github.com/bitcoin-sv/spv-wallet-go-client/examples"
"github.com/bitcoin-sv/spv-wallet-go-client/models"
"github.com/bitcoin-sv/spv-wallet/models"
)

// simulate a storage of merkle roots that exists on a client side that is using SyncMerkleRoots method
Expand Down
2 changes: 1 addition & 1 deletion fixtures/spv_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fixtures
import (
"slices"

"github.com/bitcoin-sv/spv-wallet-go-client/models"
"github.com/bitcoin-sv/spv-wallet/models"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion fixtures/sync_merkleroots.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http/httptest"
"time"

"github.com/bitcoin-sv/spv-wallet-go-client/models"
"github.com/bitcoin-sv/spv-wallet/models"
)

// simulate a storage of merkle roots that exists on a client side that is using SyncMerkleRoots method
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.

2 changes: 2 additions & 0 deletions go.sum

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

38 changes: 0 additions & 38 deletions models/sync_merkleroots.go

This file was deleted.

13 changes: 11 additions & 2 deletions sync_merkleroots.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ import (
"net/http"
"strings"

"github.com/bitcoin-sv/spv-wallet-go-client/models"
"github.com/bitcoin-sv/spv-wallet/models"
)

// MerkleRootsRepository is an interface responsible for storing synchronized MerkleRoots and retrieving the last evaluation key from the database.
type MerkleRootsRepository interface {
// GetLastMerkleRoot should return the Merkle root with the highest height from your memory, or undefined if empty.
GetLastMerkleRoot() string
// SaveMerkleRoots should store newly synced merkle roots into your storage;
// NOTE: items are sorted in ascending order by block height.
SaveMerkleRoots(syncedMerkleRoots []models.MerkleRoot) error
}

// SyncMerkleRoots syncs merkleroots known to spv-wallet with the client database
// If timeout is needed pass context.WithTimeout() as ctx param
func (wc *WalletClient) SyncMerkleRoots(ctx context.Context, repo models.MerkleRootsRepository) error {
func (wc *WalletClient) SyncMerkleRoots(ctx context.Context, repo MerkleRootsRepository) error {
lastEvaluatedKey := repo.GetLastMerkleRoot()
requestPath := "merkleroots"
lastEvaluatedKeyQuery := ""
Expand Down
2 changes: 1 addition & 1 deletion sync_merkleroots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

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

Expand Down
Loading