walletclient

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 9 Imported by: 15

README

SPV Wallet: Go Client

Release Build Status Report codecov Mergify Status

Go Gitpod Ready-to-Code standard-readme compliant Makefile Included


Table of Contents


Installation

spv-wallet-go-client requires a supported release of Go.

go get -u github.com/bitcoin-sv/spv-wallet-go-client

Documentation

View the generated documentation

GoDoc


Repository Features

This repository was created using MrZ's go-template

Built-in Features
Package Dependencies
Library Deployment

Releases are automatically created when you create a new git tag!

If you want to manually make releases, please install GoReleaser:

goreleaser for easy binary or library deployment to GitHub and can be installed:

  • using make: make install-releaser
  • using brew: brew install goreleaser

The .goreleaser.yml file is used to configure goreleaser.


Automatic releases via GitHub Actions from creating a new tag:

make tag version=1.2.3

Manual Releases (optional)

Use make release-snap to create a snapshot version of the release, and finally make release to ship to production (manually).


Makefile Commands

View all makefile commands

make help

List of all current commands:

all                           Runs multiple commands
clean                         Remove previous builds and any cached data
clean-mods                    Remove all the Go mod cache
coverage                      Shows the test coverage
diff                          Show the git diff
generate                      Runs the go generate command in the base of the repo
godocs                        Sync the latest tag with GoDocs
help                          Show this help message
install                       Install the application
install-all-contributors      Installs all contributors locally
install-go                    Install the application (Using Native Go)
install-releaser              Install the GoReleaser application
lint                          Run the golangci-lint application (install if not found)
release                       Full production release (creates release in GitHub)
release                       Runs common.release then runs godocs
release-snap                  Test the full release (build binaries)
release-test                  Full production test release (everything except deploy)
replace-version               Replaces the version in HTML/JS (pre-deploy)
tag                           Generate a new tag and push (tag version=0.0.0)
tag-remove                    Remove a tag if found (tag-remove version=0.0.0)
tag-update                    Update an existing tag to current commit (tag-update version=0.0.0)
test                          Runs lint and ALL tests
test-ci                       Runs all tests via CI (exports coverage)
test-ci-no-race               Runs all tests via CI (no race) (exports coverage)
test-ci-short                 Runs unit tests via CI (exports coverage)
test-no-lint                  Runs just tests
test-short                    Runs vet, lint and tests (excludes integration tests)
test-unit                     Runs tests and outputs coverage
uninstall                     Uninstall the application (and remove files)
update-contributors           Regenerates the contributors html/list
update-linter                 Update the golangci-lint package (macOS only)
vet                           Run the Go vet application

Usage

Checkout all the examples!


Examples & Tests

All unit tests and examples run via GitHub Actions and uses Go version 1.19.x. View the configuration file.


Run all tests (including integration tests)

make test

Run tests (excluding integration tests)

make test-short

Benchmarks

Run the Go benchmarks:

make bench

Code Standards

Read more about this Go project's code standards.


Usage

// http example
func main() {

	// Generate keys
	keys, _ := xpriv.Generate()

	// Create a client
	client, _ := walletclient.New(
        walletclient.WithXPriv(keys.XPriv()),
        walletclient.WithHTTP("localhost:3001"),
        walletclient.WithSignRequest(true))
    
    fmt.Println(client.IsSignRequest())
}

Checkout all the examples!


Contributing

All kinds of contributions are welcome!
To get started, take a look at code standards.
View the contributing guidelines and follow the code of conduct.


License

License

Documentation

Overview

Package walletclient is a Go client for interacting with Spv Wallet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOps

type ClientOps func(c *WalletClient)

ClientOps are used for client options

func WithAccessKey

func WithAccessKey(accessKeyString string) ClientOps

WithAccessKey will set the access key on the client

func WithAdminKey

func WithAdminKey(adminKey string) ClientOps

WithAdminKey will set the admin key for admin requests

func WithHTTP

func WithHTTP(serverURL string) ClientOps

WithHTTP will overwrite the default client with a custom client

func WithHTTPClient

func WithHTTPClient(serverURL string, httpClient *http.Client) ClientOps

WithHTTPClient will overwrite the default client with a custom client

func WithSignRequest

func WithSignRequest(signRequest bool) ClientOps

WithSignRequest will set whether to sign all requests

func WithXPriv

func WithXPriv(xPrivString string) ClientOps

WithXPriv will set xPrivString on the client

func WithXPub

func WithXPub(xPubString string) ClientOps

WithXPub will set xPubString on the client

type WalletClient

type WalletClient struct {
	transports.TransportService
	// contains filtered or unexported fields
}

WalletClient is the spv wallet go client representation.

func New

func New(opts ...ClientOps) (*WalletClient, error)

New create a new wallet client

func (*WalletClient) CreateAccessKey

func (b *WalletClient) CreateAccessKey(ctx context.Context, metadata *models.Metadata) (*models.AccessKey, transports.ResponseError)

CreateAccessKey creates new access key

func (*WalletClient) DraftToRecipients

func (b *WalletClient) DraftToRecipients(ctx context.Context, recipients []*transports.Recipients,
	metadata *models.Metadata,
) (*models.DraftTransaction, transports.ResponseError)

DraftToRecipients initialize a new P2PKH draft transaction to a list of recipients

func (*WalletClient) DraftTransaction

func (b *WalletClient) DraftTransaction(ctx context.Context, transactionConfig *models.TransactionConfig,
	metadata *models.Metadata,
) (*models.DraftTransaction, transports.ResponseError)

DraftTransaction initialize a new draft transaction

func (*WalletClient) FinalizeTransaction

func (b *WalletClient) FinalizeTransaction(draft *models.DraftTransaction) (string, transports.ResponseError)

FinalizeTransaction will finalize the transaction

func (*WalletClient) GetAccessKey

GetAccessKey gets the access key given by id

func (*WalletClient) GetAccessKeys

func (b *WalletClient) GetAccessKeys(ctx context.Context, metadataConditions *models.Metadata) ([]*models.AccessKey, transports.ResponseError)

GetAccessKeys gets all the access keys filtered by the metadata

func (*WalletClient) GetDestinationByAddress

func (b *WalletClient) GetDestinationByAddress(ctx context.Context, address string) (*models.Destination, transports.ResponseError)

GetDestinationByAddress gets the destination by address

func (*WalletClient) GetDestinationByID

func (b *WalletClient) GetDestinationByID(ctx context.Context, id string) (*models.Destination, transports.ResponseError)

GetDestinationByID gets the destination by id

func (*WalletClient) GetDestinationByLockingScript

func (b *WalletClient) GetDestinationByLockingScript(ctx context.Context,
	lockingScript string,
) (*models.Destination, transports.ResponseError)

GetDestinationByLockingScript gets the destination by locking script

func (*WalletClient) GetDestinations

func (b *WalletClient) GetDestinations(ctx context.Context,
	metadataConditions *models.Metadata,
) ([]*models.Destination, transports.ResponseError)

GetDestinations gets all destinations that match the metadata filter

func (*WalletClient) GetTransaction

func (b *WalletClient) GetTransaction(ctx context.Context, txID string) (*models.Transaction, transports.ResponseError)

GetTransaction get a transaction by id

func (*WalletClient) GetTransactions

func (b *WalletClient) GetTransactions(ctx context.Context, conditions map[string]interface{},
	metadata *models.Metadata, queryParams *transports.QueryParams,
) ([]*models.Transaction, transports.ResponseError)

GetTransactions get all transactions matching search criteria

func (*WalletClient) GetTransactionsCount

func (b *WalletClient) GetTransactionsCount(ctx context.Context, conditions map[string]interface{},
	metadata *models.Metadata,
) (int64, transports.ResponseError)

GetTransactionsCount get number of user transactions

func (*WalletClient) GetTransport

func (b *WalletClient) GetTransport() *transports.TransportService

GetTransport returns the current transport service

func (*WalletClient) GetXPub

GetXPub gets the current xpub

func (*WalletClient) IsSignRequest

func (b *WalletClient) IsSignRequest() bool

IsSignRequest return whether to sign all requests

func (*WalletClient) NewDestination

func (b *WalletClient) NewDestination(ctx context.Context, metadata *models.Metadata) (*models.Destination, transports.ResponseError)

NewDestination create a new destination and return it

func (*WalletClient) RecordTransaction

func (b *WalletClient) RecordTransaction(ctx context.Context, hex, draftID string,
	metadata *models.Metadata,
) (*models.Transaction, transports.ResponseError)

RecordTransaction record a new transaction

func (*WalletClient) RevokeAccessKey

func (b *WalletClient) RevokeAccessKey(ctx context.Context, id string) (*models.AccessKey, transports.ResponseError)

RevokeAccessKey revoked the access key given by id

func (*WalletClient) SendToRecipients

func (b *WalletClient) SendToRecipients(ctx context.Context, recipients []*transports.Recipients,
	metadata *models.Metadata,
) (*models.Transaction, transports.ResponseError)

SendToRecipients send to recipients

func (*WalletClient) SetAdminKey

func (b *WalletClient) SetAdminKey(adminKeyString string) error

SetAdminKey set the admin key to use to create new xpubs

func (*WalletClient) SetSignRequest

func (b *WalletClient) SetSignRequest(signRequest bool)

SetSignRequest turn the signing of the http request on or off

func (*WalletClient) UpdateDestinationMetadataByAddress

func (b *WalletClient) UpdateDestinationMetadataByAddress(ctx context.Context, address string,
	metadata *models.Metadata,
) (*models.Destination, transports.ResponseError)

UpdateDestinationMetadataByAddress updates the destination metadata by address

func (*WalletClient) UpdateDestinationMetadataByID

func (b *WalletClient) UpdateDestinationMetadataByID(ctx context.Context, id string,
	metadata *models.Metadata,
) (*models.Destination, transports.ResponseError)

UpdateDestinationMetadataByID updates the destination metadata by id

func (*WalletClient) UpdateDestinationMetadataByLockingScript

func (b *WalletClient) UpdateDestinationMetadataByLockingScript(ctx context.Context, lockingScript string,
	metadata *models.Metadata,
) (*models.Destination, transports.ResponseError)

UpdateDestinationMetadataByLockingScript updates the destination metadata by locking script

func (*WalletClient) UpdateTransactionMetadata

func (b *WalletClient) UpdateTransactionMetadata(ctx context.Context, txID string,
	metadata *models.Metadata,
) (*models.Transaction, transports.ResponseError)

UpdateTransactionMetadata update the metadata of a transaction

func (*WalletClient) UpdateXPubMetadata

func (b *WalletClient) UpdateXPubMetadata(ctx context.Context, metadata *models.Metadata) (*models.Xpub, transports.ResponseError)

UpdateXPubMetadata update the metadata of the logged in xpub

Directories

Path Synopsis
examples module
Package transports encapsulates the different ways to communicate with SPV Wallet
Package transports encapsulates the different ways to communicate with SPV Wallet
Package utils contains utility functions for the wallet like hashes and crypto functions
Package utils contains utility functions for the wallet like hashes and crypto functions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL