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 ¶
- Constants
- type AppAction
- type Attachment
- type AttachmentFormat
- type BalanceRequest
- type Client
- func (c *Client) GetPayment(ctx context.Context, authToken, transactionID string) (*PaymentResponse, error)
- func (c *Client) GetProfile(ctx context.Context, token string) (*Profile, error)
- func (c *Client) GetSpendableBalance(ctx context.Context, authToken string, currencyCode CurrencyCode) (*SpendableBalanceResponse, error)
- func (c *Client) Pay(ctx context.Context, authToken string, payParams *PayParameters) (*PaymentResponse, error)
- type ClientOptions
- type CurrencyCode
- type Environment
- type Participant
- type ParticipantType
- type PayParameters
- type Payment
- type PaymentRequest
- type PaymentResponse
- type PaymentType
- type PrivateProfile
- type Profile
- type PublicProfile
- type RequestResponse
- type SpendableBalanceResponse
Examples ¶
Constants ¶
const ( EnvironmentBeta = "beta" EnvironmentIAE = "iae" EnvironmentProduction = "prod" )
Environments for Handcash
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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
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 ¶
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