Documentation
¶
Index ¶
- Constants
- type Balance
- type BalanceReader
- type BalanceService
- type BroadcastWriter
- type ClientError
- type DerivationExistsArgs
- type DerivationReader
- type Destination
- type DestinationCreate
- type DestinationsArgs
- type DestinationsCreate
- type DestinationsCreateArgs
- type DestinationsReader
- type DestinationsReaderWriter
- type DestinationsService
- type DestinationsWriter
- type FeeReader
- type Invoice
- type InvoiceArgs
- type InvoiceCreate
- type InvoiceReader
- type InvoiceReaderWriter
- type InvoiceService
- type InvoiceState
- type InvoiceUpdateArgs
- type InvoiceUpdatePaid
- type InvoiceUpdateRefunded
- type InvoiceWriter
- type KeyArgs
- type MetaData
- type Output
- type OwnerService
- type OwnerStore
- type P2PCapabilityArgs
- type P2POutputCreateArgs
- type P2PPayment
- type P2PTransaction
- type P2PTransactionArgs
- type P2PTransactionMetadata
- type PaymailReader
- type PaymailReaderWriter
- type PaymailWriter
- type PaymentCreate
- type PaymentsService
- type PrivateKey
- type PrivateKeyReader
- type PrivateKeyReaderWriter
- type PrivateKeyService
- type PrivateKeyWriter
- type ProofCallback
- type ProofCallbackArgs
- type ProofCallbackWriter
- type ProofCreateArgs
- type ProofWrapper
- type ProofsService
- type ProofsWriter
- type SpendTxo
- type SpendTxoArgs
- type Transacter
- type Transaction
- type TransactionArgs
- type TransactionCreate
- type TransactionStateUpdate
- type TransactionWriter
- type TxState
- type Txo
- type TxoArgs
- type TxoCreate
- type TxoWriter
- type User
Constants ¶
const (
// DustLimit is the minimum amount a miner will accept from an output.
DustLimit = 136
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Balance ¶
type Balance struct {
Satoshis uint64 `json:"satoshis" db:"satoshis"`
}
Balance contains the current balance of unspent outputs.
type BalanceReader ¶
BalanceReader is used to read balance info from a datastore.
type BalanceService ¶
BalanceService is used to enforce balance buiness rules.
type BroadcastWriter ¶
type BroadcastWriter interface {
// Broadcast will submit a tx to a blockchain network.
Broadcast(ctx context.Context, tx *bt.Tx) error
}
BroadcastWriter is used to submit a transaction for public broadcast to nodes.
type ClientError ¶
type ClientError struct {
ID string `json:"id" example:"e97970bf-2a88-4bc8-90e6-2f597a80b93d"`
Code string `json:"code" example:"N01"`
Title string `json:"title" example:"not found"`
Message string `json:"message" example:"unable to find foo when loading bar"`
}
ClientError defines an error type that can be returned to handle client errors.
type DerivationExistsArgs ¶
type DerivationExistsArgs struct {
KeyName string `db:"key_name"`
Path string `db:"derivation_path"`
}
DerivationExistsArgs are used to check a derivation path exists for a specific master key and path.
type DerivationReader ¶
type DerivationReader interface {
DerivationPathExists(ctx context.Context, args DerivationExistsArgs) (bool, error)
}
DerivationReader can be used to read derivation path data from a data store.
type Destination ¶
type Destination struct {
SPVRequired bool `json:"spvRequired"`
Outputs []Output `json:"outputs"`
Fees *bt.FeeQuote `json:"fees"`
}
Destination contains outputs and current fees required to construct a transaction.
type DestinationCreate ¶
type DestinationCreate struct {
Script string `db:"locking_script"`
DerivationPath string `db:"derivation_path"`
Satoshis uint64 `db:"satoshis"`
Keyname string `db:"key_name"`
}
DestinationCreate can be used to create a single Output for storage.
type DestinationsArgs ¶
type DestinationsArgs struct {
InvoiceID string `param:"invoiceID"`
}
DestinationsArgs are used to get a set of Denominations for an existing InvoiceID.
func (DestinationsArgs) Validate ¶
func (d DestinationsArgs) Validate() error
Validate will ensure arguments to get destinations are as expected.
type DestinationsCreate ¶
DestinationsCreate will create new destinations.
func (DestinationsCreate) Validate ¶
func (d DestinationsCreate) Validate() error
Validate will ensure arguments for destinationsCreate are valid, otherwise an error is returned.
type DestinationsCreateArgs ¶
type DestinationsCreateArgs struct {
// InvoiceID, this is optional, if not supplied destinations
// will not be associated with an invoice.
InvoiceID null.String `db:"invoice_id"`
}
DestinationsCreateArgs are used when adding destinations to a datastore and can be sued to group them.
type DestinationsReader ¶
type DestinationsReader interface {
// Destinations will return destination outputs.
Destinations(ctx context.Context, args DestinationsArgs) ([]Output, error)
}
DestinationsReader will return destination outputs.
type DestinationsReaderWriter ¶
type DestinationsReaderWriter interface {
DestinationsReader
DestinationsWriter
}
DestinationsReaderWriter combines the reader and writer interfaces for convenience.
type DestinationsService ¶
type DestinationsService interface {
// InvoiceCreate will split satoshis into multiple denominations and store
// as denominations waiting to be fulfilled in a tx.
DestinationsCreate(ctx context.Context, req DestinationsCreate) (*Destination, error)
// Destinations given the args, will return a set of Destinations.
Destinations(ctx context.Context, args DestinationsArgs) (*Destination, error)
}
DestinationsService enforces business rules and validation for Destinations.
type DestinationsWriter ¶
type DestinationsWriter interface {
// DestinationsCreate will add a set of destinations to a data store.
DestinationsCreate(ctx context.Context, args DestinationsCreateArgs, req []DestinationCreate) ([]Output, error)
}
DestinationsWriter can be implemented to store new destinations in a data store.
type FeeReader ¶
type FeeReader interface {
// Fees will return fees from a datastore.
Fees(ctx context.Context) (*bt.FeeQuote, error)
}
FeeReader can be implemented to read fees.
type Invoice ¶
type Invoice struct {
// ID is a unique identifier for an invoice and can be used
// to lookup a single invoice.
ID string `json:"id" db:"invoice_id"`
// Reference is an identifier that can be used to link the
// PayD invoice with an external system.
Reference null.String `json:"reference" db:"payment_reference"`
// Description is an optional text field that can have some further info
// like 'invoice for oranges'.
Description null.String `json:"description" db:"description"`
// Satoshis is the total amount this invoice is to pay.
Satoshis uint64 `json:"satoshis" db:"satoshis"`
// ExpiresAt is an optional param that can be passed to set an expiration
// date on an invoice, after which, payments will not be accepted.
ExpiresAt null.Time `json:"expiresAt" db:"expires_at"`
// PaymentReceivedAt will be set when this invoice has been paid and
// states when the payment was received in UTC time.
PaymentReceivedAt null.Time `json:"paymentReceivedAt" db:"payment_received_at"`
// RefundTo is an optional paymail address that can be used to refund the
// customer if required.
RefundTo null.String `json:"refundTo" db:"refund_to"`
// RefundedAt if this payment has been refunded, this date will be set
// to the UTC time of the refund.
RefundedAt null.Time `json:"refundedAt" db:"refunded_at"`
// State is the current status of the invoice.
State InvoiceState `json:"state" db:"state" enums:"pending,paid,refunded,deleted"`
// SPVRequired if true will mean this invoice requires a valid spvenvelope otherwise a rawTX will suffice.
SPVRequired bool `json:"-" db:"spv_required"`
MetaData
}
Invoice identifies a single payment request from this payd wallet, it states the amount, id and optional refund address. This indicate we are requesting n satoshis in payment.
type InvoiceArgs ¶
type InvoiceArgs struct {
InvoiceID string `param:"invoiceID" db:"invoice_id"`
}
InvoiceArgs contains argument/s to return a single invoice.
func (*InvoiceArgs) Validate ¶
func (i *InvoiceArgs) Validate() error
Validate will check that invoice arguments match expectations.
type InvoiceCreate ¶
type InvoiceCreate struct {
InvoiceID string `json:"-" db:"invoice_id"`
// Satoshis is the total amount this invoice is to pay.
Satoshis uint64 `json:"satoshis" db:"satoshis"`
// Reference is an identifier that can be used to link the
// payd invoice with an external system.
// MaxLength is 32 characters.
Reference null.String `json:"reference" db:"payment_reference"`
// Description is an optional text field that can have some further info
// like 'invoice for oranges'.
// MaxLength is 1024 characters.
Description null.String `json:"description" db:"description"`
// ExpiresAt is an optional param that can be passed to set an expiration
// date on an invoice, after which, payments will not be accepted.
ExpiresAt null.Time `json:"expiresAt" db:"expires_at"`
// SPVRequired if true will mean this invoice requires a valid spvenvelope otherwise a rawTX will suffice.
SPVRequired bool `json:"-" db:"spv_required"`
}
InvoiceCreate is used to create a new invoice.
func (InvoiceCreate) Validate ¶
func (i InvoiceCreate) Validate() error
Validate will check that InvoiceCreate params match expectations.
type InvoiceReader ¶
type InvoiceReader interface {
// Invoice will return an invoice that matches the provided args.
Invoice(ctx context.Context, args InvoiceArgs) (*Invoice, error)
// Invoices returns all currently stored invoices TODO: update to support search args
Invoices(ctx context.Context) ([]Invoice, error)
}
InvoiceReader defines a data store used to read invoice data.
type InvoiceReaderWriter ¶
type InvoiceReaderWriter interface {
InvoiceWriter
InvoiceReader
}
InvoiceReaderWriter can be implemented to support storing and retrieval of invoices.
type InvoiceService ¶
type InvoiceService interface {
Invoice(ctx context.Context, args InvoiceArgs) (*Invoice, error)
Invoices(ctx context.Context) ([]Invoice, error)
Create(ctx context.Context, req InvoiceCreate) (*Invoice, error)
Delete(ctx context.Context, args InvoiceArgs) error
}
InvoiceService defines a service for managing invoices.
type InvoiceState ¶
type InvoiceState string
InvoiceState enforces invoice states.
const ( StateInvoicePending InvoiceState = "pending" StateInvoicePaid InvoiceState = "paid" StateInvoiceRefunded InvoiceState = "refunded" StateInvoiceDeleted InvoiceState = "deleted" )
contains states that an invocie can have.
func (InvoiceState) String ¶
func (i InvoiceState) String() string
type InvoiceUpdateArgs ¶
type InvoiceUpdateArgs struct {
InvoiceID string
}
InvoiceUpdateArgs are used to identify the invoice to update.
type InvoiceUpdatePaid ¶
InvoiceUpdatePaid can be used to update an invoice after it has been created.
type InvoiceUpdateRefunded ¶
type InvoiceUpdateRefunded struct {
// RefundTo will set an invoice as refunded.
RefundTo null.String `db:"refund_to"`
// RefundedAt if this payment has been refunded, this date will be set
// to the UTC time of the refund.
RefundedAt null.Time `json:"refundedAt" db:"refunded_at"`
}
InvoiceUpdateRefunded can be used to update an invoice state to refunded.
type InvoiceWriter ¶
type InvoiceWriter interface {
// Create will persist a new Invoice in the data store.
InvoiceCreate(ctx context.Context, req InvoiceCreate) (*Invoice, error)
// Update will update an invoice matching the provided args with the requested changes.
InvoiceUpdate(ctx context.Context, args InvoiceUpdateArgs, req InvoiceUpdatePaid) (*Invoice, error)
// Delete will remove an invoice from the data store, depending on implementation this could
// be a hard or soft delete.
InvoiceDelete(ctx context.Context, args InvoiceArgs) error
}
InvoiceWriter defines a data store used to write invoice data.
type KeyArgs ¶
type KeyArgs struct {
// Name is the name of the key to return.
Name string `db:"name"`
}
KeyArgs defines all arguments required to get a key.
type MetaData ¶
type MetaData struct {
// CreatedAt is the UTC time the object was created.
CreatedAt time.Time `json:"createdAt" db:"created_at"`
// UpdatedAt is the UTC time the object was updated.
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
// DeletedAt is the date the object was removed.
DeletedAt null.Time `json:"deletedAt,omitempty" db:"deleted_at"`
}
MetaData contains common meta info for objects.
type Output ¶
type Output struct {
ID uint64 `json:"-" db:"destination_id"`
// LockingScript is the P2PKH locking script used.
LockingScript string `json:"script" db:"locking_script"`
Satoshis uint64 `json:"satoshis" db:"satoshis"`
// DerivationPath is the deterministic path for this destination.
DerivationPath string `json:"-" db:"derivation_path"`
// State will indicate if this destination is still waiting on a tx to fulfil it (pending)
// has been paid to in a tx (received) or has been deleted.
State string `json:"-" db:"state" enums:"pending,received,deleted"`
}
Output contains a single locking script and satoshi amount and can be used to construct transaction outputs.
type OwnerService ¶
OwnerService interfaces with owners.
type OwnerStore ¶
OwnerStore interfaces with an owner store.
type P2PCapabilityArgs ¶
P2PCapabilityArgs is used to retrieve information from a p2p server. https://bsvalias.org/02-02-capability-discovery.html
type P2POutputCreateArgs ¶
P2POutputCreateArgs is used to locate a `signer when sending a p2p payment.
type P2PPayment ¶
type P2PPayment struct {
Satoshis uint64
}
P2PPayment contains the amount of satoshis to send peer to peer.
type P2PTransaction ¶
type P2PTransaction struct {
TxHex string
Metadata P2PTransactionMetadata
}
P2PTransaction defines a peer to peer transaction.
type P2PTransactionArgs ¶
P2PTransactionArgs is used to get a transaction.
type P2PTransactionMetadata ¶
type P2PTransactionMetadata struct {
Note string // A human readable bit of information about the payment
PubKey string // Public key to validate the signature (if signature is given)
Sender string // The paymail of the person that originated the transaction
Signature string
}
P2PTransactionMetadata contains potentially optional metadata that can be sent along with a p2p payment.
type PaymailReader ¶
type PaymailReader interface {
Capability(ctx context.Context, args P2PCapabilityArgs) (string, error)
}
PaymailReader reads paymail information from a datastore.
type PaymailReaderWriter ¶
type PaymailReaderWriter interface {
PaymailReader
PaymailWriter
}
PaymailReaderWriter combines the reader and writer interfaces.
type PaymailWriter ¶
type PaymailWriter interface {
OutputsCreate(ctx context.Context, args P2POutputCreateArgs, req P2PPayment) ([]*bt.Output, error)
}
PaymailWriter writes to a paymail datastore.
type PaymentCreate ¶
type PaymentCreate struct {
InvoiceID string `json:"-" param:"invoiceID"`
SPVEnvelope *spv.Envelope `json:"spvEnvelope"`
RawTX null.String `json:"rawTx"`
// ProofCallbacks allow support of multiple callbacks for merkle proofs
// this will help support multisig and also transmitting proofs to the sender wallet.
// "proofCallbacks": {
// "http://domain.com/proofs": {
// "token": "abc123"
// }
// }
ProofCallbacks map[string]ProofCallback `json:"proofCallbacks"`
}
PaymentCreate is submitted to validate and add a payment to the wallet.
func (PaymentCreate) Validate ¶
func (p PaymentCreate) Validate(spvRequired bool) error
Validate will ensure the users request is correct.
type PaymentsService ¶
type PaymentsService interface {
// PaymentCreate will validate a new payment.
PaymentCreate(ctx context.Context, req PaymentCreate) error
}
PaymentsService is used for handling payments.
type PrivateKey ¶
type PrivateKey struct {
// Name of the private key.
Name string `db:"name"`
// Xprv is the private key.
Xprv string `db:"xprv"`
// CreatedAt is the date/time when the key was stored.
CreatedAt time.Time `db:"createdAt"`
}
PrivateKey describes a named private key.
type PrivateKeyReader ¶
type PrivateKeyReader interface {
// PrivateKey can be used to return an existing private key.
PrivateKey(ctx context.Context, args KeyArgs) (*PrivateKey, error)
}
PrivateKeyReader reads private info from a data store.
type PrivateKeyReaderWriter ¶
type PrivateKeyReaderWriter interface {
PrivateKeyReader
PrivateKeyWriter
}
PrivateKeyReaderWriter describes a data store that can be implemented to get and store private keys.
type PrivateKeyService ¶
type PrivateKeyService interface {
// Create will create a new private key if it doesn't exist already.
Create(ctx context.Context, keyName string) error
// PrivateKey will return a private key.
PrivateKey(ctx context.Context, keyName string) (*bip32.ExtendedKey, error)
}
PrivateKeyService can be implemented to get and create PrivateKeys.
type PrivateKeyWriter ¶
type PrivateKeyWriter interface {
// PrivateKeyCreate will add a new private key to the data store.
PrivateKeyCreate(ctx context.Context, req PrivateKey) (*PrivateKey, error)
}
PrivateKeyWriter will add private key to the datastore.
type ProofCallback ¶
type ProofCallback struct {
// Token to use for authentication when sending the proof to the destination. Optional.
Token string
}
ProofCallback contains information relating to a merkleproof callback.
type ProofCallbackArgs ¶
type ProofCallbackArgs struct {
InvoiceID string `db:"invoice_id"`
}
ProofCallbackArgs are used to identify proofs for an invoice.
type ProofCallbackWriter ¶
type ProofCallbackWriter interface {
// ProofCallBacksCreate can be implemented to store merkle proof callback urls for an invoice.
ProofCallBacksCreate(ctx context.Context, args ProofCallbackArgs, callbacks map[string]ProofCallback) error
}
ProofCallbackWriter can be implemented to support writing proof callbacks.
type ProofCreateArgs ¶
type ProofCreateArgs struct {
// TxID will be used to validate the proof envelope.
TxID string `json:"txId" param:"txid"`
}
ProofCreateArgs are used to create a proof.
type ProofWrapper ¶
type ProofWrapper struct {
CallbackPayload *bc.MerkleProof `json:"callbackPayload"`
BlockHash string `json:"blockHash"`
BlockHeight uint32 `json:"blockHeight"`
CallbackTxID string `json:"callbackTxID"`
CallbackReason string `json:"callbackReason"`
}
ProofWrapper represents a mapi callback payload for a merkleproof. mAPI returns proofs in a JSONEnvelope with a payload. This represents the Payload format which contains a parent object with tx meta and a nested object which is the TSC format merkleProof.
func (ProofWrapper) Validate ¶
func (p ProofWrapper) Validate(args ProofCreateArgs) error
Validate will ensure the ProofWrapper is valid.
type ProofsService ¶
type ProofsService interface {
// Create will store a JSONEnvelope that contains a merkleproof. The envelope should
// be validated to not be tampered with and the Envelope should be opened to check the payload
// is indeed a MerkleProof.
Create(ctx context.Context, args ProofCreateArgs, req envelope.JSONEnvelope) error
}
ProofsService enforces business rules and validation when handling merkle proofs.
type ProofsWriter ¶
type ProofsWriter interface {
// ProofCreate can be used to persist a merkle proof in TSC format.
ProofCreate(ctx context.Context, req ProofWrapper) error
}
ProofsWriter is used to persist a proof to a data store.
type SpendTxo ¶
SpendTxo can be used to update a transaction out with information on when it was spent and by what transaction.
type SpendTxoArgs ¶
type SpendTxoArgs struct {
Outpoint string
}
SpendTxoArgs are used to identify the transaction output to mark as spent.
type Transacter ¶
type Transacter interface {
WithTx(ctx context.Context) context.Context
Commit(ctx context.Context) error
Rollback(ctx context.Context) error
}
Transacter can be implemented to provide context based transactions.
type Transaction ¶
type Transaction struct {
PaymentID string `db:"paymentid"`
TxID string `db:"tx_id"`
TxHex string `db:"tx_hex"`
CreatedAt time.Time `db:"created_at"`
Outputs []Txo `db:"-"`
State string `enums:"pending,broadcast,failed,deleted"`
}
Transaction defines a single transaction.
type TransactionArgs ¶
type TransactionArgs struct {
TxID string `db:"tx_id"`
}
TransactionArgs are used to identify a specific tx.
type TransactionCreate ¶
type TransactionCreate struct {
InvoiceID string `db:"invoice_id"`
TxID string `db:"tx_id"`
TxHex string `db:"tx_hex"`
Outputs []*TxoCreate `db:"-"`
}
TransactionCreate is used to insert a tx into the data store. To save calls, Txos can be included to also add in the same transaction.
type TransactionStateUpdate ¶
type TransactionStateUpdate struct {
State TxState `db:"state"`
}
TransactionStateUpdate contains information to update a tx.
type TransactionWriter ¶
type TransactionWriter interface {
TransactionCreate(ctx context.Context, req TransactionCreate) error
// TransactionUpdateState can be used to change a tx state (failed, broadcast).
TransactionUpdateState(ctx context.Context, args TransactionArgs, req TransactionStateUpdate) error
}
TransactionWriter will add and update transaction data.
type Txo ¶
type Txo struct {
Outpoint string `db:"outpoint"`
TxID string `db:"tx_id"`
Vout int `db:"vout"`
KeyName null.String `db:"key_name"`
DerivationPath null.String `db:"derivation_path"`
LockingScript string `db:"locking_script"`
Satoshis uint64 `db:"satoshis"`
SpentAt null.Time `db:"spent_at"`
SpendingTxID null.String `db:"spending_txid"`
CreatedAt time.Time `db:"created_at"`
ModifiedAt time.Time `db:"updated_at"`
}
Txo defines a single txo and can be returned from the data store.
type TxoCreate ¶
type TxoCreate struct {
Outpoint string `db:"outpoint"`
DestinationID uint64 `db:"destination_id"`
TxID string `db:"tx_id"`
Vout uint64 `db:"vout"`
}
TxoCreate will add utxos to our data store linked by a destinationId. These are added when a user submit a tx to pay an invoice.
type TxoWriter ¶
type TxoWriter interface {
// TxosCreate will add an array of txos to a data store.
TxosCreate(ctx context.Context, req []*TxoCreate) error
}
TxoWriter is used to add transaction information to a data store.
type User ¶
type User struct {
ID uint64 `json:"id" db:"user_id"`
Name string `json:"name" db:"name"`
Avatar string `json:"avatar" db:"avatar_url"`
Email string `json:"email" db:"email"`
Address string `json:"address" db:"address"`
PhoneNumber string `json:"phoneNumber" db:"phone_number"`
ExtendedData map[string]string `json:"extendedData"`
}
User information on wallet users.