Documentation ¶
Overview ¶
Package agent contains a rudimentary and experimental implementation of an agent that coordinates a TCP network connection, initial handshake, and channel opens, payments, and closes.
The agent is intended for use in examples only at this point and is not intended to be stable or reliable.
Index ¶
- type Agent
- func (a *Agent) Close() error
- func (a *Agent) Config() Config
- func (a *Agent) ConnectTCP(addr string) error
- func (a *Agent) DeclareClose() error
- func (a *Agent) Open(asset state.Asset) error
- func (a *Agent) Payment(paymentAmount int64) error
- func (a *Agent) PaymentWithMemo(paymentAmount int64, memo []byte) error
- func (a *Agent) ServeTCP(addr string) error
- func (a *Agent) Snapshot() Snapshot
- type BalanceCollector
- type ClosedEvent
- type ClosingEvent
- type ClosingWithOutdatedStateEvent
- type Config
- type ConnectedEvent
- type ErrorEvent
- type OpenedEvent
- type PaymentReceivedEvent
- type PaymentSentEvent
- type SequenceNumberCollector
- type Snapshot
- type Snapshotter
- type StreamedTransaction
- type Streamer
- type Submitter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent coordinates a payment channel over a TCP connection.
func NewAgentFromSnapshot ¶
NewAgentFromSnapshot creates an agent using a previously generated snapshot so that the new agent has the same state as the previous agent. To restore the channel to its identical state the same config should be provided that was in use when the snapshot was created.
func (*Agent) Close ¶
Close closes the channel. The close must have been declared first either by calling DeclareClose or by the other participant. If the close fails it may be because the channel is already closed, or the participant has submitted the same close which is already queued but not yet processed, or the observation period has not yet passed since the close was declared.
func (*Agent) ConnectTCP ¶
ConnectTCP connects to the given address for establishing a single payment channel.
func (*Agent) DeclareClose ¶
DeclareClose kicks off the close process by submitting a tx to the network to begin the close process, then asynchronously coordinating with the remote participant to coordinate the close. If the participant responds the agent will automatically submit the final close tx that can be submitted immediately. If no closed notification occurs before the observation period, manually submit the close by calling Close.
func (*Agent) Open ¶
Open kicks off the open process which will continue after the function returns.
func (*Agent) Payment ¶
Payment makes a payment with an empty memo. It is equivalent to calling PaymentWithMemo(paymentAmount, "").
func (*Agent) PaymentWithMemo ¶
PaymentWithMemo makes a payment of the payment amount to the remote participant using the open channel. The process is asynchronous and the function returns immediately after the payment is signed and sent to the remote participant. The payment is not authorized until the remote participant signs the payment and returns the payment. The memo is attached to the payment.
type BalanceCollector ¶
type BalanceCollector interface {
GetBalance(account *keypair.FromAddress, asset state.Asset) (int64, error)
}
BalanceCollector gets the balance of an asset for an account.
type ClosedEvent ¶
type ClosedEvent struct{}
ClosedEvent occurs when the channel is successfully closed.
type ClosingEvent ¶
type ClosingEvent struct{}
ClosingEvent occurs when the channel is closing and no new payments should be proposed or confirmed.
type ClosingWithOutdatedStateEvent ¶
type ClosingWithOutdatedStateEvent struct{}
ClosingWithOutdatedStateEvent occurs when the channel is closing and no new payments should be proposed or confirmed, and the state it is closing in is not the latest known state.
type Config ¶
type Config struct { ObservationPeriodTime time.Duration ObservationPeriodLedgerGap uint32 MaxOpenExpiry time.Duration NetworkPassphrase string SequenceNumberCollector SequenceNumberCollector BalanceCollector BalanceCollector Submitter Submitter Streamer Streamer Snapshotter Snapshotter ChannelAccountKey *keypair.FromAddress ChannelAccountSigner *keypair.Full LogWriter io.Writer Events chan<- interface{} }
Config contains the information that can be supplied to configure the Agent at construction.
type ConnectedEvent ¶
type ConnectedEvent struct { ChannelAccount *keypair.FromAddress Signer *keypair.FromAddress }
ConnectedEvent occurs when the agent is connected to another participant.
type ErrorEvent ¶
type ErrorEvent struct {
Err error
}
ErrorEvent occurs when an error has occurred, and contains the error occurred.
type OpenedEvent ¶
type OpenedEvent struct {
OpenAgreement state.OpenAgreement
}
OpenedEvent occurs when the channel has been opened.
type PaymentReceivedEvent ¶
type PaymentReceivedEvent struct {
CloseAgreement state.CloseAgreement
}
PaymentReceivedEvent occurs when a payment is received and the balance it agrees to would be the resulting disbursements from the channel if closed.
type PaymentSentEvent ¶
type PaymentSentEvent struct {
CloseAgreement state.CloseAgreement
}
PaymentSentEvent occurs when a payment is sent and the other participant has confirmed it such that the balance the agreement agrees to would be the resulting disbursements from the channel if closed.
type SequenceNumberCollector ¶
type SequenceNumberCollector interface {
GetSequenceNumber(account *keypair.FromAddress) (int64, error)
}
SequenceNumberCollector gets the sequence number for an account.
type Snapshot ¶
type Snapshot struct { OtherChannelAccount *keypair.FromAddress OtherChannelAccountSigner *keypair.FromAddress StreamerCursor string State *struct { Initiator bool Snapshot state.Snapshot } }
Snapshot is a snapshot of the agent and its dependencies excluding any fields provided in the Config when instantiating an agent. A Snapshot can be restored into an Agent using NewAgentWithSnapshot.
type Snapshotter ¶
Snapshotter is given a snapshot of the agent and its dependencies whenever its meaningful state changes. Snapshots can be restore using NewAgentFromSnapshot.
type StreamedTransaction ¶
type StreamedTransaction struct { // Cursor is a cursor that can be used to resume streaming. Cursor string // TransactionOrderID is an identifier that orders transactions in the order // they were executed on the Stellar network. TransactionOrderID int64 TransactionXDR string ResultXDR string ResultMetaXDR string }
StreamedTransaction is a transaction that has been seen by the Streamer.
type Streamer ¶
type Streamer interface {
StreamTx(cursor string, accounts ...*keypair.FromAddress) (transactions <-chan StreamedTransaction, cancel func())
}
Streamer streams transactions that affect a set of accounts.
type Submitter ¶
type Submitter interface {
SubmitTx(tx *txnbuild.Transaction) error
}
Submitter submits a transaction to the network.
Directories ¶
Path | Synopsis |
---|---|
Package agenthttp contains a simple HTTP handler that, when requested, will return a snapshot of an agent's snapshot at that moment.
|
Package agenthttp contains a simple HTTP handler that, when requested, will return a snapshot of an agent's snapshot at that moment. |
Package bufferedagent contains a rudimentary and experimental implementation of an agent that coordinates a TCP network connection, initial handshake, and channel opens, payments, and closes, and buffers outgoing payments, collapsing them down to a single payment.
|
Package bufferedagent contains a rudimentary and experimental implementation of an agent that coordinates a TCP network connection, initial handshake, and channel opens, payments, and closes, and buffers outgoing payments, collapsing them down to a single payment. |
Package horizon contains types that implement a variety of interfaces defined by the sdk/agent and its sub-packages, providing the functionality of those interfaces by querying Horizon.
|
Package horizon contains types that implement a variety of interfaces defined by the sdk/agent and its sub-packages, providing the functionality of those interfaces by querying Horizon. |
Package msg contains simple types to assist with transmitting and communicating across a network about a payment channel between two participants.
|
Package msg contains simple types to assist with transmitting and communicating across a network about a payment channel between two participants. |
Package submit contains a type and logic for submitting transactions that need to be fee bumped.
|
Package submit contains a type and logic for submitting transactions that need to be fee bumped. |