Versions in this module Expand all Collapse all v0 v0.2.97 Oct 15, 2022 Changes in this version + const BitcoinCsv + const CLAIMTYPE_CSV + const CLAIMTYPE_PREIMAGE + const Default + const LiquidCsv + const NoOp + const PEERSWAP_PROTOCOL_VERSION + const PaymentLabelSeparator + var AllowedAssets = []string + var AlreadyExistsError = errors.New("Message already exists") + var AssetOrNetworkSetError = errors.New("Either asset or network must be set") + var ErrAlreadyExists = fmt.Errorf("swap already exist") + var ErrDataNotAvailable = errors.New("data not in store") + var ErrDoesNotExist = fmt.Errorf("does not exist") + var ErrEventRejected = errors.New("event rejected") + var ErrFsmConfig = errors.New("fsm config invalid") + var ErrSwapDoesNotExist = errors.New("swap does not exist") + var InvalidLengthError = errors.New("Hex string is of invalid length") + var InvalidNetworkError = errors.New("Invalid network") + var InvalidScidError = errors.New("Invalid Scid") + func ErrReceivedMessageFromUnexpectedPeer(peerId string, swapId *SwapId) error + func MarshalPeerswapMessage(msg PeerMessage) ([]byte, int, error) + func NewBboltStore(db *bbolt.DB) (*bboltStore, error) + func NewInvalidLengthError(paramName string, expected, actual int) error + func NewRequestedSwapsStore(db *bbolt.DB) (*requestedSwapsStore, error) + func SwapInReceiverStatesToMermaid(filename string) error + func SwapInSenderStatesToMermaid(filename string) error + func SwapOutReceiverStatesToMermaid(filename string) error + func SwapOutSenderStatesToMermaid(filename string) error + type Action interface + Execute func(services *SwapServices, swap *SwapData) EventType + type AwaitCsvAction struct + func (w *AwaitCsvAction) Execute(services *SwapServices, swap *SwapData) EventType + type AwaitFeeInvoicePayment struct + func (w *AwaitFeeInvoicePayment) Execute(services *SwapServices, swap *SwapData) EventType + type AwaitPaymentOrCsvAction struct + func (w *AwaitPaymentOrCsvAction) Execute(services *SwapServices, swap *SwapData) EventType + type AwaitTxConfirmationAction struct + func (t *AwaitTxConfirmationAction) Execute(services *SwapServices, swap *SwapData) EventType + type CancelAction struct + func (c *CancelAction) Execute(services *SwapServices, swap *SwapData) EventType + type CancelMessage struct + Message string + SwapId *SwapId + func (e CancelMessage) MessageType() messages.MessageType + func (m CancelMessage) ApplyToSwapData(swap *SwapData) error + func (s CancelMessage) Validate(swap *SwapData) error + type CheckRequestWrapperAction struct + func (a CheckRequestWrapperAction) Execute(services *SwapServices, swap *SwapData) EventType + type ClaimParams struct + BlindingSeed []byte + EphemeralKey *btcec.PrivateKey + OpeningTxHex string + OutputAssetBlindingFactor []byte + Preimage string + Signer Signer + func (o *ClaimParams) String() string + type ClaimSwapTransactionCoop struct + func (c *ClaimSwapTransactionCoop) Execute(services *SwapServices, swap *SwapData) EventType + type ClaimSwapTransactionWithCsv struct + func (c *ClaimSwapTransactionWithCsv) Execute(services *SwapServices, swap *SwapData) EventType + type ClaimSwapTransactionWithPreimageAction struct + func (s *ClaimSwapTransactionWithPreimageAction) Execute(services *SwapServices, swap *SwapData) EventType + type ClaimType int + type CoopCloseMessage struct + Message string + Privkey string + SwapId *SwapId + func (c CoopCloseMessage) MessageType() messages.MessageType + func (m CoopCloseMessage) ApplyToSwapData(swap *SwapData) error + func (s CoopCloseMessage) Validate(swap *SwapData) error + type CreateAndBroadcastOpeningTransaction struct + func (c *CreateAndBroadcastOpeningTransaction) Execute(services *SwapServices, swap *SwapData) EventType + type CreateSwapOutFromRequestAction struct + func (c *CreateSwapOutFromRequestAction) Execute(services *SwapServices, swap *SwapData) EventType + type CreateSwapRequestAction struct + func (a *CreateSwapRequestAction) Execute(services *SwapServices, swap *SwapData) EventType + type ErrMinimumSwapSize uint64 + func (u ErrMinimumSwapSize) Error() string + type ErrUnknownSwapMessageType string + func (s ErrUnknownSwapMessageType) Error() string + type EventContext interface + ApplyToSwapData func(data *SwapData) error + Validate func(data *SwapData) error + type EventType string + const Event_ActionFailed + const Event_ActionSucceeded + const Event_Done + const Event_OnCancelReceived + const Event_OnClaimInvoicePaid + const Event_OnClaimedCsv + const Event_OnCoopCloseReceived + const Event_OnCsvPassed + const Event_OnFeeInvoicePaid + const Event_OnFeeInvoiceReceived + const Event_OnInvalid_Message + const Event_OnRetry + const Event_OnSwapOutRequestReceived + const Event_OnSwapOutStarted + const Event_OnTimeout + const Event_OnTxConfirmed + const Event_OnTxOpenedMessage + const Event_SwapInReceiver_OnRequestReceived + const Event_SwapInSender_OnAgreementReceived + const Event_SwapInSender_OnSwapInRequested + type Events map[EventType]StateType + type InvoiceType int + const INVOICE_CLAIM + const INVOICE_FEE + func (i InvoiceType) String() string + type JsonAssetRequest struct + NRequests uint64 + TotalAmountSat uint64 + type JsonEnty struct + NodeId string + Requests map[string]map[string]*JsonAssetRequest + type LightningClient interface + AddPaymentCallback func(f func(swapId string, invoiceType InvoiceType)) + AddPaymentNotifier func(swapId string, payreq string, invoiceType InvoiceType) + DecodePayreq func(payreq string) (paymentHash string, amountMsat uint64, expiry int64, err error) + GetPayreq func(msatAmount uint64, preimage string, swapId string, memo string, ...) (string, error) + PayInvoice func(payreq string) (preImage string, err error) + PayInvoiceViaChannel func(payreq string, channel string) (preimage string, err error) + RebalancePayment func(payreq string, channel string) (preimage string, err error) + type Messenger interface + AddMessageHandler func(func(peerId string, msgType string, payload []byte) error) + SendMessage func(peerId string, message []byte, messageType int) error + type MessengerManager interface + AddSender func(id string, messenger messages.StoppableMessenger) error + RemoveSender func(id string) + type NoOpAction struct + func (n *NoOpAction) Execute(services *SwapServices, swap *SwapData) EventType + type NoOpDoneAction struct + func (a *NoOpDoneAction) Execute(services *SwapServices, swap *SwapData) EventType + type OpeningParams struct + Amount uint64 + BlindingKey *btcec.PrivateKey + ClaimPaymentHash string + MakerPubkey string + OpeningAddress string + TakerPubkey string + func (o *OpeningParams) String() string + type OpeningTxBroadcastedMessage struct + BlindingKey string + Payreq string + ScriptOut uint32 + SwapId *SwapId + TxId string + func (m OpeningTxBroadcastedMessage) ApplyToSwapData(swap *SwapData) error + func (s OpeningTxBroadcastedMessage) Validate(swap *SwapData) error + func (t OpeningTxBroadcastedMessage) MessageType() messages.MessageType + type PayFeeInvoiceAction struct + func (r *PayFeeInvoiceAction) Execute(services *SwapServices, swap *SwapData) EventType + type PeerIsSuspiciousError string + func (s PeerIsSuspiciousError) Error() string + type PeerMessage interface + MessageType func() messages.MessageType + type PeerNotAllowedError string + func (s PeerNotAllowedError) Error() string + type Policy interface + GetMinSwapAmountMsat func() uint64 + GetReserveOnchainMsat func() uint64 + IsPeerAllowed func(peer string) bool + IsPeerSuspicious func(peer string) bool + NewSwapsAllowed func() bool + type RequestedSwap struct + AmountSat uint64 + Asset string + RejectionReason string + Type SwapType + type RequestedSwapsPrinter struct + func NewRequestedSwapsPrinter(store RequestedSwapsStore) *RequestedSwapsPrinter + func (p *RequestedSwapsPrinter) Get() ([]JsonEnty, error) + func (p *RequestedSwapsPrinter) GetRaw() (map[string][]RequestedSwap, error) + func (p *RequestedSwapsPrinter) Write(w io.Writer) + type RequestedSwapsStore interface + Add func(id string, reqswap RequestedSwap) error + Get func(id string) ([]RequestedSwap, error) + GetAll func() (map[string][]RequestedSwap, error) + type Secp256k1Signer struct + func (s *Secp256k1Signer) Sign(hash []byte) (*ecdsa.Signature, error) + type SendCancelAction struct + func (s *SendCancelAction) Execute(services *SwapServices, swap *SwapData) EventType + type SendMessageAction struct + func (s *SendMessageAction) Execute(services *SwapServices, swap *SwapData) EventType + type SendMessageWithRetryAction struct + func (s *SendMessageWithRetryAction) Execute(services *SwapServices, swap *SwapData) EventType + type SetBlindingKeyActionWrapper struct + func (a *SetBlindingKeyActionWrapper) Execute(services *SwapServices, swap *SwapData) EventType + type SetStartingBlockHeightAction struct + func (s *SetStartingBlockHeightAction) Execute(services *SwapServices, swap *SwapData) EventType + type Signer interface + Sign func(hash []byte) (*btecdsa.Signature, error) + type State struct + Action Action + Events Events + FailOnrecover bool + type StateType string + const State_ClaimedCoop + const State_ClaimedCsv + const State_ClaimedPreimage + const State_SendCancel + const State_SwapCanceled + const State_SwapInReceiver_AwaitTxBroadcastedMessage + const State_SwapInReceiver_AwaitTxConfirmation + const State_SwapInReceiver_ClaimSwap + const State_SwapInReceiver_CreateSwap + const State_SwapInReceiver_SendAgreement + const State_SwapInReceiver_SendCoopClose + const State_SwapInReceiver_SendPrivkey + const State_SwapInReceiver_ValidateTxAndPayClaimInvoice + const State_SwapInSender_AwaitAgreement + const State_SwapInSender_AwaitClaimPayment + const State_SwapInSender_BroadcastOpeningTx + const State_SwapInSender_ClaimSwapCoop + const State_SwapInSender_ClaimSwapCsv + const State_SwapInSender_CreateSwap + const State_SwapInSender_SendRequest + const State_SwapInSender_SendTxBroadcastedMessage + const State_SwapOutReceiver_AwaitClaimInvoicePayment + const State_SwapOutReceiver_AwaitFeeInvoicePayment + const State_SwapOutReceiver_BroadcastOpeningTx + const State_SwapOutReceiver_ClaimSwapCoop + const State_SwapOutReceiver_ClaimSwapCsv + const State_SwapOutReceiver_CreateSwap + const State_SwapOutReceiver_SendFeeInvoice + const State_SwapOutReceiver_SendTxBroadcastedMessage + const State_SwapOutReceiver_SwapAborted + const State_SwapOutSender_AwaitAgreement + const State_SwapOutSender_AwaitTxBroadcastedMessage + const State_SwapOutSender_AwaitTxConfirmation + const State_SwapOutSender_ClaimSwap + const State_SwapOutSender_CreateSwap + const State_SwapOutSender_PayFeeInvoice + const State_SwapOutSender_SendCoopClose + const State_SwapOutSender_SendPrivkey + const State_SwapOutSender_SendRequest + const State_SwapOutSender_ValidateTxAndPayClaimInvoice + const State_WaitCsv + type States map[StateType]State + type StopSendMessageWithRetryWrapperAction struct + func (a StopSendMessageWithRetryWrapperAction) Execute(services *SwapServices, swap *SwapData) EventType + type Store interface + GetData func(id string) (*SwapStateMachine, error) + ListAll func() ([]*SwapStateMachine, error) + ListAllByPeer func(peer string) ([]*SwapStateMachine, error) + UpdateData func(data *SwapStateMachine) error + type SwapData struct + BlindingKeyHex string + Cancel *CancelMessage + CancelMessage string + ClaimPaymentHash string + ClaimPreimage string + ClaimTxId string + CoopClose *CoopCloseMessage + CreatedAt int64 + FSMState StateType + FeePreimage string + InitiatorNodeId string + LastErr error + LastErrString string + LastMessage EventContext + NextMessage []byte + NextMessageType int + OpeningTxBroadcasted *OpeningTxBroadcastedMessage + OpeningTxFee uint64 + OpeningTxHex string + PeerNodeId string + PrivkeyBytes []byte + Role SwapRole + StartingBlockHeight uint32 + SwapInAgreement *SwapInAgreementMessage + SwapInRequest *SwapInRequestMessage + SwapOutAgreement *SwapOutAgreementMessage + SwapOutRequest *SwapOutRequestMessage + func NewSwapData(swapId *SwapId, initiatorNodeId string, peerNodeId string) *SwapData + func NewSwapDataFromRequest(swapId *SwapId, senderNodeId string) *SwapData + func (s *SwapData) GetAmount() uint64 + func (s *SwapData) GetAsset() string + func (s *SwapData) GetCancelMessage() string + func (s *SwapData) GetChain() string + func (s *SwapData) GetClaimParams() *ClaimParams + func (s *SwapData) GetCurrentState() StateType + func (s *SwapData) GetId() *SwapId + func (s *SwapData) GetInvoiceCltv() uint64 + func (s *SwapData) GetInvoiceExpiry() uint64 + func (s *SwapData) GetMakerPubkey() string + func (s *SwapData) GetNetwork() string + func (s *SwapData) GetOpeningParams() *OpeningParams + func (s *SwapData) GetOpeningTxId() string + func (s *SwapData) GetPaymentHash() string + func (s *SwapData) GetPreimage() string + func (s *SwapData) GetPrivkey() *btcec.PrivateKey + func (s *SwapData) GetProtocolVersion() uint8 + func (s *SwapData) GetRequest() PeerMessage + func (s *SwapData) GetScid() string + func (s *SwapData) GetScidInBoltFormat() string + func (s *SwapData) GetTakerPubkey() string + func (s *SwapData) GetType() SwapType + func (s *SwapData) HandleError(err error) EventType + func (s *SwapData) SetState(stateType StateType) + type SwapErrorContext struct + Err error + SendPeer bool + func (s *SwapErrorContext) Validate(data *SwapData) error + func (s SwapErrorContext) ApplyToSwapData(data *SwapData) error + type SwapId [32]byte + func NewSwapId() *SwapId + func ParseSwapIdFromString(str string) (*SwapId, error) + func (s *SwapId) FromString(str string) error + func (s *SwapId) MarshalJSON() ([]byte, error) + func (s *SwapId) String() string + func (s *SwapId) UnmarshalJSON(data []byte) error + type SwapInAgreementMessage struct + Premium uint64 + ProtocolVersion uint8 + Pubkey string + SwapId *SwapId + func (s SwapInAgreementMessage) ApplyToSwapData(swap *SwapData) error + func (s SwapInAgreementMessage) MessageType() messages.MessageType + func (s SwapInAgreementMessage) Validate(swap *SwapData) error + type SwapInReceiverInitAction struct + func (s *SwapInReceiverInitAction) Execute(services *SwapServices, swap *SwapData) EventType + type SwapInRequestMessage struct + Amount uint64 + Asset string + Network string + ProtocolVersion uint8 + Pubkey string + Scid string + SwapId *SwapId + func (s SwapInRequestMessage) ApplyToSwapData(swap *SwapData) error + func (s SwapInRequestMessage) MessageType() messages.MessageType + func (s SwapInRequestMessage) Validate(swap *SwapData) error + type SwapOutAgreementMessage struct + Payreq string + ProtocolVersion uint8 + Pubkey string + SwapId *SwapId + func (s SwapOutAgreementMessage) ApplyToSwapData(swap *SwapData) error + func (s SwapOutAgreementMessage) MessageType() messages.MessageType + func (s SwapOutAgreementMessage) Validate(swap *SwapData) error + type SwapOutRequestMessage struct + Amount uint64 + Asset string + Network string + ProtocolVersion uint8 + Pubkey string + Scid string + SwapId *SwapId + func (s SwapOutRequestMessage) ApplyToSwapData(swap *SwapData) error + func (s SwapOutRequestMessage) MessageType() messages.MessageType + func (s SwapOutRequestMessage) Validate(swap *SwapData) error + type SwapRole int + const SWAPROLE_RECEIVER + const SWAPROLE_SENDER + func (s SwapRole) String() string + type SwapService struct + BitcoinEnabled bool + LiquidEnabled bool + func NewSwapService(services *SwapServices) *SwapService + func (s *SwapService) AddActiveSwap(swapId string, swap *SwapStateMachine) + func (s *SwapService) GetActiveSwap(swapId string) (*SwapStateMachine, error) + func (s *SwapService) GetSwap(swapId string) (*SwapStateMachine, error) + func (s *SwapService) HasActiveSwaps() (bool, error) + func (s *SwapService) ListActiveSwaps() ([]*SwapStateMachine, error) + func (s *SwapService) ListSwaps() ([]*SwapStateMachine, error) + func (s *SwapService) ListSwapsByPeer(peer string) ([]*SwapStateMachine, error) + func (s *SwapService) OnCancelReceived(swapId *SwapId, cancelMsg *CancelMessage) error + func (s *SwapService) OnClaimInvoiceNotification(swapId *SwapId) error + func (s *SwapService) OnCoopCloseReceived(swapId *SwapId, coopCloseMessage *CoopCloseMessage) error + func (s *SwapService) OnCsvPassed(swapId string) error + func (s *SwapService) OnFeeInvoiceNotification(swapId *SwapId) error + func (s *SwapService) OnMessageReceived(peerId string, msgTypeString string, payload []byte) error + func (s *SwapService) OnPayment(swapIdStr string, invoiceType InvoiceType) + func (s *SwapService) OnSwapInAgreementReceived(msg *SwapInAgreementMessage) error + func (s *SwapService) OnSwapInRequestReceived(swapId *SwapId, peerId string, message *SwapInRequestMessage) error + func (s *SwapService) OnSwapOutAgreementReceived(message *SwapOutAgreementMessage) error + func (s *SwapService) OnSwapOutRequestReceived(swapId *SwapId, peerId string, message *SwapOutRequestMessage) error + func (s *SwapService) OnTxConfirmed(swapId string, txHex string) error + func (s *SwapService) OnTxOpenedMessage(message *OpeningTxBroadcastedMessage) error + func (s *SwapService) RecoverSwaps() error + func (s *SwapService) RemoveActiveSwap(swapId string) + func (s *SwapService) ResendLastMessage(swapId string) error + func (s *SwapService) SenderOnTxConfirmed(swapId string) error + func (s *SwapService) Start() error + func (s *SwapService) SwapIn(peer string, chain string, channelId string, initiator string, amtSat uint64) (*SwapStateMachine, error) + func (s *SwapService) SwapOut(peer string, chain string, channelId string, initiator string, amtSat uint64) (*SwapStateMachine, error) + type SwapServices struct + func NewSwapServices(swapStore Store, requestedSwapsStore RequestedSwapsStore, ...) *SwapServices + type SwapStateMachine struct + Current StateType + Data *SwapData + Previous StateType + Role SwapRole + States States + SwapId *SwapId + Type SwapType + func (s *SwapStateMachine) EventIsValid(event EventType) bool + func (s *SwapStateMachine) Infof(format string, v ...interface{}) + func (s *SwapStateMachine) IsFinished() bool + func (s *SwapStateMachine) Recover() (bool, error) + func (s *SwapStateMachine) SendEvent(event EventType, eventCtx EventContext) (bool, error) + type SwapType int + const SWAPTYPE_IN + const SWAPTYPE_OUT + func (s SwapType) JsonFieldValue() string + func (s SwapType) String() string + type TakerSendPrivkeyAction struct + func (s *TakerSendPrivkeyAction) Execute(services *SwapServices, swap *SwapData) EventType + type TimeOutService interface + type TxWatcher interface + AddConfirmationCallback func(func(swapId string, txHex string) error) + AddCsvCallback func(func(swapId string) error) + AddWaitForConfirmationTx func(swapId, txId string, vout, startingHeight uint32, scriptpubkey []byte) + AddWaitForCsvTx func(swapId, txId string, vout uint32, startingHeight uint32, scriptpubkey []byte) + GetBlockHeight func() (uint32, error) + type ValidateTxAndPayClaimInvoiceAction struct + func (p *ValidateTxAndPayClaimInvoiceAction) Execute(services *SwapServices, swap *SwapData) EventType + type Validator interface + GetCSVHeight func() uint32 + TxIdFromHex func(txHex string) (string, error) + ValidateTx func(swapParams *OpeningParams, txHex string) (bool, error) + type Wallet interface + BroadcastOpeningTx func(unpreparedTxHex string) (txId, txHex string, error error) + CreateCoopSpendingTransaction func(swapParams *OpeningParams, claimParams *ClaimParams, takerSigner Signer) (txId, txHex string, error error) + CreateCsvSpendingTransaction func(swapParams *OpeningParams, claimParams *ClaimParams) (txId, txHex string, error error) + CreateOpeningTransaction func(swapParams *OpeningParams) (unpreparedTxHex string, fee uint64, vout uint32, err error) + CreatePreimageSpendingTransaction func(swapParams *OpeningParams, claimParams *ClaimParams) (string, string, error) + GetAsset func() string + GetFlatSwapOutFee func() (uint64, error) + GetNetwork func() string + GetOnchainBalance func() (uint64, error) + GetOutputScript func(params *OpeningParams) ([]byte, error) + GetRefundFee func() (uint64, error) + NewAddress func() (string, error) + type WrongAssetError string + func (e WrongAssetError) Error() string