Documentation ¶
Overview ¶
Package upvest provides the binding for Upvest REST APIs. Where possible, the services available on the client groups the API into logical chunks and correspond to the structure of the Upvest API documentation at https://doc.upvest.co/reference.
First, create an Upvest client and depending on what action to take, you either create tenancy or clientele client. All tenancy related operations must be authenticated using the API Keys Authentication, whereas all actions on a user's behalf need to be authenticated via OAuth. The API calls are built along with those two authentication objects.
Usage:
// NewClient creates a new Upvest API client with the given base URL // and HTTP client, allowing overriding of the HTTP client to use. // This is useful if you're running in a Google AppEngine environment // where the http.DefaultClient is not available. c := NewClient("", nil) // Tenant API - API Keys Authentication // The Upvest API uses the notion of _tenants_, which represent customers that build their platform upon the Upvest API. // The authentication via API keys and secret allows you to perform all tenant related operations. tenancyClient = c.NewTenant(apiKey, apiSecret, apiPassphrase) // create a user user, err := tenancyClient.User.Create(username, randomString(12)) if err != nil { t.Errorf("CREATE User returned error: %v", err) } // list users users, err := tenancyClient.User.List() if err != nil { t.Errorf("List Users returned error: %v", err) } // retrieve 20 users users, err := tenancyClient.User.ListN(20) if err != nil { t.Errorf("List Users returned error: %v", err) } // change password user, err = tenancyClient.User.Update(username, params) // Clinetele API - OAuth Authentication // The authentication via OAuth allows you to perform operations on behalf of your user. // For more information on the OAuth concept, please refer to our documentation at https://doc.upvest.co/docs/oauth2-authentication // Next, create an `Clientele` object with these credentials // and your user authentication data in order to authenticate your API calls on behalf of a user: clienteleClient = c.NewClientele(clientID, clientSecret, username, password) wp := &WalletParams{ Password: staticUserPW, AssetID: ethWallet.Balances[0].AssetID, } // create the wallet wallet, err := clienteleTestClient.Wallet.Create(wp) if err != nil { t.Errorf("CREATE Wallet returned error: %v", err) } // // retrieve the wallet wallet1, err := clienteleTestClient.Wallet.Get(wallet.ID) if err != nil { t.Errorf("GET Wallet returned error: %v", err) }
Index ¶
- Constants
- type Asset
- type AssetList
- type AssetService
- type AuthProvider
- type Balance
- type ChangePasswordParams
- type Client
- func (c *Client) Call(method, path string, body, v interface{}, p *Params) error
- func (c *Client) NewClientele(clientID, clientSecret, username, password string) *ClienteleAPI
- func (c *Client) NewRequest(method, path string, body interface{}, params *Params) (*http.Request, error)
- func (c *Client) NewTenant(apiKey, apiSecret, apiPassphrase string) *TenancyAPI
- type ClienteleAPI
- type Error
- type ErrorType
- type Headers
- type KeyAuth
- type ListMeta
- type Logger
- type OAuth
- type OAuthResponse
- type Params
- type Response
- type Signature
- type SignatureParams
- type TenancyAPI
- type Transaction
- type TransactionList
- type TransactionParams
- type TransactionService
- type User
- type UserList
- type UserService
- func (s *UserService) ChangePassword(username string, params *ChangePasswordParams) (*User, error)
- func (s *UserService) Create(username, password string) (*User, error)
- func (s *UserService) Delete(username string) error
- func (s *UserService) Get(username string) (*User, error)
- func (s *UserService) List() (*UserList, error)
- func (s *UserService) ListN(count int) (*UserList, error)
- type Wallet
- type WalletList
- type WalletParams
- type WalletService
- func (s *WalletService) Create(wp *WalletParams) (*Wallet, error)
- func (s *WalletService) Get(walletID string) (*Wallet, error)
- func (s *WalletService) List() (*WalletList, error)
- func (s *WalletService) ListN(count int) (*WalletList, error)
- func (s *WalletService) Sign(walletID string, sp *SignatureParams) (*Signature, error)
Constants ¶
const ( ErrInvalidRequest ErrorType = "invalid_request_error" ErrAuthorization = "authorization_error" ErrAuthentication = "authentication_error" ErrDuplicateUser = "duplicate_user" ErrServer = "server_error" )
List of values that ErrorType can take.
const ( // DefaultHTTPTimeout is the default timeout on the http client DefaultHTTPTimeout = 60 * time.Second // DefaultBaseURL for all requests. default to playground environment DefaultBaseURL = "https://api.playground.upvest.co/" // UserAgent used when communicating with the Upvest API. UserAgent = "upvest-go/" + version // APIVersion is the currently supported API version APIVersion = "1.0" // Encoding is the text encoding to use Encoding = "utf-8" // MaxPageSize is the maximum page size when retrieving list MaxPageSize = 100 )
const (
// URLEncodeHeader is the content-type header for OuAth2
URLEncodeHeader = "application/x-www-form-urlencoded"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Asset ¶
type Asset struct { ID string `json:"id"` Name string `json:"name"` Symbol string `json:"symbol"` Exponent int64 `json:"exponent"` Protocol string `json:"protocol"` MetaData map[string]interface{} `json:"metadata"` }
Asset is the resource representing your Upvest Tenant asset. For more details see https://doc.upvest.co/reference#assets
type AssetService ¶
type AssetService struct {
// contains filtered or unexported fields
}
AssetService handles operations related to the asset For more details see https://doc.upvest.co/reference#assets/
func (*AssetService) Get ¶
func (s *AssetService) Get(assetID string) (*Asset, error)
Get returns the details of a asset. For more details see https://doc.upvest.co/reference#common_assets_read
func (*AssetService) List ¶
func (s *AssetService) List() (*AssetList, error)
List returns list of all assets. For more details see https://doc.upvest.co/reference#asset
type AuthProvider ¶
type AuthProvider interface { // GetHeaders returns authorization headers (or other info) to be attached to requests. GetHeaders(method, path string, body interface{}, c *Client) (Headers, error) }
AuthProvider interface for authentication mechanisms supported by Upvest API
type Balance ¶
type Balance struct { Amount int64 `json:"amount"` AssetID string `json:"asset_id"` Name string `json:"name"` Symbol string `json:"symbol"` Exponent int `json:"exponent"` }
Balance has a quantity and an asset
type ChangePasswordParams ¶
type ChangePasswordParams struct { //Params `json:"-"` OldPassword string `json:"old_password"` NewPassword string `json:"new_password"` }
ChangePasswordParams is the set of parameters that can be used when changing user password For more details see https://doc.upvest.co/reference#tenancy_user_password_update
type Client ¶
Client manages communication with the Upvest API Service specific actions are implemented on resource services mapped to the Upvest API. Miscellaneous actions are directly implemented on the Client object
func NewClient ¶
NewClient creates a new Upvest API client with the given base URL and HTTP client, allowing overriding of the HTTP client to use. This is useful if you're running in a Google AppEngine environment where the http.DefaultClient is not available.
func (*Client) Call ¶
Call actually does the HTTP request to Upvest API TODO: refactor additional params into Param struct
func (*Client) NewClientele ¶
func (c *Client) NewClientele(clientID, clientSecret, username, password string) *ClienteleAPI
NewClientele creates a new clientele for interacting with your Upvest clients/users
func (*Client) NewRequest ¶
func (c *Client) NewRequest(method, path string, body interface{}, params *Params) (*http.Request, error)
NewRequest is used by Call to generate an http.Request. It handles encoding parameters and attaching the appropriate headers.
func (*Client) NewTenant ¶
func (c *Client) NewTenant(apiKey, apiSecret, apiPassphrase string) *TenancyAPI
NewTenant creates a new tenant for interacting with your Upvest tenant
type ClienteleAPI ¶
type ClienteleAPI struct { Wallet *WalletService Transaction *TransactionService }
ClienteleAPI represents Upvest Clientele API For more details, please see https://doc.upvest.co/reference#clientele
type Error ¶
type Error struct { Type ErrorType `json:"type,omitempty"` Message string `json:"message,omitempty"` StatusCode int `json:"code,omitempty"` Details map[string]interface{} `json:"details,omitempty"` URL *url.URL `json:"url,omitempty"` Header http.Header `json:"header,omitempty"` }
Error represents an error response from the Upvest API server
type ErrorType ¶
type ErrorType string
ErrorType is represents the allowed values for the error's type.
type KeyAuth ¶
type KeyAuth struct {
// contains filtered or unexported fields
}
KeyAuth (The API Key Authentication) is used to authenticate requests as a tenant.
type Logger ¶
type Logger interface {
Printf(format string, v ...interface{})
}
Logger interface for custom loggers
type OAuth ¶
type OAuth struct {
// contains filtered or unexported fields
}
OAuth (The OAuth2 Key Authentication) is used to authenticate requests on behalf of a user
type OAuthResponse ¶
type OAuthResponse struct { AccessToken string `json:"access_token"` ExpiresIn string `json:"exxpires_in"` TokenType string `json:"token_type"` Scope string `json:"scope"` RefreshToken string `json:"refresh_token"` }
OAuthResponse represents succesful OAuth response
type Params ¶
type Params struct { // Headers may be used to provide extra header lines on the HTTP request. Headers http.Header `json:"-"` // AuthProvider for authenticating the request AuthProvider AuthProvider `json:"-"` }
Params is the structure that contains the common properties of any *Params structure.
func (*Params) SetAuthProvider ¶
func (p *Params) SetAuthProvider(auth AuthProvider)
SetAuthProvider sets a value for the auth mechanism
type Signature ¶
type Signature struct { // Has the same value as the "output_format" parameter. // The name of the string format for the big numbers in the signature. (Some JSON implementations can not handle integers which need more than 64 bits to be represented.) BigNumberFormat string `json:"big_number_format"` // The encryption algorithm used. (Currently only ECDSA) Algorithm string `json:"algorithm"` // The name of the elliptic curve used. Curve string `json:"curve"` // The x coordinate of the public key of the wallet PublicKey map[string]interface{} `json:"public_key"` // The "r" signature component. // Represented in the format given in the "big_number_format" field. R string `json:"r"` // The "s" signature component. // Represented in the format given in the "big_number_format" field. S string `json:"s"` // The "recover" signature component, sometimes also called "v". // Since this is a small integer with less than 64 bits, this is an actual JSON integer, and NOT represented in the big integer format. Recover string `json:"string"` }
Signature represents the signed wallet signature For more details, see https://doc.upvest.co/reference#kms_sign
type SignatureParams ¶
type SignatureParams struct { //Params `json:"-"` Password string `json:"password"` ToSign string `json:"to_sign"` InputFormat string `json:"input_format,omitempty"` OutputFormat string `json:"output_format,omitempty"` }
SignatureParams is the set of parameters that can be used when signing a wallet For more details see https://doc.upvest.co/reference#kms_sign
type TenancyAPI ¶
type TenancyAPI struct { User *UserService Asset *AssetService }
TenancyAPI represents Upvest tenancy API For more details, please see https://doc.upvest.co/reference#tenancy
type Transaction ¶
type Transaction struct { ID string `json:"id"` TxHash string `json:"txhash"` WalletID string `json:"wallet_id"` AssetID string `json:"asset_id"` AssetName string `json:"asset_name"` Exponent string `json:"exponent"` Sender string `json:"sender"` Recipient string `json:"recipient"` Quantity string `json:"quantity"` Fee string `json:"fee"` Status string `json:"status"` }
Transaction represents a wallet transaction For more details, see https://doc.upvest.co/reference#kms_transaction_create
type TransactionList ¶
type TransactionList struct { Meta ListMeta Values []Transaction `json:"results"` }
TransactionList is a list object for transactions
type TransactionParams ¶
type TransactionParams struct { Password string `json:"password"` AssetID string `json:"asset_id"` Quantity int64 `json:"quantity"` Fee int64 `json:"fee"` Recipient string `json:"recipient"` }
TransactionParams is the set of parameters that can be used when creating a transaction For more details see https://doc.upvest.co/reference#kms_transaction_create
type TransactionService ¶
type TransactionService struct {
// contains filtered or unexported fields
}
TransactionService handles operations related to the transaction For more details see https://doc.upvest.co/reference#kms_transaction_create
func (*TransactionService) Create ¶
func (s *TransactionService) Create(walletID string, tp *TransactionParams) (*Transaction, error)
Create creates a new transaction For more details https://doc.upvest.co/reference#kms_transaction_create
func (*TransactionService) Get ¶
func (s *TransactionService) Get(walletID, txnID string) (*Transaction, error)
Get returns the details of a transaction. For more details see https://doc.upvest.co/reference#kms_transactions_read
func (*TransactionService) List ¶
func (s *TransactionService) List(walletID string) (*TransactionList, error)
List returns list of all transactions. For more details see https://doc.upvest.co/reference#kms_transaction_list
type User ¶
type User struct { Username string `json:"username,omitempty"` RecoveryKit string `json:"recoverykit,omitempty"` WalletIDs map[int]string `json:"wallet_ids,omitempty"` }
User is the resource representing your Upvest Tenant user. For more details see https://doc.upvest.co/reference#tenancy_user_create
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
UserService handles operations related to the user For more details see https://doc.upvest.co/reference#tenancy_user_create
func (*UserService) ChangePassword ¶
func (s *UserService) ChangePassword(username string, params *ChangePasswordParams) (*User, error)
ChangePassword changes user password with the provided password For more details https://doc.upvest.co/reference#tenancy_user_password_update
func (*UserService) Create ¶
func (s *UserService) Create(username, password string) (*User, error)
Create creates a new user For more details https://doc.upvest.co/reference#tenancy_user_create
func (*UserService) Delete ¶
func (s *UserService) Delete(username string) error
Delete permanently deletes a user For more details https://doc.upvest.co/reference#tenancy_user_create
func (*UserService) Get ¶
func (s *UserService) Get(username string) (*User, error)
Get returns the details of a user. For more details see
func (*UserService) List ¶
func (s *UserService) List() (*UserList, error)
List returns list of all users. For more details see https://doc.upvest.co/reference#tenancy_user_list
func (*UserService) ListN ¶
func (s *UserService) ListN(count int) (*UserList, error)
ListN returns a specific number of users For more details see https://doc.upvest.co/reference#tenancy_user_list
type Wallet ¶
type Wallet struct { ID string `json:"id"` Path string `json:"path"` Balances []Balance `json:"balances"` Protocol string `json:"protocol"` Address string `json:"address"` Status string `json:"status"` Index int64 `json:"index"` }
Wallet represents an Upvest wallet
type WalletList ¶
WalletList is a list object for wallets.
type WalletParams ¶
type WalletParams struct { //Params `json:"-"` Password string `json:"password"` AssetID string `json:"asset_id"` Type string `json:"type,omitempty"` Index int `json:"index,omitempty"` }
WalletParams is the set of parameters that can be used when creating or updating a wallet For more details see https://doc.upvest.co/reference#kms_wallet_create
type WalletService ¶
type WalletService struct {
// contains filtered or unexported fields
}
WalletService handles operations related to the wallet For more details see https://doc.upvest.co/reference#kms_wallet_create
func (*WalletService) Create ¶
func (s *WalletService) Create(wp *WalletParams) (*Wallet, error)
Create creates a new wallet For more details https://doc.upvest.co/reference#kms_wallet_create
func (*WalletService) Get ¶
func (s *WalletService) Get(walletID string) (*Wallet, error)
Get returns the details of a wallet. For more details see https://doc.upvest.co/reference#kms_wallets_read
func (*WalletService) List ¶
func (s *WalletService) List() (*WalletList, error)
List returns list of all wallets. For more details see https://doc.upvest.co/reference#wallet
func (*WalletService) ListN ¶
func (s *WalletService) ListN(count int) (*WalletList, error)
ListN returns a specific number of wallets For more details see https://doc.upvest.co/reference#tenancy_wallet_list
func (*WalletService) Sign ¶
func (s *WalletService) Sign(walletID string, sp *SignatureParams) (*Signature, error)
Sign signs (the hash of) data with the private key corresponding to this wallet. For more details, see https://doc.upvest.co/reference#kms_sign