handcash

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 15 Imported by: 1

README

go-handcash-connect

The unofficial golang implementation for the HandCash Connect SDK

Release Build Status Report codecov Go
Mergify Status Gitpod Ready-to-Code


Table of Contents


Installation

go-handcash-connect requires a supported release of Go.

go get -u github.com/tonicpow/go-handcash-connect

Documentation

View the generated documentation

GoDoc

Features
  • Current coverage for the HandCash Connect SDK
    • GetProfile
    • Pay
    • GetPayment
    • GetEncryptionKeypair
    • GetFriends
    • GetPermissions
    • GetPublicProfiles
    • GetSpendableBalance
    • SignData
Library Deployment

goreleaser for easy binary or library deployment to GitHub and can be installed via: brew install goreleaser.

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

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

Makefile Commands

View all makefile commands

make help

List of all current commands:

all                  Runs lint, test-short and vet
clean                Remove previous builds and any test cache 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-go           Install the application (Using Native Go)
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-linter        Update the golangci-lint package (macOS only)
vet                  Run the Go vet application

Examples & Tests

All unit tests and examples run via GitHub Actions and uses Go version 1.18.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

View the examples


Maintainers

MrZ Satchmo
MrZ Satchmo

Contributing

View the contributing guidelines and please follow the code of conduct.

Stars

Credits

HandCash for their hard work on the HandCash Connect SDK


License

License

Documentation

Overview

Package handcash is an unofficial Go version of HandCash Connect's SDK

If you have any suggestions or comments, please feel free to open an issue on this GitHub repository!

By TonicPow Inc (https://tonicpow.com)

Index

Examples

Constants

View Source
const (
	EnvironmentBeta       = "beta"
	EnvironmentIAE        = "iae"
	EnvironmentProduction = "prod"
)

Environments for Handcash

Variables

This section is empty.

Functions

This section is empty.

Types

type AppAction added in v0.1.0

type AppAction string

AppAction enum

const (
	AppActionLike     AppAction = "like"
	AppActionPublish  AppAction = "publish"
	AppActionTip      AppAction = "tip"
	AppActionTipGroup AppAction = "tip-group"
)

AppAction enum

type Attachment added in v0.1.0

type Attachment struct {
	Format AttachmentFormat `json:"format,omitempty"`
	Value  interface{}      `json:"value,omitempty"`
}

Attachment is for additional data

type AttachmentFormat added in v0.1.0

type AttachmentFormat string

AttachmentFormat enum

const (
	AttachmentFormatBase64 AttachmentFormat = "base64"
	AttachmentFormatHex    AttachmentFormat = "hex"
	AttachmentFormatJSON   AttachmentFormat = "json"
)

AttachmentFormat enum

type BalanceRequest added in v0.1.5

type BalanceRequest struct {
	CurrencyCode CurrencyCode `json:"currencyCode"`
}

BalanceRequest is used for GetSpendableBalance()

type Client added in v0.1.0

type Client struct {
	Environment *Environment // Current environment for the client

	Options *ClientOptions // Client options config
	// contains filtered or unexported fields
}

Client is the parent struct that contains the miner clients and list of miners to use

func NewClient added in v0.1.0

func NewClient(options *ClientOptions, customHTTPClient *http.Client,
	customEnvironment string) (c *Client)

NewClient creates a new client for requests If no environment is set, production is used as the default

Example

ExampleNewClient example using NewClient()

client := NewClient(nil, nil, EnvironmentIAE)

fmt.Printf("created new client: %s", client.Options.UserAgent)
Output:

created new client: go-handcash-connect: v0.3.1

func (*Client) GetPayment added in v0.1.0

func (c *Client) GetPayment(ctx context.Context, authToken,
	transactionID string) (*PaymentResponse, error)

GetPayment fetches a payment by transaction id

Specs: https://github.com/HandCash/handcash-connect-sdk-js/blob/master/src/api/http_request_factory.js

func (*Client) GetProfile added in v0.1.0

func (c *Client) GetProfile(ctx context.Context, token string) (*Profile, error)

GetProfile will get the profile for the associated auth token

Specs: https://github.com/HandCash/handcash-connect-sdk-js/blob/master/src/profile/index.js

func (*Client) GetSpendableBalance added in v0.1.5

func (c *Client) GetSpendableBalance(ctx context.Context, authToken string,
	currencyCode CurrencyCode) (*SpendableBalanceResponse, error)

GetSpendableBalance gets the user's spendable balance from the handcash connect API

func (*Client) Pay added in v0.1.0

func (c *Client) Pay(ctx context.Context, authToken string,
	payParams *PayParameters) (*PaymentResponse, error)

Pay makes a new payment request to the HandCash Connect API

Specs: https://github.com/HandCash/handcash-connect-sdk-js/blob/master/src/api/http_request_factory.js

type ClientOptions added in v0.1.0

type ClientOptions struct {
	BackOffExponentFactor          float64       `json:"back_off_exponent_factor"`
	BackOffInitialTimeout          time.Duration `json:"back_off_initial_timeout"`
	BackOffMaximumJitterInterval   time.Duration `json:"back_off_maximum_jitter_interval"`
	BackOffMaxTimeout              time.Duration `json:"back_off_max_timeout"`
	DialerKeepAlive                time.Duration `json:"dialer_keep_alive"`
	DialerTimeout                  time.Duration `json:"dialer_timeout"`
	RequestRetryCount              int           `json:"request_retry_count"`
	RequestTimeout                 time.Duration `json:"request_timeout"`
	TransportExpectContinueTimeout time.Duration `json:"transport_expect_continue_timeout"`
	TransportIdleTimeout           time.Duration `json:"transport_idle_timeout"`
	TransportMaxIdleConnections    int           `json:"transport_max_idle_connections"`
	TransportTLSHandshakeTimeout   time.Duration `json:"transport_tls_handshake_timeout"`
	UserAgent                      string        `json:"user_agent"`
}

ClientOptions holds all the configuration for connection, dialer and transport

func DefaultClientOptions added in v0.1.0

func DefaultClientOptions() (clientOptions *ClientOptions)

DefaultClientOptions will return an Options struct with the default settings. Useful for starting with the default and then modifying as needed

Example

ExampleDefaultClientOptions example using DefaultClientOptions()

options := DefaultClientOptions()
options.UserAgent = "Custom UserAgent v1.0"
client := NewClient(options, nil, "")

fmt.Printf("created new client with user agent: %s", client.Options.UserAgent)
Output:

created new client with user agent: Custom UserAgent v1.0

type CurrencyCode added in v0.1.0

type CurrencyCode string

CurrencyCode is an enum for supported currencies

const (
	CurrencyARS CurrencyCode = "ARS"
	CurrencyAUD CurrencyCode = "AUD"
	CurrencyBRL CurrencyCode = "BRL"
	CurrencyBSV CurrencyCode = "BSV"
	CurrencyCAD CurrencyCode = "CAD"
	CurrencyCHF CurrencyCode = "CHF"
	CurrencyCNY CurrencyCode = "CNY"
	CurrencyCOP CurrencyCode = "COP"
	CurrencyCZK CurrencyCode = "CZK"
	CurrencyDKK CurrencyCode = "DKK"
	CurrencyEUR CurrencyCode = "EUR"
	CurrencyGBP CurrencyCode = "GBP"
	CurrencyHKD CurrencyCode = "HKD"
	CurrencyJPY CurrencyCode = "JPY"
	CurrencyMXN CurrencyCode = "MXN"
	CurrencyNOK CurrencyCode = "NOK"
	CurrencyNZD CurrencyCode = "NZD"
	CurrencyPHP CurrencyCode = "PHP"
	CurrencyRUB CurrencyCode = "RUB"
	CurrencySAT CurrencyCode = "SAT"
	CurrencySEK CurrencyCode = "SEK"
	CurrencySGD CurrencyCode = "SGD"
	CurrencyTHB CurrencyCode = "THB"
	CurrencyUSD CurrencyCode = "USD"
	CurrencyZAR CurrencyCode = "ZAR"
)

CurrencyCode enums

type Environment added in v0.1.0

type Environment struct {
	APIURL      string `json:"api_url"`
	ClientURL   string `json:"client_url"`
	Environment string `json:"environment"`
}

Environment is the Handcash environment information

type Participant added in v0.1.0

type Participant struct {
	Alias             string          `json:"alias"`
	DisplayName       string          `json:"displayName"`
	ProfilePictureURL string          `json:"profilePictureUrl"`
	ResponseNote      string          `json:"responseNote"`
	Type              ParticipantType `json:"type"`
}

Participant is used for payments

type ParticipantType added in v0.1.0

type ParticipantType string

ParticipantType enum

const (
	ParticipantUser ParticipantType = "user"
)

ParticipantUser enum

type PayParameters added in v0.1.0

type PayParameters struct {
	AppAction   AppAction   `json:"appAction,omitempty"`
	Attachment  *Attachment `json:"attachment,omitempty"`
	Description string      `json:"description,omitempty"`
	Receivers   []*Payment  `json:"receivers,omitempty"`
}

PayParameters is used by Pay()

type Payment added in v0.1.0

type Payment struct {
	Amount       float64      `json:"amount"`
	CurrencyCode CurrencyCode `json:"currencyCode"`
	To           string       `json:"to"`
}

Payment is used by PayParameters

type PaymentRequest added in v0.1.0

type PaymentRequest struct {
	TransactionID string `json:"transactionId"`
}

PaymentRequest is used for GetPayment()

type PaymentResponse added in v0.1.0

type PaymentResponse struct {
	AppAction         AppAction      `json:"appAction"`
	Attachments       []*Attachment  `json:"attachments"`
	FiatCurrencyCode  CurrencyCode   `json:"fiatCurrencyCode"`
	FiatExchangeRate  float64        `json:"fiatExchangeRate"`
	Note              string         `json:"note"`
	Participants      []*Participant `json:"participants"`
	RawTransactionHex string         `json:"rawTransactionHex,omitempty"`
	SatoshiAmount     uint64         `json:"satoshiAmount"`
	SatoshiFees       uint64         `json:"satoshiFees"`
	Time              uint64         `json:"time"`
	TransactionID     string         `json:"transactionId"`
	Type              PaymentType    `json:"type"`
}

PaymentResponse is returned from the GetPayment function

type PaymentType added in v0.1.0

type PaymentType string

PaymentType enum

const (
	PaymentSend PaymentType = "send"
)

PaymentSend enum

type PrivateProfile

type PrivateProfile struct {
	Email       string `json:"email"`
	PhoneNumber string `json:"phoneNumber"`
}

PrivateProfile is the private profile

type Profile added in v0.1.0

type Profile struct {
	PublicProfile  PublicProfile  `json:"publicProfile"`
	PrivateProfile PrivateProfile `json:"privateProfile"`
}

Profile are the user fields returned by the public and private profile endpoints

type PublicProfile

type PublicProfile struct {
	AvatarURL         string       `json:"avatarUrl"`
	DisplayName       string       `json:"displayName"`
	Handle            string       `json:"handle"`
	ID                string       `json:"id"`
	LocalCurrencyCode CurrencyCode `json:"localCurrencyCode"`
	Paymail           string       `json:"paymail"`
	BitcoinUnit       string       `json:"bitcoinUnit"`
}

PublicProfile is the public profile

type RequestResponse added in v0.1.0

type RequestResponse struct {
	BodyContents []byte `json:"body_contents"` // Raw body response
	Error        error  `json:"error"`         // If an error occurs
	Method       string `json:"method"`        // Method is the HTTP method used
	PostData     string `json:"post_data"`     // PostData is the post data submitted if POST/PUT request
	StatusCode   int    `json:"status_code"`   // StatusCode is the last code from the request
	URL          string `json:"url"`           // URL is used for the request
}

RequestResponse is the response from a request

type SpendableBalanceResponse added in v0.1.5

type SpendableBalanceResponse struct {
	SpendableSatoshiBalance uint64       `json:"spendableSatoshiBalance"`
	SpendableFiatBalance    float64      `json:"spendableFiatBalance"`
	CurrencyCode            CurrencyCode `json:"currencyCode"`
}

SpendableBalanceResponse is the balance response

Directories

Path Synopsis
examples
pay

Jump to

Keyboard shortcuts

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