Documentation ¶
Index ¶
- type Addresses
- type Builder
- func (b *Builder) AcceptAdderss(addr btcutil.Address) error
- func (b *Builder) AcceptCETxSignatures(sigs [][]byte) error
- func (b *Builder) AcceptChangeAdderss(addr btcutil.Address) error
- func (b *Builder) AcceptFundWitnesses(wits []wire.TxWitness)
- func (b *Builder) AcceptPubkey(pub []byte) error
- func (b *Builder) AcceptRefundTxSignature(sig []byte) error
- func (b *Builder) AcceptUtxos(utxos []Utxo) error
- func (b *Builder) Address() btcutil.Address
- func (b *Builder) ChangeAddress() btcutil.Address
- func (b *Builder) ExecuteContract() error
- func (b *Builder) FixDeal(fm *oracle.SignedMsg, idxs []int) error
- func (b *Builder) FixedDealAmt() (btcutil.Amount, error)
- func (b *Builder) FundAmt() btcutil.Amount
- func (b *Builder) PrepareFundTx() error
- func (b *Builder) PreparePubkey() error
- func (b *Builder) PublicKey() ([]byte, error)
- func (b *Builder) SendFundTx() error
- func (b *Builder) SendRefundTx() error
- func (b *Builder) SetOraclePubkeySet(pubset *oracle.PubkeySet, idxs []int) error
- func (b *Builder) SignContractExecutionTx(deal *Deal, idx int) ([]byte, error)
- func (b *Builder) SignContractExecutionTxs() ([][]byte, error)
- func (b *Builder) SignFundTx() ([]wire.TxWitness, error)
- func (b *Builder) SignRefundTx() ([]byte, error)
- func (b *Builder) SignedClosingTx(cetx *wire.MsgTx) (*wire.MsgTx, error)
- func (b *Builder) SignedContractExecutionTx() (*wire.MsgTx, error)
- func (b *Builder) Utxos() []Utxo
- type ChangeAddressNotExistsError
- type Conditions
- type ConditionsJSON
- type Contractor
- type DLC
- func (d *DLC) AcceptCETxSignature(party Contractor, idx int, sig []byte) error
- func (d *DLC) Addresses() Addresses
- func (d *DLC) ChangeAddresses() Addresses
- func (d *DLC) ClosingTx(p Contractor, cetx *wire.MsgTx) (*wire.MsgTx, error)
- func (d *DLC) ContractAbandonmentTx(p Contractor) (*wire.MsgTx, error)
- func (d *DLC) ContractExecutionTx(party Contractor, deal *Deal, dID int) (*wire.MsgTx, error)
- func (d *DLC) ContractID() (string, error)
- func (d *DLC) Deal(idx int) (*Deal, error)
- func (d *DLC) DealByMsgs(msgs [][]byte) (idx int, deal *Deal, err error)
- func (d *DLC) DepositAmt(p Contractor) btcutil.Amount
- func (d *DLC) FixDeal(msgs [][]byte, sigs [][]byte) error
- func (d *DLC) FixedContractExecutionTx(p Contractor) (*wire.MsgTx, error)
- func (d *DLC) FixedDeal() (idx int, deal *Deal, err error)
- func (d *DLC) FundTx() (*wire.MsgTx, error)
- func (d *DLC) HasDealFixed() bool
- func (d *DLC) ParseAddresses(addrs Addresses) error
- func (d *DLC) ParseChangeAddresses(addrs Addresses) error
- func (d *DLC) ParsePublicKeys(pubs PublicKeys) error
- func (d *DLC) PrepareOracleCommitments(V *btcec.PublicKey, Rs []*btcec.PublicKey) error
- func (d *DLC) PublicKeys() PublicKeys
- func (d *DLC) RefundTx() (*wire.MsgTx, error)
- func (d *DLC) SignedFundTx() (*wire.MsgTx, error)
- func (d *DLC) SignedRefundTx() (*wire.MsgTx, error)
- func (d *DLC) VerifyRefundTx(sig []byte, pub *btcec.PublicKey) error
- type Deal
- type DealJSON
- type InvalidNetworkNameError
- type NoFixedDealError
- type NotEnoughFeesError
- type Oracle
- type OracleJSON
- type PremiumInfo
- type PremiumInfoJSON
- type PubkeyNotExistsError
- type PublicKeys
- type Utxo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct { Contract *DLC // contains filtered or unexported fields }
Builder builds DLC by interacting with wallet
func NewBuilder ¶
func NewBuilder( p Contractor, w wallet.Wallet, d *DLC) *Builder
NewBuilder createa a builder from DLC
func (*Builder) AcceptAdderss ¶
AcceptAdderss accepts address from the counterparty
func (*Builder) AcceptCETxSignatures ¶
AcceptCETxSignatures accepts CETx signatures received from the counterparty
func (*Builder) AcceptChangeAdderss ¶
AcceptChangeAdderss accepts change address from the counterparty
func (*Builder) AcceptFundWitnesses ¶
AcceptFundWitnesses accepts witnesses for fund txins owned by the counerparty
func (*Builder) AcceptPubkey ¶
AcceptPubkey accepts counter party's public key
func (*Builder) AcceptRefundTxSignature ¶
AcceptRefundTxSignature verifies couterparty's given signature is valid and then
func (*Builder) AcceptUtxos ¶
AcceptUtxos accepts utxos
func (*Builder) ChangeAddress ¶
ChangeAddress returns address to send change
func (*Builder) ExecuteContract ¶
ExecuteContract sends CETx and closing tx
func (*Builder) FixDeal ¶
FixDeal fixes a deal by a oracle's signature set by picking up required messages and sigs
func (*Builder) FixedDealAmt ¶
FixedDealAmt returns fixed amt that the party will receive
func (*Builder) PrepareFundTx ¶
PrepareFundTx prepares fundtx ins and out
func (*Builder) PreparePubkey ¶
PreparePubkey sets fund pubkey
func (*Builder) SendFundTx ¶
SendFundTx sends fund tx to the network
func (*Builder) SetOraclePubkeySet ¶
SetOraclePubkeySet sets oracle's pubkey set
func (*Builder) SignContractExecutionTx ¶
SignContractExecutionTx signs a contract execution tx for a given party
func (*Builder) SignContractExecutionTxs ¶
SignContractExecutionTxs signs contract execution txs for all deals
func (*Builder) SignFundTx ¶
SignFundTx signs fund tx and return witnesses for the txins owned by the party
func (*Builder) SignRefundTx ¶
SignRefundTx creates signature for a refund tx, sets it, and returns it
func (*Builder) SignedClosingTx ¶
SignedClosingTx constructs a closing tx with witness
func (*Builder) SignedContractExecutionTx ¶
SignedContractExecutionTx returns a contract execution tx signed by both parties TODO: separate SignedContractExecutionTx and SignContractExecutionTx
type ChangeAddressNotExistsError ¶
type ChangeAddressNotExistsError struct {
// contains filtered or unexported fields
}
ChangeAddressNotExistsError is raised when change address doesn't exist
type Conditions ¶
type Conditions struct { NetParams *chaincfg.Params `validate:"required"` FixingTime time.Time `validate:"required,gt=time.Now()"` FundAmts map[Contractor]btcutil.Amount `validate:"required,funds,dive,gte=0"` FundFeerate btcutil.Amount `validate:"required,gt=0"` // fund fee rate (satoshi per byte) RedeemFeerate btcutil.Amount `validate:"required,gt=0"` // redeem fee rate (satoshi per byte) RefundLockTime uint32 `validate:"required,gt=0"` // refund locktime (block height) Deals []*Deal `validate:"required,gt=0,dive,required"` PremiumInfo *PremiumInfo }
Conditions contains conditions of a contract
func NewConditions ¶
func NewConditions( net *chaincfg.Params, ftime time.Time, famt1, famt2 btcutil.Amount, ffeerate, rfeerate btcutil.Amount, refundLockTime uint32, deals []*Deal, info *PremiumInfo, ) (*Conditions, error)
NewConditions creates a new DLC conditions
func (*Conditions) MarshalJSON ¶
func (conds *Conditions) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler
func (*Conditions) UnmarshalJSON ¶
func (conds *Conditions) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler
type ConditionsJSON ¶
type ConditionsJSON struct { Net string `json:"network"` FixingTime int64 `json:"fixing_time"` FundAmts map[Contractor]int `json:"fund_amts"` FundFeerate int `json:"fund_feerate"` RedeemFeerate int `json:"redeem_feerate"` RefundLockTime uint32 `json:"refund_locktime"` Deals []*DealJSON `json:"deals"` PremiumInfo *PremiumInfoJSON `json:"premium_info"` }
ConditionsJSON is contract conditions in JSON format
type Contractor ¶
type Contractor int
Contractor represents a contractor type
const ( // FirstParty is a contractor who creates offer FirstParty Contractor = 0 // SecondParty is a contractor who accepts offer SecondParty Contractor = 1 )
func (Contractor) String ¶
func (p Contractor) String() string
String represents contractor in string format
type DLC ¶
type DLC struct { Conds *Conditions Oracle *Oracle Pubs map[Contractor]*btcec.PublicKey // pubkeys used for script and txout Addrs map[Contractor]btcutil.Address // addresses used to distribute funds after fixing deal ChangeAddrs map[Contractor]btcutil.Address // addresses used to send change Utxos map[Contractor][]*Utxo FundWits map[Contractor][]wire.TxWitness // TODO: change to fund signatures RefundSigs map[Contractor][]byte // signatures for refund tx ExecSigs [][]byte // counterparty's signatures for CETxs }
DLC contains all information required for DLC contract including FundTx, SettlementTx, RefundTx
func (*DLC) AcceptCETxSignature ¶
func (d *DLC) AcceptCETxSignature(party Contractor, idx int, sig []byte) error
AcceptCETxSignature sets a signature if it's valid for an identified CETx
func (*DLC) ChangeAddresses ¶
ChangeAddresses converts btcutil.Address to string
func (*DLC) ContractAbandonmentTx ¶
func (d *DLC) ContractAbandonmentTx(p Contractor) (*wire.MsgTx, error)
ContractAbandonmentTx creates tx that sends all fund to the counterparty Note: This transaction isn't useful in the realworld, but is necessary for PoC
func (*DLC) ContractExecutionTx ¶
ContractExecutionTx constructs a contract execution tx (CET) using pubkeys and given condition. Both parties have different transactions signed by the other side.
txins:
[0]:fund transaction output[0]
txouts:
[0]:settlement script [1]:p2wpkh (option)
func (*DLC) ContractID ¶
ContractID returns contract ID Use fund txid at this moment
func (*DLC) DealByMsgs ¶
DealByMsgs finds a deal by messages
func (*DLC) DepositAmt ¶
func (d *DLC) DepositAmt(p Contractor) btcutil.Amount
DepositAmt calculates fund amount + fees
func (*DLC) FixedContractExecutionTx ¶
func (d *DLC) FixedContractExecutionTx(p Contractor) (*wire.MsgTx, error)
FixedContractExecutionTx returns fixed CETx
func (*DLC) HasDealFixed ¶
HasDealFixed checks if a deal has been fixed
func (*DLC) ParseAddresses ¶
ParseAddresses parses address string
func (*DLC) ParseChangeAddresses ¶
ParseChangeAddresses parses address string
func (*DLC) ParsePublicKeys ¶
func (d *DLC) ParsePublicKeys(pubs PublicKeys) error
ParsePublicKeys parses public key hex strings
func (*DLC) PrepareOracleCommitments ¶
PrepareOracleCommitments prepares oracle's commitments for all deals
func (*DLC) PublicKeys ¶
func (d *DLC) PublicKeys() PublicKeys
PublicKeys converts btcec.PublicKey to hex string
func (*DLC) RefundTx ¶
RefundTx creates refund tx refund transaction input:
[0]:fund transaction output[0] Sequence (0xfeffffff LE)
output:
[0]:p2wpkh a [1]:p2wpkh b
locktime:
Value decided by contract.
func (*DLC) SignedFundTx ¶
SignedFundTx constructs signed fundtx
func (*DLC) SignedRefundTx ¶
SignedRefundTx returns a refund tx with its witness signature
type Deal ¶
type Deal struct { Amts map[Contractor]btcutil.Amount `validate:"required,dive,gte=0"` Msgs [][]byte `validate:"required,gt=0"` }
Deal contains information about the distributed amounts, commitment messages, and signatures of fixed messages
type DealJSON ¶
type DealJSON struct { Amts map[Contractor]int `json:"amts"` Msgs [][]byte `json:"msgs"` }
DealJSON is DLC deals in JSON format
type InvalidNetworkNameError ¶
type InvalidNetworkNameError struct {
// contains filtered or unexported fields
}
InvalidNetworkNameError is used when invalid network name is given
type NoFixedDealError ¶
type NoFixedDealError struct {
// contains filtered or unexported fields
}
NoFixedDealError is an error for a case when no deals has been fixed yet
type NotEnoughFeesError ¶
type NotEnoughFeesError struct {
// contains filtered or unexported fields
}
NotEnoughFeesError is an error that txins aren't enough for txouts
type Oracle ¶
type Oracle struct { PubkeySet *oracle.PubkeySet // Oracle's pubkey set Commitments []*btcec.PublicKey // Commitments for deals Sig []byte // Signature for a fixed deal SignedMsgs [][]byte // Messages signed by Oracle }
Oracle contains pubkeys and commitments and signature received from oracle
func (*Oracle) MarshalJSON ¶
MarshalJSON implements json.Marshaler
func (*Oracle) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler
type OracleJSON ¶
type OracleJSON struct { PubkeySet *oracle.PubkeySetJSON `json:"pubkey"` Commitments []string `json:"commitments"` Sig []byte `json:"sig"` SignedMsgs [][]byte `json:"signed_msgs"` }
OracleJSON is oracle information in JSON format
type PremiumInfo ¶
type PremiumInfo struct { PremiumDestAddress btcutil.Address `validate:"required"` PremiumAmount btcutil.Amount `validate:"required,gt=0"` PayingParty Contractor `validate:"oneof= 0 1"` }
func NewPremiumInfo ¶
func NewPremiumInfo(premiumAddress btcutil.Address, premiumAmount btcutil.Amount, payingParty Contractor) (*PremiumInfo, error)
type PremiumInfoJSON ¶
type PremiumInfoJSON struct { PremiumDestAddress string `json:"premium_dest_address"` PremiumAmount int `json:"premium_amount"` PayingParty int `json:"paying_party"` }
PremiumInfoJSON is PremiumInfo in JSON format
type PubkeyNotExistsError ¶
type PubkeyNotExistsError struct {
// contains filtered or unexported fields
}
PubkeyNotExistsError is error when either public key doesn't exist
type PublicKeys ¶
type PublicKeys map[Contractor]string
PublicKeys is public keys in hex string format