Documentation ¶
Overview ¶
Package pingpong implements the off-chain communications of the payment protocol. TODO: The package should get renamed to payments once we're done with keeping the old payment implementation for backwards compatibility.
Index ¶
- Constants
- Variables
- func CalculatePaymentAmount(timePassed time.Duration, bytesTransferred DataTransferred, price market.Price) *big.Int
- func ExchangeFactoryFunc(keystore hashSigner, signer identity.SignerFactory, ...) ...
- func InvoiceFactoryCreator(channel p2p.Channel, ...) ...
- func NewHermesPromiseSettler(transactor transactor, promiseStorage promiseStorage, paySettler paySettler, ...) *hermesPromiseSettler
- type ConsumerBalance
- type ConsumerBalanceTracker
- func (cbt *ConsumerBalanceTracker) ForceBalanceUpdate(chainID int64, id identity.Identity) *big.Int
- func (cbt *ConsumerBalanceTracker) ForceBalanceUpdateCached(chainID int64, id identity.Identity) *big.Int
- func (cbt *ConsumerBalanceTracker) GetBalance(chainID int64, id identity.Identity) *big.Int
- func (cbt *ConsumerBalanceTracker) NeedsForceSync(chainID int64, id identity.Identity) bool
- func (cbt *ConsumerBalanceTracker) Subscribe(bus eventbus.Subscriber) error
- type ConsumerBalanceTrackerConfig
- type ConsumerTotalElement
- type ConsumerTotalsStorage
- func (cts *ConsumerTotalsStorage) Add(chainID int64, id identity.Identity, hermesID common.Address, amount *big.Int) error
- func (cts *ConsumerTotalsStorage) Get(chainID int64, id identity.Identity, hermesID common.Address) (*big.Int, error)
- func (cts *ConsumerTotalsStorage) Store(chainID int64, id identity.Identity, hermesID common.Address, amount *big.Int) error
- type DataTransferred
- type ExchangeRequest
- type ExchangeSender
- type HermesCaller
- func (ac *HermesCaller) GetConsumerData(chainID int64, id string, cacheTime time.Duration) (HermesUserInfo, error)
- func (ac *HermesCaller) GetProviderData(chainID int64, id string) (HermesUserInfo, error)
- func (ac *HermesCaller) IsIdentityOffchain(chainID int64, id string) (bool, error)
- func (ac *HermesCaller) PayAndSettle(rp RequestPromise) (crypto.Promise, error)
- func (ac *HermesCaller) ProviderPromiseAmountUnsafe(chainID int64, id string) (*big.Int, error)
- func (ac *HermesCaller) RefreshLatestProviderPromise(chainID int64, id string, hashlock, recoveryData []byte, ...) (crypto.Promise, error)
- func (ac *HermesCaller) RequestPromise(rp RequestPromise) (crypto.Promise, error)
- func (ac *HermesCaller) RevealR(r, provider string, agreementID *big.Int) error
- func (ac *HermesCaller) SyncProviderPromise(promise crypto.Promise, signer identity.Signer) error
- func (ac *HermesCaller) UpdatePromiseFee(promise crypto.Promise, newFee *big.Int) (crypto.Promise, error)
- type HermesCallerFactory
- type HermesChannel
- type HermesChannelRepository
- func (hcr *HermesChannelRepository) Fetch(chainID int64, id identity.Identity, hermesID common.Address) (HermesChannel, error)
- func (hcr *HermesChannelRepository) Get(chainID int64, id identity.Identity, hermesID common.Address) (HermesChannel, bool)
- func (hcr *HermesChannelRepository) GetEarnings(chainID int64, id identity.Identity) pingEvent.Earnings
- func (hcr *HermesChannelRepository) GetEarningsDetailed(chainID int64, id identity.Identity) *pingEvent.EarningsDetailed
- func (hcr *HermesChannelRepository) List(chainID int64) []HermesChannel
- func (hcr *HermesChannelRepository) Subscribe(bus eventbus.Subscriber) error
- type HermesErrorResponse
- type HermesHTTPRequester
- type HermesPromise
- type HermesPromiseFilter
- type HermesPromiseHandler
- func (aph *HermesPromiseHandler) PayAndSettle(r []byte, em crypto.ExchangeMessage, providerID identity.Identity, ...) <-chan error
- func (aph *HermesPromiseHandler) RequestPromise(r []byte, em crypto.ExchangeMessage, providerID identity.Identity, ...) <-chan error
- func (aph *HermesPromiseHandler) Subscribe(bus eventbus.Subscriber) error
- type HermesPromiseHandlerDeps
- type HermesPromiseSettler
- type HermesPromiseSettlerConfig
- type HermesPromiseStorage
- func (aps *HermesPromiseStorage) Delete(promise HermesPromise) error
- func (aps *HermesPromiseStorage) Get(chainID int64, channelID string) (HermesPromise, error)
- func (aps *HermesPromiseStorage) List(filter HermesPromiseFilter) ([]HermesPromise, error)
- func (aps *HermesPromiseStorage) Store(promise HermesPromise) error
- type HermesStatus
- type HermesStatusChecker
- type HermesURLGetter
- type HermesUserInfo
- type HistoryType
- type InvoicePayer
- type InvoicePayerDeps
- type InvoiceRequest
- type InvoiceSender
- type InvoiceStorage
- func (is *InvoiceStorage) GetInvoice(bucket string, key string) (crypto.Invoice, error)
- func (is *InvoiceStorage) GetR(providerID identity.Identity, agreementID *big.Int) (string, error)
- func (is *InvoiceStorage) StoreInvoice(bucket string, key string, invoice crypto.Invoice) error
- func (is *InvoiceStorage) StoreR(providerID identity.Identity, agreementID *big.Int, r string) error
- type InvoiceTracker
- type InvoiceTrackerDeps
- type LatestPromise
- type PeerExchangeMessageSender
- type PeerInvoiceSender
- type PollConfig
- type Pricer
- type ProviderInvoiceStorage
- func (pis *ProviderInvoiceStorage) Get(providerIdentity, consumerIdentity identity.Identity) (crypto.Invoice, error)
- func (pis *ProviderInvoiceStorage) GetR(providerID identity.Identity, agreementID *big.Int) (string, error)
- func (pis *ProviderInvoiceStorage) Store(providerIdentity, consumerIdentity identity.Identity, invoice crypto.Invoice) error
- func (pis *ProviderInvoiceStorage) StoreR(providerID identity.Identity, agreementID *big.Int, r string) error
- type RequestPromise
- type RevealObject
- type RevealSuccess
- type SetPromiseFeeRequest
- type SettlementHistoryEntry
- type SettlementHistoryFilter
- type SettlementHistoryStorage
Constants ¶
const ( // PromiseWaitTimeout is the time that the provider waits for the promise to arrive PromiseWaitTimeout = time.Second * 50 // InvoiceSendPeriod is how often the provider will send invoice messages to the consumer InvoiceSendPeriod = time.Second * 60 // DefaultHermesFailureCount defines how many times we're allowed to fail to reach hermes in a row before announcing the failure. DefaultHermesFailureCount uint64 = 10 )
Variables ¶
var ErrAttemptToOverwrite = errors.New("attempted to overwrite a promise with and equal or lower value")
ErrAttemptToOverwrite occurs when a promise with lower value is attempted to be overwritten on top of an existing promise.
var ErrConsumerNotRegistered = errors.New("consumer not registered")
ErrConsumerNotRegistered represents the error that the consumer is not registered
var ErrConsumerPromiseValidationFailed = errors.New("consumer failed to issue promise for the correct amount")
ErrConsumerPromiseValidationFailed represents an error where consumer tries to cheat us with incorrect promises.
var ErrConsumerUnregistered = errors.New("consumer unregistered")
ErrConsumerUnregistered indicates that the consumer is not registered.
var ErrExchangeValidationFailed = errors.New("exchange validation failed")
ErrExchangeValidationFailed indicates that there was an error with the exchange signature.
var ErrExchangeWaitTimeout = errors.New("did not get a new exchange message")
ErrExchangeWaitTimeout indicates that we did not get an exchange message in time.
var ErrHermesFeeTooLarge = errors.New("hermes fee exceeds predefined limits")
ErrHermesFeeTooLarge indicates that we do not allow hermess with such high fees
var ErrHermesHashlockMissmatch = errors.New("hashlock missmatch")
ErrHermesHashlockMissmatch occurs when an expected hashlock does not match the one sent by provider.
var ErrHermesInactive = errors.New("hermes is not active")
ErrHermesInactive indicates that the chosen hermes is not active
var ErrHermesInternal = errors.New("internal error")
ErrHermesInternal represents an internal error.
var ErrHermesInvalidSignature = errors.New("invalid signature")
ErrHermesInvalidSignature indicates that an invalid signature was sent.
var ErrHermesMalformedJSON = errors.New("malformed json")
ErrHermesMalformedJSON indicates that the provider has sent an invalid json in the request.
var ErrHermesNoPreviousPromise = errors.New("no previous promise found")
ErrHermesNoPreviousPromise indicates that we have no previous knowledge of a promise for the provider.
var ErrHermesNotFound = errors.New("resource not found")
ErrHermesNotFound occurs when a requested resource is not found
var ErrHermesOverspend = errors.New("consumer does not have enough balance and is overspending")
ErrHermesOverspend indicates that the consumer has overspent his balance.
var ErrHermesPaymentValueTooLow = errors.New("payment value too low")
ErrHermesPaymentValueTooLow indicates that the agreement total has decreased as opposed to increasing.
var ErrHermesPreviousRNotRevealed = errors.New("previous R not revealed")
ErrHermesPreviousRNotRevealed represents that a previous R has not been revealed yet. No actions will be possible before the R is revealed.
var ErrHermesPromiseValueTooLow = errors.New("promise value too low")
ErrHermesPromiseValueTooLow represents an error where the consumer sent a promise with a decreasing total.
var ErrHermesProviderBalanceExhausted = errors.New("provider balance exhausted, please rebalance your channel")
ErrHermesProviderBalanceExhausted indicates that the provider has run out of stake and a rebalance is needed.
var ErrInvalidPreviuosLatestPromise = errors.New("invalid previuos latest promise, impossible to issue new one")
ErrInvalidPreviuosLatestPromise represents an error where historical promise data is invalid resulting in a non functional provider or consumner.
var ErrInvoiceExpired = errors.New("invoice expired")
ErrInvoiceExpired shows that the given invoice has already expired
var ErrInvoiceMissmatch = errors.New("invoice mismatch")
ErrInvoiceMissmatch represents an error that occurs when invoices do not match.
var ErrInvoiceSendMaxFailCountReached = errors.New("did not sent a new exchange message")
ErrInvoiceSendMaxFailCountReached indicates that we did not sent an exchange message in time.
var ErrNeedsRRecovery = errors.New("r recovery required")
ErrNeedsRRecovery indicates that we need to recover R.
var ErrNotFound = errors.New("entry does not exist")
ErrNotFound represents an error that indicates that there's no such invoice.
var ErrNothingToSettle = errors.New("nothing to settle for the given provider")
ErrNothingToSettle indicates that there is nothing to settle.
var ErrProviderOvercharge = errors.New("provider is overcharging")
ErrProviderOvercharge represents an issue where the provider is trying to overcharge us.
var ErrSettleTimeout = errors.New("settle timeout")
ErrSettleTimeout indicates that the settlement has timed out
var ErrTooManyRequests = errors.New("too many simultaneous requests")
ErrTooManyRequests occurs when we call the reveal R or request promise errors asynchronously at the same time.
var ErrUnknownChain = errors.New("unknown chain")
ErrUnknownChain is returned when an operation cannot be completed because the given chain is unknown or isn't configured.
var ErrWrongProvider = errors.New("wrong provider supplied")
ErrWrongProvider represents an issue where the wrong provider is supplied.
Functions ¶
func CalculatePaymentAmount ¶
func CalculatePaymentAmount(timePassed time.Duration, bytesTransferred DataTransferred, price market.Price) *big.Int
CalculatePaymentAmount calculates the required payment amount.
func ExchangeFactoryFunc ¶
func ExchangeFactoryFunc( keystore hashSigner, signer identity.SignerFactory, totalStorage consumerTotalsStorage, addressProvider addressProvider, eventBus eventbus.EventBus, dataLeewayMegabytes uint64, ) func(senderUUID string, channel p2p.Channel, consumer, provider identity.Identity, hermes common.Address, proposal proposal.PricedServiceProposal, price market.Price) (connection.PaymentIssuer, error)
ExchangeFactoryFunc returns a exchange factory.
func InvoiceFactoryCreator ¶
func InvoiceFactoryCreator( channel p2p.Channel, balanceSendPeriod, limitBalanceSendPeriod, promiseTimeout time.Duration, invoiceStorage providerInvoiceStorage, maxHermesFailureCount uint64, maxAllowedHermesFee uint16, maxUnpaidInvoiceValue, limitUnpaidInvoiceValue *big.Int, hermesStatusChecker hermesStatusChecker, eventBus eventbus.EventBus, promiseHandler promiseHandler, addressProvider addressProvider, observer observerApi, ) func(identity.Identity, identity.Identity, int64, common.Address, string, chan crypto.ExchangeMessage, market.Price) (service.PaymentEngine, error)
InvoiceFactoryCreator returns a payment engine factory.
func NewHermesPromiseSettler ¶
func NewHermesPromiseSettler(transactor transactor, promiseStorage promiseStorage, paySettler paySettler, addressProvider addressProvider, hermesCallerFactory HermesCallerFactory, hermesURLGetter hermesURLGetter, channelProvider hermesChannelProvider, providerChannelStatusProvider providerChannelStatusProvider, registrationStatusProvider registrationStatusProvider, ks ks, settlementHistoryStorage settlementHistoryStorage, publisher eventbus.Publisher, observerApi observerApi, beneficiaryLocalStorage beneficiary.BeneficiaryStorage, config HermesPromiseSettlerConfig) *hermesPromiseSettler
NewHermesPromiseSettler creates a new instance of hermes promise settler.
Types ¶
type ConsumerBalance ¶
type ConsumerBalance struct { BCBalance *big.Int BCSettled *big.Int GrandTotalPromised *big.Int // IsOffchain is an optional indicator which marks an offchain balanace. // Offchain balances receive no updates on the blockchain and their // actual remaining balance should be retreived from hermes. IsOffchain bool LastOffchainSync time.Time }
ConsumerBalance represents the consumer balance
func (ConsumerBalance) GetBalance ¶
func (cb ConsumerBalance) GetBalance() *big.Int
GetBalance returns the current balance
func (ConsumerBalance) OffchainNeedsSync ¶
func (cb ConsumerBalance) OffchainNeedsSync() bool
OffchainNeedsSync returns true if balance is offchain and should be synced.
type ConsumerBalanceTracker ¶
type ConsumerBalanceTracker struct {
// contains filtered or unexported fields
}
ConsumerBalanceTracker keeps track of consumer balances. TODO: this needs to take into account the saved state.
func NewConsumerBalanceTracker ¶
func NewConsumerBalanceTracker( publisher eventbus.EventBus, consumerBalanceChecker consumerBalanceChecker, consumerGrandTotalsStorage consumerTotalsStorage, consumerInfoGetter consumerInfoGetter, transactorRegistrationStatusProvider transactorRegistrationStatusProvider, registry registrationStatusProvider, addressProvider addressProvider, blockchainInfoProvider blockchainInfoProvider, cfg ConsumerBalanceTrackerConfig, ) *ConsumerBalanceTracker
NewConsumerBalanceTracker creates a new instance
func (*ConsumerBalanceTracker) ForceBalanceUpdate ¶
ForceBalanceUpdate forces a balance update and returns the updated balance
func (*ConsumerBalanceTracker) ForceBalanceUpdateCached ¶
func (cbt *ConsumerBalanceTracker) ForceBalanceUpdateCached(chainID int64, id identity.Identity) *big.Int
ForceBalanceUpdateCached forces a balance update for the given identity only if the last call to this func was done no sooner than a minute ago.
func (*ConsumerBalanceTracker) GetBalance ¶
GetBalance gets the current balance for given identity
func (*ConsumerBalanceTracker) NeedsForceSync ¶
func (cbt *ConsumerBalanceTracker) NeedsForceSync(chainID int64, id identity.Identity) bool
NeedsForceSync returns true if balance needs to be force synced.
func (*ConsumerBalanceTracker) Subscribe ¶
func (cbt *ConsumerBalanceTracker) Subscribe(bus eventbus.Subscriber) error
Subscribe subscribes the consumer balance tracker to relevant events
type ConsumerBalanceTrackerConfig ¶
type ConsumerBalanceTrackerConfig struct { FastSync PollConfig LongSync PollConfig }
ConsumerBalanceTrackerConfig represents the consumer balance tracker configuration.
type ConsumerTotalElement ¶
type ConsumerTotalElement struct {
// contains filtered or unexported fields
}
ConsumerTotalElement stores a grand total promised amount for a single identity, hermes and chain id
type ConsumerTotalsStorage ¶
type ConsumerTotalsStorage struct {
// contains filtered or unexported fields
}
ConsumerTotalsStorage allows to store total promised amounts for each channel.
func NewConsumerTotalsStorage ¶
func NewConsumerTotalsStorage(bus eventbus.Publisher) *ConsumerTotalsStorage
NewConsumerTotalsStorage creates a new instance of consumer totals storage.
func (*ConsumerTotalsStorage) Add ¶
func (cts *ConsumerTotalsStorage) Add(chainID int64, id identity.Identity, hermesID common.Address, amount *big.Int) error
Add adds the given amount as promised for the given channel.
type DataTransferred ¶
type DataTransferred struct {
Up, Down uint64
}
DataTransferred represents the data transferred in a session.
type ExchangeRequest ¶
type ExchangeRequest struct {
Message crypto.ExchangeMessage `json:"exchangeMessage"`
}
ExchangeRequest structure represents message from service consumer to send a an exchange message.
type ExchangeSender ¶
type ExchangeSender struct {
// contains filtered or unexported fields
}
ExchangeSender is responsible for sending the exchange messages.
func NewExchangeSender ¶
func NewExchangeSender(ch p2p.ChannelSender) *ExchangeSender
NewExchangeSender returns a new instance of exchange message sender.
func (*ExchangeSender) Send ¶
func (es *ExchangeSender) Send(em crypto.ExchangeMessage) error
Send sends the given exchange message.
type HermesCaller ¶
type HermesCaller struct {
// contains filtered or unexported fields
}
HermesCaller represents the http caller for hermes.
func NewHermesCaller ¶
func NewHermesCaller(transport *requests.HTTPClient, hermesBaseURI string) *HermesCaller
NewHermesCaller returns a new instance of hermes caller.
func (*HermesCaller) GetConsumerData ¶
func (ac *HermesCaller) GetConsumerData(chainID int64, id string, cacheTime time.Duration) (HermesUserInfo, error)
GetConsumerData gets consumer data from hermes, use a negative cacheTime to force update
func (*HermesCaller) GetProviderData ¶
func (ac *HermesCaller) GetProviderData(chainID int64, id string) (HermesUserInfo, error)
GetProviderData gets provider data from hermes
func (*HermesCaller) IsIdentityOffchain ¶
func (ac *HermesCaller) IsIdentityOffchain(chainID int64, id string) (bool, error)
IsIdentityOffchain returns true if identity is considered offchain in hermes.
func (*HermesCaller) PayAndSettle ¶
func (ac *HermesCaller) PayAndSettle(rp RequestPromise) (crypto.Promise, error)
PayAndSettle requests a promise from hermes.
func (*HermesCaller) ProviderPromiseAmountUnsafe ¶
ProviderPromiseAmountUnsafe returns the provider promise amount. If can also return `nil` as the result if no promise exists.
func (*HermesCaller) RefreshLatestProviderPromise ¶
func (ac *HermesCaller) RefreshLatestProviderPromise(chainID int64, id string, hashlock, recoveryData []byte, signer identity.Signer) (crypto.Promise, error)
RefreshLatestProviderPromise reissue latest promise with a new hashlock.
func (*HermesCaller) RequestPromise ¶
func (ac *HermesCaller) RequestPromise(rp RequestPromise) (crypto.Promise, error)
RequestPromise requests a promise from hermes.
func (*HermesCaller) RevealR ¶
func (ac *HermesCaller) RevealR(r, provider string, agreementID *big.Int) error
RevealR reveals hashlock key 'r' from 'provider' to the hermes for the agreement identified by 'agreementID'.
func (*HermesCaller) SyncProviderPromise ¶
SyncProviderPromise syncs provider promise.
func (*HermesCaller) UpdatePromiseFee ¶
func (ac *HermesCaller) UpdatePromiseFee(promise crypto.Promise, newFee *big.Int) (crypto.Promise, error)
UpdatePromiseFee calls hermes to update its promise with new fee.
type HermesCallerFactory ¶
type HermesCallerFactory func(url string) HermesHTTPRequester
HermesCallerFactory represents Hermes caller factory.
type HermesChannel ¶
type HermesChannel struct { ChannelID string Identity identity.Identity HermesID common.Address Channel client.ProviderChannel Beneficiary common.Address // contains filtered or unexported fields }
HermesChannel represents opened payment channel between identity and hermes.
func NewHermesChannel ¶
func NewHermesChannel(channelID string, id identity.Identity, hermesID common.Address, channel client.ProviderChannel, promise HermesPromise, beneficiary common.Address) HermesChannel
NewHermesChannel creates HermesChannel model.
func (HermesChannel) Copy ¶
func (hc HermesChannel) Copy() HermesChannel
Copy returns a deep copy of channel
func (HermesChannel) LifetimeBalance ¶
func (hc HermesChannel) LifetimeBalance() *big.Int
LifetimeBalance returns earnings of all history.
func (HermesChannel) UnsettledBalance ¶
func (hc HermesChannel) UnsettledBalance() *big.Int
UnsettledBalance returns current unsettled earnings.
type HermesChannelRepository ¶
type HermesChannelRepository struct {
// contains filtered or unexported fields
}
HermesChannelRepository is fetches HermesChannel models from blockchain.
func NewHermesChannelRepository ¶
func NewHermesChannelRepository(promiseProvider promiseProvider, channelProvider channelProvider, publisher eventbus.Publisher, bprovider beneficiaryProvider, hermesCaller hermesCaller, addressProvider addressProvider, signer identity.SignerFactory, encryption encryption) *HermesChannelRepository
NewHermesChannelRepository returns a new instance of HermesChannelRepository.
func (*HermesChannelRepository) Fetch ¶
func (hcr *HermesChannelRepository) Fetch(chainID int64, id identity.Identity, hermesID common.Address) (HermesChannel, error)
Fetch force identity's channel update and returns updated channel.
func (*HermesChannelRepository) Get ¶
func (hcr *HermesChannelRepository) Get(chainID int64, id identity.Identity, hermesID common.Address) (HermesChannel, bool)
Get retrieves identity's channel with given hermes.
func (*HermesChannelRepository) GetEarnings ¶
func (hcr *HermesChannelRepository) GetEarnings(chainID int64, id identity.Identity) pingEvent.Earnings
GetEarnings returns all channels earnings for given identity combined from all hermeses possible
func (*HermesChannelRepository) GetEarningsDetailed ¶
func (hcr *HermesChannelRepository) GetEarningsDetailed(chainID int64, id identity.Identity) *pingEvent.EarningsDetailed
GetEarningsDetailed returns earnings in a detailed format grouping them by hermes ID but also providing totals.
func (*HermesChannelRepository) List ¶
func (hcr *HermesChannelRepository) List(chainID int64) []HermesChannel
List retrieves identity's channels with all known hermeses.
func (*HermesChannelRepository) Subscribe ¶
func (hcr *HermesChannelRepository) Subscribe(bus eventbus.Subscriber) error
Subscribe subscribes to the appropriate events.
type HermesErrorResponse ¶
type HermesErrorResponse struct { CausedBy string `json:"cause"` ErrorMessage string `json:"message"` ErrorData string `json:"data"` // contains filtered or unexported fields }
HermesErrorResponse represents the errors that hermes returns
func (HermesErrorResponse) Cause ¶
func (aer HermesErrorResponse) Cause() error
Cause returns the associated cause
func (HermesErrorResponse) Data ¶
func (aer HermesErrorResponse) Data() string
Data returns the associated data
func (HermesErrorResponse) Error ¶
func (aer HermesErrorResponse) Error() string
Error returns the associated error
func (*HermesErrorResponse) UnmarshalJSON ¶
func (aer *HermesErrorResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals given data to HermesErrorResponse
func (HermesErrorResponse) Unwrap ¶
func (aer HermesErrorResponse) Unwrap() error
Unwrap unwraps the associated error
type HermesHTTPRequester ¶
type HermesHTTPRequester interface { PayAndSettle(rp RequestPromise) (crypto.Promise, error) RequestPromise(rp RequestPromise) (crypto.Promise, error) RevealR(r string, provider string, agreementID *big.Int) error UpdatePromiseFee(promise crypto.Promise, newFee *big.Int) (crypto.Promise, error) GetConsumerData(chainID int64, id string, cacheTime time.Duration) (HermesUserInfo, error) GetProviderData(chainID int64, id string) (HermesUserInfo, error) SyncProviderPromise(promise crypto.Promise, signer identity.Signer) error }
HermesHTTPRequester represents HTTP requests to Hermes.
type HermesPromise ¶
type HermesPromise struct { ChannelID string Identity identity.Identity HermesID common.Address Promise crypto.Promise R string Revealed bool AgreementID *big.Int }
HermesPromise represents a promise we store from the hermes
type HermesPromiseFilter ¶
type HermesPromiseFilter struct { Identity *identity.Identity HermesID *common.Address ChainID int64 }
HermesPromiseFilter defines all flags for filtering in promises in storage.
type HermesPromiseHandler ¶
type HermesPromiseHandler struct {
// contains filtered or unexported fields
}
HermesPromiseHandler handles the hermes promises for ongoing sessions.
func NewHermesPromiseHandler ¶
func NewHermesPromiseHandler(deps HermesPromiseHandlerDeps) *HermesPromiseHandler
NewHermesPromiseHandler returns a new instance of hermes promise handler.
func (*HermesPromiseHandler) PayAndSettle ¶
func (aph *HermesPromiseHandler) PayAndSettle(r []byte, em crypto.ExchangeMessage, providerID identity.Identity, sessionID string) <-chan error
PayAndSettle adds the request to the queue.
func (*HermesPromiseHandler) RequestPromise ¶
func (aph *HermesPromiseHandler) RequestPromise(r []byte, em crypto.ExchangeMessage, providerID identity.Identity, sessionID string) <-chan error
RequestPromise adds the request to the queue.
func (*HermesPromiseHandler) Subscribe ¶
func (aph *HermesPromiseHandler) Subscribe(bus eventbus.Subscriber) error
Subscribe subscribes HermesPromiseHandler to relevant events.
type HermesPromiseHandlerDeps ¶
type HermesPromiseHandlerDeps struct { HermesPromiseStorage hermesPromiseStorage FeeProvider feeProvider Encryption encryption EventBus eventbus.Publisher HermesURLGetter hermesURLGetter HermesCallerFactory HermesCallerFactory Signer identity.SignerFactory Chains []int64 }
HermesPromiseHandlerDeps represents the HermesPromiseHandler dependencies.
type HermesPromiseSettler ¶
type HermesPromiseSettler interface { ForceSettle(chainID int64, providerID identity.Identity, hermesID ...common.Address) error ForceSettleAsync(chainID int64, providerID identity.Identity, hermesID ...common.Address) error SettleWithBeneficiary(chainID int64, providerID identity.Identity, beneficiary common.Address, hermeses []common.Address) error SettleIntoStake(chainID int64, providerID identity.Identity, hermesID ...common.Address) error GetHermesFee(chainID int64, hermesID common.Address) (uint16, error) Withdraw(fromChainID int64, toChainID int64, providerID identity.Identity, hermesID, beneficiary common.Address, amount *big.Int) error CheckLatestWithdrawal(chainID int64, providerID identity.Identity, hermesID common.Address) (*big.Int, string, error) RetryWithdrawLatest(chainID int64, amountToWithdraw *big.Int, chid string, beneficiary common.Address, providerID identity.Identity) error }
HermesPromiseSettler is responsible for settling the hermes promises.
type HermesPromiseSettlerConfig ¶
type HermesPromiseSettlerConfig struct { MaxFeeThreshold float64 MinAutoSettleAmount float64 MaxUnSettledAmount float64 L1ChainID int64 L2ChainID int64 SettlementCheckInterval time.Duration SettlementCheckTimeout time.Duration BalanceThreshold float64 }
HermesPromiseSettlerConfig configures the hermes promise settler accordingly.
type HermesPromiseStorage ¶
type HermesPromiseStorage struct {
// contains filtered or unexported fields
}
HermesPromiseStorage allows for storing of hermes promises.
func NewHermesPromiseStorage ¶
func NewHermesPromiseStorage(bolt *boltdb.Bolt) *HermesPromiseStorage
NewHermesPromiseStorage returns a new instance of the hermes promise storage.
func (*HermesPromiseStorage) Delete ¶
func (aps *HermesPromiseStorage) Delete(promise HermesPromise) error
Delete deletes the given hermes promise.
func (*HermesPromiseStorage) Get ¶
func (aps *HermesPromiseStorage) Get(chainID int64, channelID string) (HermesPromise, error)
Get fetches the promise by channel ID identifier.
func (*HermesPromiseStorage) List ¶
func (aps *HermesPromiseStorage) List(filter HermesPromiseFilter) ([]HermesPromise, error)
List fetches the promise for the given hermes.
func (*HermesPromiseStorage) Store ¶
func (aps *HermesPromiseStorage) Store(promise HermesPromise) error
Store stores the given promise.
type HermesStatus ¶
type HermesStatus struct { HermesID common.Address ChainID int64 IsActive bool Fee uint16 ValidUntil time.Time }
HermesStatus represents the hermes status.
type HermesStatusChecker ¶
type HermesStatusChecker struct {
// contains filtered or unexported fields
}
HermesStatusChecker checks hermes activity and caches the results.
func NewHermesStatusChecker ¶
func NewHermesStatusChecker(bc mbc, observer observerApi, cacheDuration time.Duration) *HermesStatusChecker
NewHermesStatusChecker creates a new instance of hermes activity checker.
func (*HermesStatusChecker) GetHermesStatus ¶
func (hac *HermesStatusChecker) GetHermesStatus(chainID int64, registryAddress common.Address, hermesID common.Address) (HermesStatus, error)
GetHermesStatus determines if hermes is active or not.
type HermesURLGetter ¶
type HermesURLGetter struct {
// contains filtered or unexported fields
}
HermesURLGetter allows for fetching and storing of hermes urls.
func NewHermesURLGetter ¶
func NewHermesURLGetter( bc bc, addressProvider addressProvider, observer observerApi, ) *HermesURLGetter
NewHermesURLGetter creates a new instance of hermes url getter.
func (*HermesURLGetter) GetHermesURL ¶
GetHermesURL fetches the hermes url from blockchain, observer or local cache if it has already been loaded.
type HermesUserInfo ¶
type HermesUserInfo struct { Identity string `json:"Identity"` Beneficiary string `json:"Beneficiary"` ChannelID string `json:"ChannelID"` Balance *big.Int `json:"Balance"` Settled *big.Int `json:"Settled"` Stake *big.Int `json:"Stake"` LatestPromise LatestPromise `json:"LatestPromise"` LatestSettlement time.Time `json:"LatestSettlement"` IsOffchain bool `json:"IsOffchain"` }
HermesUserInfo represents the consumer data
type HistoryType ¶
type HistoryType string
HistoryType settlement history type swagger:model HistoryType
const ( // SettlementType settlement type SettlementType HistoryType = "settlement" // WithdrawalType withdrawal type WithdrawalType HistoryType = "withdrawal" )
type InvoicePayer ¶
type InvoicePayer struct {
// contains filtered or unexported fields
}
InvoicePayer keeps track of exchange messages and sends them to the provider.
func NewInvoicePayer ¶
func NewInvoicePayer(ipd InvoicePayerDeps) *InvoicePayer
NewInvoicePayer returns a new instance of exchange message tracker.
func (*InvoicePayer) SetSessionID ¶
func (ip *InvoicePayer) SetSessionID(sessionID string)
SetSessionID updates invoice payer dependencies to set session ID once session established.
func (*InvoicePayer) Start ¶
func (ip *InvoicePayer) Start() error
Start starts the message exchange tracker. Blocks.
type InvoicePayerDeps ¶
type InvoicePayerDeps struct { InvoiceChan chan crypto.Invoice PeerExchangeMessageSender PeerExchangeMessageSender ConsumerTotalsStorage consumerTotalsStorage TimeTracker timeTracker Ks hashSigner Identity, Peer identity.Identity AgreedPrice market.Price SenderUUID string SessionID string AddressProvider addressProvider EventBus eventbus.EventBus HermesAddress common.Address DataLeeway datasize.BitSize ChainID int64 }
InvoicePayerDeps contains all the dependencies for the exchange message tracker.
type InvoiceRequest ¶
InvoiceRequest structure represents the invoice message that the provider sends to the consumer.
type InvoiceSender ¶
type InvoiceSender struct {
// contains filtered or unexported fields
}
InvoiceSender is responsible for sending the invoice messages.
func NewInvoiceSender ¶
func NewInvoiceSender(ch p2p.ChannelSender) *InvoiceSender
NewInvoiceSender returns a new instance of the invoice sender.
type InvoiceStorage ¶
type InvoiceStorage struct {
// contains filtered or unexported fields
}
InvoiceStorage allows to store promises.
func NewInvoiceStorage ¶
func NewInvoiceStorage(bolt persistentStorage) *InvoiceStorage
NewInvoiceStorage creates a new instance of invoice storage.
func (*InvoiceStorage) GetInvoice ¶
GetInvoice gets the corresponding invoice from storage.
func (*InvoiceStorage) StoreInvoice ¶
StoreInvoice stores the given invoice in the given bucket with the identity as key.
type InvoiceTracker ¶
type InvoiceTracker struct {
// contains filtered or unexported fields
}
InvoiceTracker keeps tab of invoices and sends them to the consumer.
func NewInvoiceTracker ¶
func NewInvoiceTracker( itd InvoiceTrackerDeps, ) *InvoiceTracker
NewInvoiceTracker creates a new instance of invoice tracker.
func (*InvoiceTracker) Start ¶
func (it *InvoiceTracker) Start() error
Start stars the invoice tracker
func (*InvoiceTracker) WaitFirstInvoice ¶
func (it *InvoiceTracker) WaitFirstInvoice(wait time.Duration) error
WaitFirstInvoice waits for a first invoice to be paid.
type InvoiceTrackerDeps ¶
type InvoiceTrackerDeps struct { AgreedPrice market.Price Peer identity.Identity PeerInvoiceSender PeerInvoiceSender InvoiceStorage providerInvoiceStorage TimeTracker timeTracker ChargePeriodLeeway time.Duration ExchangeMessageChan chan crypto.ExchangeMessage ExchangeMessageWaitTimeout time.Duration ProviderID identity.Identity ConsumersHermesID common.Address AddressProvider addressProvider MaxHermesFailureCount uint64 MaxAllowedHermesFee uint16 HermesStatusChecker hermesStatusChecker EventBus eventbus.EventBus SessionID string PromiseHandler promiseHandler ChainID int64 ChargePeriod time.Duration LimitChargePeriod time.Duration LimitNotPaidInvoice *big.Int MaxNotPaidInvoice *big.Int Observer observerApi }
InvoiceTrackerDeps contains all the deps needed for invoice tracker.
type LatestPromise ¶
type LatestPromise struct { ChainID int64 `json:"ChainID"` ChannelID string `json:"ChannelID"` Amount *big.Int `json:"Amount"` Fee *big.Int `json:"Fee"` Hashlock string `json:"Hashlock"` Signature string `json:"Signature"` }
LatestPromise represents the latest promise
type PeerExchangeMessageSender ¶
type PeerExchangeMessageSender interface {
Send(crypto.ExchangeMessage) error
}
PeerExchangeMessageSender allows for sending of exchange messages.
type PeerInvoiceSender ¶
PeerInvoiceSender allows to send invoices.
type PollConfig ¶
PollConfig sets the interval and timeout for polling.
type Pricer ¶
type Pricer struct {
// contains filtered or unexported fields
}
Pricer fetches and caches prices from discovery api.
func NewPricer ¶
func NewPricer(discoAPI discoAPI) *Pricer
NewPricer creates a new instance of pricer.
func (*Pricer) GetCurrentPrice ¶
func (p *Pricer) GetCurrentPrice(nodeType string, country string, serviceType string) (market.Price, error)
GetCurrentPrice gets the current price from cache if possible, fetches it otherwise.
type ProviderInvoiceStorage ¶
type ProviderInvoiceStorage struct {
// contains filtered or unexported fields
}
ProviderInvoiceStorage allows the provider to store sent invoices.
func NewProviderInvoiceStorage ¶
func NewProviderInvoiceStorage(gis providerSpecificInvoiceStorage) *ProviderInvoiceStorage
NewProviderInvoiceStorage returns a new instance of provider invoice storage.
func (*ProviderInvoiceStorage) Get ¶
func (pis *ProviderInvoiceStorage) Get(providerIdentity, consumerIdentity identity.Identity) (crypto.Invoice, error)
Get returns the stored invoice.
func (*ProviderInvoiceStorage) GetR ¶
func (pis *ProviderInvoiceStorage) GetR(providerID identity.Identity, agreementID *big.Int) (string, error)
GetR gets the R for agreement.
type RequestPromise ¶
type RequestPromise struct { ExchangeMessage crypto.ExchangeMessage `json:"exchange_message"` TransactorFee *big.Int `json:"transactor_fee"` RRecoveryData string `json:"r_recovery_data"` }
RequestPromise represents the request for a new hermes promise
type RevealObject ¶
RevealObject represents the reveal request object.
type RevealSuccess ¶
type RevealSuccess struct {
Message string `json:"message"`
}
RevealSuccess represents the reveal success response from hermes
type SetPromiseFeeRequest ¶
type SetPromiseFeeRequest struct { HermesPromise crypto.Promise `json:"hermes_promise"` NewFee *big.Int `json:"new_fee"` }
SetPromiseFeeRequest represents the payload for changing a promise fee.
type SettlementHistoryEntry ¶
type SettlementHistoryEntry struct { TxHash common.Hash `storm:"id"` BlockExplorerURL string ProviderID identity.Identity HermesID common.Address ChannelAddress common.Address Time time.Time Promise crypto.Promise Beneficiary common.Address Amount *big.Int TotalSettled *big.Int Fees *big.Int IsWithdrawal bool Error string }
SettlementHistoryEntry represents a settlement history entry
type SettlementHistoryFilter ¶
type SettlementHistoryFilter struct { TimeFrom *time.Time TimeTo *time.Time ProviderID *identity.Identity HermesID *common.Address Types []HistoryType }
SettlementHistoryFilter defines all flags for filtering in settlement history storage.
type SettlementHistoryStorage ¶
type SettlementHistoryStorage struct {
// contains filtered or unexported fields
}
SettlementHistoryStorage stores the settlement events for historical purposes.
func NewSettlementHistoryStorage ¶
func NewSettlementHistoryStorage(bolt *boltdb.Bolt) *SettlementHistoryStorage
NewSettlementHistoryStorage returns a new instance of the SettlementHistoryStorage.
func (*SettlementHistoryStorage) List ¶
func (shs *SettlementHistoryStorage) List(filter SettlementHistoryFilter) (result []SettlementHistoryEntry, err error)
List retrieves stored entries.
func (*SettlementHistoryStorage) Store ¶
func (shs *SettlementHistoryStorage) Store(she SettlementHistoryEntry) error
Store stores a given settlement history entry.
Source Files ¶
- consumer_balance_syncer.go
- consumer_balance_tracker.go
- consumer_totals_storage.go
- docs.go
- exchange_messaging.go
- factory.go
- hermes_caller.go
- hermes_channel.go
- hermes_channel_repository.go
- hermes_promise_handler.go
- hermes_promise_settler.go
- hermes_promise_storage.go
- hermes_status_checker.go
- hermes_url_getter.go
- invoice_messaging.go
- invoice_payer.go
- invoice_storage.go
- invoice_tracker.go
- job.go
- price_calculator.go
- pricing.go
- settlement_history_storage.go