boltz

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Retry

func Retry(
	ctx context.Context, interval time.Duration, fn func(ctx context.Context) (bool, error),
) error

Types

type Api

type Api struct {
	URL    string
	WSURL  string
	Client http.Client
}

func (*Api) AcceptChainSwapQuote

func (boltz *Api) AcceptChainSwapQuote(swapId string, quote QuoteResponse) error

func (*Api) CreateChainSwap

func (boltz *Api) CreateChainSwap(
	request CreateChainSwapRequest,
) (*CreateChainSwapResponse, error)

func (*Api) CreateReverseSwap

func (boltz *Api) CreateReverseSwap(
	request CreateReverseSwapRequest,
) (*CreateReverseSwapResponse, error)

func (*Api) CreateSwap

func (boltz *Api) CreateSwap(request CreateSwapRequest) (*CreateSwapResponse, error)

func (*Api) FetchBolt12Invoice

func (boltz *Api) FetchBolt12Invoice(
	request FetchBolt12InvoiceRequest,
) (*FetchBolt12InvoiceResponse, error)

func (*Api) GetChainSwapClaimDetails

func (boltz *Api) GetChainSwapClaimDetails(swapId string) (*ChainSwapClaimDetailsResponse, error)

func (*Api) GetChainSwapQuote

func (boltz *Api) GetChainSwapQuote(swapId string) (*QuoteResponse, error)

func (*Api) GetChainSwapTransactions

func (boltz *Api) GetChainSwapTransactions(swapId string) (*ChainSwapTransactionsResponse, error)

func (*Api) GetSwapHistory

func (boltz *Api) GetSwapHistory(pubkey string) ([]Swap, error)

func (*Api) NewWebsocket

func (boltz *Api) NewWebsocket() *Websocket

func (*Api) RefundChainSwap

func (boltz *Api) RefundChainSwap(
	swapId string,
	request RefundSwapRequest,
) (*RefundSwapResponse, error)

func (*Api) RefundSubmarine

func (boltz *Api) RefundSubmarine(
	swapId string,
	request RefundSwapRequest,
) (*RefundSwapResponse, error)

func (*Api) RevealPreimage

func (boltz *Api) RevealPreimage(swapId string, preimage string) (*RevealPreimageResponse, error)

func (*Api) SubmitChainSwapClaim

func (boltz *Api) SubmitChainSwapClaim(
	swapId string,
	request ChainSwapClaimRequest,
) (*PartialSignatureResponse, error)

type ArkTimeouts

type ArkTimeouts struct {
	Refund                          int `json:"refund"`
	UnilateralClaim                 int `json:"unilateralClaim"`
	UnilateralRefund                int `json:"unilateralRefund"`
	UnilateralRefundWithoutReceiver int `json:"unilateralRefundWithoutReceiver"`
}

type ChainSwapClaimDetailsResponse

type ChainSwapClaimDetailsResponse struct {
	PubNonce        string         `json:"pubNonce"`
	PublicKey       string         `json:"publicKey"`
	TheirPublicKey  string         `json:"theirPublicKey"`
	TransactionHash string         `json:"transactionHash"`
	SwapTree        string         `json:"swapTree"` // base64 serialized
	Transaction     TransactionRef `json:"transaction"`
}

type ChainSwapClaimRequest

type ChainSwapClaimRequest struct {
	Preimage         string             `json:"preimage"`
	ToSign           ToSign             `json:"toSign"`
	PubNonce         string             `json:"pubNonce"`
	PartialSignature string             `json:"partialSignature"`
	Transaction      string             `json:"transaction"`
	Index            int                `json:"index"`
	Signature        CrossSignSignature `json:"signature,omitempty"`
}

type ChainSwapLockupDetails

type ChainSwapLockupDetails struct {
	LockupAddress      string   `json:"lockupAddress"`
	Amount             uint64   `json:"amount"`
	ClaimPublicKey     string   `json:"claimPublicKey,omitempty"`
	RefundPublicKey    string   `json:"refundPublicKey,omitempty"`
	TimeoutBlockHeight uint32   `json:"timeoutBlockHeight"`
	SwapTree           SwapTree `json:"swapTree"`
}

type ChainSwapTimeouts

type ChainSwapTimeouts struct {
	Refund                          int `json:"refund"`
	UnilateralClaim                 int `json:"unilateralClaim"`
	UnilateralRefund                int `json:"unilateralRefund"`
	UnilateralRefundWithoutReceiver int `json:"unilateralRefundWithoutReceiver"`
}

type ChainSwapTransaction

type ChainSwapTransaction struct {
	Id     string `json:"id"`
	Hex    string `json:"hex"`
	Status string `json:"status"`
}

type ChainSwapTransactionsResponse

type ChainSwapTransactionsResponse struct {
	UserLock   *ChainSwapTransaction `json:"userLock,omitempty"`
	ServerLock *ChainSwapTransaction `json:"serverLock,omitempty"`
}

type CreateChainSwapRequest

type CreateChainSwapRequest struct {
	From             Currency `json:"from"`
	To               Currency `json:"to"`
	PreimageHash     string   `json:"preimageHash"`
	ClaimPublicKey   string   `json:"claimPublicKey"`
	RefundPublicKey  string   `json:"refundPublicKey"`
	UserLockAmount   uint64   `json:"userLockAmount,omitempty"`
	ServerLockAmount uint64   `json:"serverLockAmount,omitempty"`
	PairHash         string   `json:"pairHash,omitempty"`
	ReferralId       string   `json:"referralId,omitempty"`
}

type CreateChainSwapResponse

type CreateChainSwapResponse struct {
	Id            string  `json:"id"`
	ClaimDetails  SwapLeg `json:"claimDetails"`
	LockupDetails SwapLeg `json:"lockupDetails"`
	Error         string  `json:"error,omitempty"`
}

func (CreateChainSwapResponse) GetSwapTree

func (c CreateChainSwapResponse) GetSwapTree(isArkToBtc bool) SwapTree

type CreateReverseSwapRequest

type CreateReverseSwapRequest struct {
	From           Currency `json:"from"`
	To             Currency `json:"to"`
	ClaimPublicKey string   `json:"claimPublicKey"`
	InvoiceAmount  uint64   `json:"invoiceAmount,omitempty"`
	OnchainAmount  uint64   `json:"onchainAmount,omitempty"`
	PreimageHash   string   `json:"preimageHash,omitempty"`
}

type CreateReverseSwapResponse

type CreateReverseSwapResponse struct {
	Id                  string              `json:"id"`
	LockupAddress       string              `json:"lockupAddress"`
	RefundPublicKey     string              `json:"refundPublicKey"`
	TimeoutBlockHeights TimeoutBlockHeights `json:"timeoutBlockHeights"`
	Invoice             string              `json:"invoice"`
	InvoiceAmount       uint64              `json:"invoiceAmount,omitempty"`
	OnchainAmount       uint64              `json:"onchainAmount"`

	Error string `json:"error"`
}

type CreateSwapRequest

type CreateSwapRequest struct {
	From            Currency `json:"from"`
	To              Currency `json:"to"`
	RefundPublicKey string   `json:"refundPublicKey"`
	Invoice         string   `json:"invoice,omitempty"`
	PaymentTimeout  uint32   `json:"paymentTimeout,omitempty"`
}

type CreateSwapResponse

type CreateSwapResponse struct {
	Id                  string              `json:"id"`
	Address             string              `json:"address"`
	AcceptZeroConf      bool                `json:"acceptZeroConf"`
	ExpectedAmount      uint64              `json:"expectedAmount"`
	ClaimPublicKey      string              `json:"claimPublicKey"`
	TimeoutBlockHeights TimeoutBlockHeights `json:"timeoutBlockHeights"`

	Error string `json:"error"`
}

type CrossSignSignature

type CrossSignSignature struct {
	PubNonce         string `json:"pubNonce"`
	PartialSignature string `json:"partialSignature"`
}

type Currency

type Currency string
const (
	CurrencyBtc       Currency = "BTC"
	CurrencyArk       Currency = "ARK"
	CurrencyLiquid    Currency = "L-BTC"
	CurrencyRootstock Currency = "RBTC"
)

type FetchBolt12InvoiceRequest

type FetchBolt12InvoiceRequest struct {
	Offer  string `json:"offer"`
	Amount uint64 `json:"amount,omitempty"`
	Note   string `json:"note,omitempty"`
}

type FetchBolt12InvoiceResponse

type FetchBolt12InvoiceResponse struct {
	Invoice string `json:"invoice"`

	Error string `json:"error"`
}

type GetSwapLimitsResponse

type GetSwapLimitsResponse struct {
	Ark struct {
		Btc struct {
			Limits struct {
				Maximal int `json:"maximal"`
				Minimal int `json:"minimal"`
			} `json:"limits"`
		} `json:"BTC"`
	} `json:"ARK"`
}

type HTTPError

type HTTPError struct {
	Method     string
	URL        string
	StatusCode int
	Body       string
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Leaf

type Leaf struct {
	Version int    `json:"version"`
	Output  string `json:"output"`
}

type PartialSignatureResponse

type PartialSignatureResponse struct {
	PubNonce         string `json:"pubNonce"`
	PartialSignature string `json:"partialSignature"`
}

type QuoteResponse

type QuoteResponse struct {
	Amount             uint64 `json:"amount"`
	OnchainAmount      uint64 `json:"onchainAmount"`
	TimeoutBlockHeight uint32 `json:"timeoutBlockHeight"`
}

type RefundSwapRequest

type RefundSwapRequest struct {
	Transaction string `json:"transaction"`
	Checkpoint  string `json:"checkpoint"`
}

type RefundSwapResponse

type RefundSwapResponse struct {
	Transaction string `json:"transaction"`
	Checkpoint  string `json:"checkpoint"`
	Error       string `json:"error"`
}

type RevealPreimageRequest

type RevealPreimageRequest struct {
	Id       string `json:"id"`
	Preimage string `json:"preimage"`
}

type RevealPreimageResponse

type RevealPreimageResponse struct {
	Id          string `json:"id"`
	Transaction string `json:"transaction"`

	Error string `json:"error"`
}

type Swap

type Swap struct {
	Id            string       `json:"id"`
	Type          string       `json:"type"`
	Status        string       `json:"status"`
	From          Currency     `json:"from"`
	To            Currency     `json:"to"`
	CreatedAt     uint32       `json:"createdAt"`
	PreimageHash  string       `json:"preimageHash"`
	ClaimDetails  *SwapDetails `json:"claimDetails,omitempty"`
	RefundDetails *SwapDetails `json:"refundDetails,omitempty"`
}

type SwapDetails

type SwapDetails struct {
	Tree               Tree           `json:"tree"`
	Amount             uint64         `json:"amount"`
	Transaction        TransactionRef `json:"transaction,omitempty"`
	LockupAddress      string         `json:"lockupAddress"`
	TimeoutBlockHeight uint32         `json:"timeoutBlockHeight"`
}

type SwapLeg

type SwapLeg struct {
	ServerPublicKey    string `json:"serverPublicKey"`
	Amount             int    `json:"amount"`
	LockupAddress      string `json:"lockupAddress"`
	TimeoutBlockHeight int    `json:"timeoutBlockHeight"`

	// BTC-specific (present on the BTC leg; may appear on either claimDetails or lockupDetails)
	SwapTree *SwapTree `json:"swapTree,omitempty"`
	// ARK-specific (present on the ARK leg; may appear on either claimDetails or lockupDetails)
	Timeouts *ArkTimeouts `json:"timeouts,omitempty"`
}

SwapLeg describes ONE side (one chain) of the swap. Some fields exist only for BTC (swapTree, bip21) or only for ARK (timeouts).

type SwapStatusResponse

type SwapStatusResponse struct {
	Status           string `json:"status"`
	ZeroConfRejected bool   `json:"zeroConfRejected"`
	Transaction      struct {
		Id  string `json:"id"`
		Hex string `json:"hex"`
	} `json:"transaction"`

	Error string `json:"error"`
}

type SwapTree

type SwapTree struct {
	ClaimLeaf  SwapTreeLeaf `json:"claimLeaf"`
	RefundLeaf SwapTreeLeaf `json:"refundLeaf"`
}

type SwapTreeLeaf

type SwapTreeLeaf struct {
	Version uint8  `json:"version"`
	Output  string `json:"output"`
}

type SwapUpdate

type SwapUpdate struct {
	SwapStatusResponse `       mapstructure:",squash"`
	Id                 string `                       json:"id"`
}

type SwapUpdateEvent

type SwapUpdateEvent int
const (
	SwapCreated SwapUpdateEvent = iota
	SwapExpired

	InvoiceSet
	InvoicePaid
	InvoicePending
	InvoiceSettled
	InvoiceFailedToPay

	ChannelCreated

	TransactionFailed
	TransactionMempool
	TransactionClaimed
	TransactionRefunded
	TransactionConfirmed
	TransactionLockupFailed
	TransactionClaimPending

	TransactionServerMempoool
	TransactionServerConfirmed

	TransactionDirect
	TransactionDirectMempool
)

func ParseEvent

func ParseEvent(event string) SwapUpdateEvent

type TapLeaf

type TapLeaf struct {
	Version int    `json:"version"`
	Output  string `json:"output"`
}

type TimeoutBlockHeights

type TimeoutBlockHeights struct {
	RefundLocktime                  uint32 `json:"refund"`
	UnilateralClaim                 uint32 `json:"unilateralClaim"`
	UnilateralRefund                uint32 `json:"unilateralRefund"`
	UnilateralRefundWithoutReceiver uint32 `json:"unilateralRefundWithoutReceiver"`
}

type ToSign

type ToSign struct {
	Nonce   string `json:"pubNonce"`
	ClaimTx string `json:"transaction"`
	Index   int    `json:"index"`
}

type TransactionRef

type TransactionRef struct {
	ID   string `json:"id"`
	Vout int    `json:"vout"`
}

type Tree

type Tree struct {
	ClaimLeaf                       Leaf `json:"claimLeaf"`
	RefundLeaf                      Leaf `json:"refundLeaf"`
	RefundLeafWithoutReceiver       Leaf `json:"refundWithoutBoltzLeaf"`
	UnilateralClaimLeaf             Leaf `json:"unilateralClaimLeaf"`
	UnilateralRefundLeaf            Leaf `json:"unilateralRefundLeaf"`
	UnilateralRefundWithoutReceiver Leaf `json:"unilateralRefundWithoutBoltzLeaf"`
}

type Websocket

type Websocket struct {
	Updates chan SwapUpdate
	// contains filtered or unexported fields
}

func (*Websocket) Close

func (boltz *Websocket) Close() error

func (*Websocket) Connect

func (boltz *Websocket) Connect() error

func (*Websocket) ConnectAndSubscribe

func (boltz *Websocket) ConnectAndSubscribe(
	ctx context.Context,
	swapIds []string,
	retryInterval time.Duration,
) error

func (*Websocket) Reconnect

func (boltz *Websocket) Reconnect() error

func (*Websocket) Subscribe

func (boltz *Websocket) Subscribe(swapIds []string) error

func (*Websocket) Unsubscribe

func (boltz *Websocket) Unsubscribe(swapId string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址