Documentation
¶
Index ¶
- Constants
- Variables
- func EventsHandler(secret string, f EventsFunc) http.HandlerFunc
- func KinToQuarks(val string) (int64, error)
- func MustKinToQuarks(val string) int64
- func QuarksToKin(amount int64) string
- func SignTransactionHandler(env Environment, secret string, f SignTransactionFunc) http.HandlerFunc
- type Client
- type ClientOption
- func WithAppIndex(index uint16) ClientOption
- func WithEndpoint(endpoint string) ClientOption
- func WithGRPC(cc *grpc.ClientConn) ClientOption
- func WithMaxDelay(maxDelay time.Duration) ClientOption
- func WithMaxNonceRetries(maxSequenceRetries uint) ClientOption
- func WithMaxRetries(maxRetries uint) ClientOption
- func WithMinDelay(minDelay time.Duration) ClientOption
- func WithWhitelister(whitelistKey PrivateKey) ClientOption
- type Earn
- type EarnBatch
- type EarnBatchResult
- type EarnResult
- type Environment
- type EventsFunc
- type InternalClient
- func (c *InternalClient) CreateStellarAccount(ctx context.Context, key PrivateKey) error
- func (c *InternalClient) GetBlockchainVersion() (int, error)
- func (c *InternalClient) GetStellarAccountInfo(ctx context.Context, account PublicKey) (*accountpb.AccountInfo, error)
- func (c *InternalClient) GetTransaction(ctx context.Context, txHash []byte) (data TransactionData, err error)
- func (c *InternalClient) SubmitStellarTransaction(ctx context.Context, envelopeXDR []byte, invoiceList *commonpb.InvoiceList) (result SubmitStellarTransactionResult, err error)
- type Payment
- type PrivateKey
- type PublicKey
- type ReadOnlyPayment
- type SignTransactionFunc
- type SignTransactionRequest
- type SignTransactionResponse
- func (r *SignTransactionResponse) IsRejected() bool
- func (r *SignTransactionResponse) MarkAlreadyPaid(idx int)
- func (r *SignTransactionResponse) MarkSKUNotFound(idx int)
- func (r *SignTransactionResponse) MarkWrongDestination(idx int)
- func (r *SignTransactionResponse) Reject()
- func (r *SignTransactionResponse) Sign(priv PrivateKey) (err error)
- type SubmitStellarTransactionResult
- type TransactionData
- type TransactionErrors
Constants ¶
const (
SDKVersion = "0.2.0"
)
Variables ¶
var ( // Query errors. ErrAccountExists = errors.New("account already exists") ErrAccountDoesNotExist = errors.New("account does not exist") ErrTransactionNotFound = errors.New("transaction not found") // Transaction errors. ErrMalformed = errors.New("malformed transaction") ErrBadNonce = errors.New("bad nonce") ErrInsufficientBalance = errors.New("insufficient balance") ErrInsufficientFee = errors.New("insufficient fee") ErrSenderDoesNotExist = errors.New("sender account does not exist") ErrDestinationDoesNotExist = errors.New("destination account does not exist") ErrInvalidSignature = errors.New("invalid signature") // Invoice Errors ErrAlreadyPaid = errors.New("invoice already paid") ErrWrongDestination = errors.New("wrong destination") ErrSKUNotFound = errors.New("sku not found") )
Functions ¶
func EventsHandler ¶
func EventsHandler(secret string, f EventsFunc) http.HandlerFunc
EventsHandler returns an http.HandlerFunc that decodes and verifies an Events webhook call, before forwarding it to the specified EventsFunc.
func KinToQuarks ¶
KinToQuarks converts a string representation of kin the quark value.
An error is returned if the value string is invalid, or it cannot be accurately represented as quarks. For example, a value smaller than quarks, or a value _far_ greater than the supply.
func MustKinToQuarks ¶
MustKinToQuarks calls KinToQuarks, panicking if there's an error.
This should only be used if you know for sure this will not panic.
func QuarksToKin ¶
QuarksToKin converts an int64 amount of quarks to the string representation of kin.
func SignTransactionHandler ¶
func SignTransactionHandler(env Environment, secret string, f SignTransactionFunc) http.HandlerFunc
SignTransactionHandler returns an http.HandlerFunc that decodes and verifies a signtransaction webhook call, before forwarding it to the specified SignTransactionFunc.
Types ¶
type Client ¶
type Client interface {
// CreateAccount creates a kin account.
CreateAccount(ctx context.Context, key PrivateKey) (err error)
// GetBalance returns the balance of a kin account in quarks.
//
// ErrAccountDoesNotExist is returned if no account exists.
GetBalance(ctx context.Context, account PublicKey) (quarks int64, err error)
// GetTransaction returns the TransactionData for a given transaction hash.
//
// ErrTransactionNotFound is returned if no transaction exists for the hash.
GetTransaction(ctx context.Context, txHash []byte) (data TransactionData, err error)
// SubmitPayment submits a single payment to a specified kin account.
SubmitPayment(ctx context.Context, payment Payment) (txHash []byte, err error)
// SubmitEarnBatch submits a batch of earn payments.
//
// The batch may be done in on or more transactions.
SubmitEarnBatch(ctx context.Context, batch EarnBatch) (result EarnBatchResult, err error)
}
func New ¶
func New(env Environment, opts ...ClientOption) (Client, error)
New creates a new client.
todo: appIndex optional, can use string memo instead
type ClientOption ¶
type ClientOption func(*clientOpts)
ClientOption configures a Client.
func WithAppIndex ¶
func WithAppIndex(index uint16) ClientOption
WithAppIndex specifies the app index to use when submitting transactions with Invoices, _or_ to use the non-text based memo format.
func WithEndpoint ¶
func WithEndpoint(endpoint string) ClientOption
WithEndpoint specifies an endpoint to use.
It cannot be used alongside WithGRPC.
func WithGRPC ¶
func WithGRPC(cc *grpc.ClientConn) ClientOption
WithGRPC specifies a grpc.ClientConn to use.
It cannot be used alongside WithEndpoint.
func WithMaxDelay ¶
func WithMaxDelay(maxDelay time.Duration) ClientOption
WithMaxDelay specifies the maximum delay when retrying.
func WithMaxNonceRetries ¶
func WithMaxNonceRetries(maxSequenceRetries uint) ClientOption
WithMaxNonceRetries specifies the maximum number of times the client will attempt to regenerate a nonce and retry a transaction.
This is independent from WithMaxRetries.
func WithMaxRetries ¶
func WithMaxRetries(maxRetries uint) ClientOption
WithMaxRetries specifies the maximum number of retries the client will perform for transient errors.
func WithMinDelay ¶
func WithMinDelay(minDelay time.Duration) ClientOption
WithMinDelay specifies the minimum delay when retrying.
func WithWhitelister ¶
func WithWhitelister(whitelistKey PrivateKey) ClientOption
WithWhitelister specifies a whitelist key that will be used to co-sign all transactions.
type EarnBatch ¶
type EarnBatch struct {
Sender PrivateKey
Channel *PrivateKey
Memo string
Earns []Earn
}
EarnBatch is a batch of Earn payments coming from a single sender/source.
type EarnBatchResult ¶
type EarnBatchResult struct {
Succeeded []EarnResult
Failed []EarnResult
}
EarnBatchResult contains the result of an EarnBatch.
All earns are contained in the union of {Succeeded, Failed}.
type EarnResult ¶
EarnResult contains the result of a single earn within an earn batch.
type Environment ¶
type Environment string
Environment specifies the desired Kin environment to use.
const ( EnvironmentTest Environment = "test" EnvironmentProd Environment = "prod" )
type EventsFunc ¶
EventsFunc is a callback function for the Events webhook.
If an error is returned, an InternalServer error is returned to Agora. Agora will retry a limited amount of times when an InternalServerError is returned.
type InternalClient ¶
type InternalClient struct {
// contains filtered or unexported fields
}
InternalClient is a low level client used for interacting with Agora directly. The API is _not_ stable and is not intend for general use.
It is exposed in case there needs to be low level access to Agora (beyond the gRPC client directly). However, there are no stability guarantees between releases, or during a migration event.
func NewInternalClient ¶
func NewInternalClient(cc *grpc.ClientConn, retrier retry.Retrier) *InternalClient
func (*InternalClient) CreateStellarAccount ¶
func (c *InternalClient) CreateStellarAccount(ctx context.Context, key PrivateKey) error
func (*InternalClient) GetBlockchainVersion ¶
func (c *InternalClient) GetBlockchainVersion() (int, error)
func (*InternalClient) GetStellarAccountInfo ¶
func (c *InternalClient) GetStellarAccountInfo(ctx context.Context, account PublicKey) (*accountpb.AccountInfo, error)
func (*InternalClient) GetTransaction ¶
func (c *InternalClient) GetTransaction(ctx context.Context, txHash []byte) (data TransactionData, err error)
func (*InternalClient) SubmitStellarTransaction ¶
func (c *InternalClient) SubmitStellarTransaction(ctx context.Context, envelopeXDR []byte, invoiceList *commonpb.InvoiceList) (result SubmitStellarTransactionResult, err error)
type Payment ¶
type Payment struct {
Sender PrivateKey
Destination PublicKey
Type kin.TransactionType
Quarks int64
Channel *PrivateKey
Invoice *commonpb.Invoice
Memo string
}
Payment represents a kin payment.
type PrivateKey ¶
type PrivateKey ed25519.PrivateKey
PrivateKey is an ed25519.PrivateKey.
func NewPrivateKey ¶
func NewPrivateKey() (PrivateKey, error)
NewPrivateKey returns a new PrivateKey from derived from crypto/rand. The public key can be accessed via key.Public().
func PrivateKeyFromString ¶
func PrivateKeyFromString(seed string) (PrivateKey, error)
PrivateKeyFromString parses a provided address, returning a PublicKey if successful.
The address may be either a Stellar encoded seed, or a base58 encoded string.
func (PrivateKey) Public ¶
func (k PrivateKey) Public() PublicKey
Public returns the corresponding PublicKey.
type PublicKey ¶
PublicKey is an ed25519.PublicKey.
func PublicKeyFromString ¶
PublicKeyFromString parses a provided address, returning a PublicKey if successful.
The address may be either a Stellar encoded address, or a base58 encoded string.
func (PublicKey) StellarAddress ¶
StellarAddress returns the stellar address representation of the public key.
type ReadOnlyPayment ¶
type ReadOnlyPayment struct {
Sender PublicKey
Destination PublicKey
Type kin.TransactionType
Quarks int64
Invoice *commonpb.Invoice
Memo string
}
ReadOnlyPayment represents a kin payment, where none of the private keys are known.
type SignTransactionFunc ¶
type SignTransactionFunc func(SignTransactionRequest, *SignTransactionResponse) error
SignTransactionFunc is a callback function for the SignTransaction webhook.
If an error is returned, an InternalServer error is returned to Agora, and then back to the client.
To reject transactions based on specific invoice failures, use the Mark functions on the SignTransactionResponse.
To reject transactions without reason, use the Reject function on the SignTransactionResponse.
Authorized transactions should be signed with the Sign function.
type SignTransactionRequest ¶
type SignTransactionRequest struct {
// The UserID provided by the client (optional).
UserID string
// The UserPassKey provided by the client (optional).
UserPasskey string
// Payments is a set of payments that a client wishes to be signed.
Payments []ReadOnlyPayment
// Envelope is included _only_ for further validation by SDK consumers,
// which is optional.
//
// It will only be set on stellar based transactions, and is _not_ a stable API.
Envelope *xdr.TransactionEnvelope
// contains filtered or unexported fields
}
SignTransactionRequest contains the transaction and payment data that is requesting to be signed/approved.
func (*SignTransactionRequest) TxHash ¶
func (s *SignTransactionRequest) TxHash() ([]byte, error)
TxHash returns the transaction hash of the transaction being signed.
type SignTransactionResponse ¶
type SignTransactionResponse struct {
// contains filtered or unexported fields
}
SignTransactionResponse contains the response information related to a request.
It is the primary mechanism in which a SignTransactionRequest can be signed or rejected.
func (*SignTransactionResponse) IsRejected ¶
func (r *SignTransactionResponse) IsRejected() bool
IsRejected returns whether or not the transaction should be rejected, with or without reason.
func (*SignTransactionResponse) MarkAlreadyPaid ¶
func (r *SignTransactionResponse) MarkAlreadyPaid(idx int)
MarkAlreadyPaid marks the Payment at index idx as paid.
This causes the entire transaction to be rejected.
func (*SignTransactionResponse) MarkSKUNotFound ¶
func (r *SignTransactionResponse) MarkSKUNotFound(idx int)
MarkSKUNotFound marks the Payment at index idx as having the an unknown SKU value.
This causes the entire transaction to be rejected.
func (*SignTransactionResponse) MarkWrongDestination ¶
func (r *SignTransactionResponse) MarkWrongDestination(idx int)
MarkWrongDestination marks the Payment at index idx as having the wrong destination.
This causes the entire transaction to be rejected.
func (*SignTransactionResponse) Reject ¶
func (r *SignTransactionResponse) Reject()
Reject indicates the transaction should be rejected, without reason.
func (*SignTransactionResponse) Sign ¶
func (r *SignTransactionResponse) Sign(priv PrivateKey) (err error)
Sign signs the underlying transaction with the specified private key.
type SubmitStellarTransactionResult ¶
type SubmitStellarTransactionResult struct {
Hash []byte
Errors TransactionErrors
InvoiceErrors []*transactionpb.SubmitTransactionResponse_InvoiceError
}
type TransactionData ¶
type TransactionData struct {
TxHash []byte
Payments []ReadOnlyPayment
Errors TransactionErrors
}
TransactionData contains high level metadata and payments contained in a transaction.
type TransactionErrors ¶
TransactionErrors contains the error details for a transaction.
If TxError is non-nil, the transaction failed. OpErrors may or may not be set if TxErrors is set. The length of OpErrors will match the number of operations in the transaction.