contract

package
v0.0.0-...-31898ba Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: ISC Imports: 9 Imported by: 0

Documentation

Overview

This package offers a storage for and basic manupulations with contracts used in the TumbleBit protocol.

Index

Constants

View Source
const (
	ReceiverAddress addressRole = iota
	RedeemAddress
	RefundAddress
	SenderAddress
	MaxAddressRole
)
View Source
const (
	PayToEdwardsPubKey addressType = 1 << iota
	PayToPubKey
	PayToPubKeyHash
	PayToSecSchnorrPubKey
	PayToScriptHash
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Contract

type Contract struct {
	// Generic sender and receiver of funds.
	SenderAddr         dcrutil.Address
	SenderAddrStr      string
	SenderScriptAddr   []byte
	ReceiverAddr       dcrutil.Address
	ReceiverAddrStr    string
	ReceiverScriptAddr []byte

	// Escrow set up by the tumbler or the client.
	EscrowTx        *wire.MsgTx
	EscrowBytes     []byte
	EscrowAddr      dcrutil.Address // P2SH address
	EscrowAddrStr   string
	EscrowPayScript []byte
	EscrowScript    []byte
	EscrowSig       []byte // transaction signature (same for all)
	EscrowHash      []byte // published transaction hash (same for all)

	// Refunding transaction used with an escrow that tumbler sets up.
	RefundTx         *wire.MsgTx
	RefundBytes      []byte
	RefundAddr       dcrutil.Address
	RefundAddrStr    string
	RefundScript     []byte
	RefundScriptAddr []byte
	RefundSig        []byte
	RefundHash       []byte

	// Fulfill the offer transaction and redeem escrowed funds.
	RedeemTx         *wire.MsgTx
	RedeemBytes      []byte
	RedeemAddr       dcrutil.Address
	RedeemAddrStr    string
	RedeemScript     []byte
	RedeemScriptAddr []byte
	RedeemSig        []byte
	RedeemHash       []byte

	Amount      int64
	LockTime    int32
	ChainParams *chaincfg.Params
}

Contract structure represents the contract associated with a client.

func New

func New(chainParams *chaincfg.Params, amount int64, lockTime int32) (*Contract, error)

New creates a new contract template that can be either refunded by refundAddr or redeemed by redeemAddr for a specified amount and after the specified locktime.

func (*Contract) AddEscrowScript

func (con *Contract) AddEscrowScript() error

func (*Contract) AddOfferScript

func (con *Contract) AddOfferScript(hashes [][]byte, hashOp byte) error

func (*Contract) AddRedeemScript

func (con *Contract) AddRedeemScript(secrets [][]byte) error

AddRedeemScript creates a redeem script to complete the escrow script.

func (*Contract) AddRefundScript

func (con *Contract) AddRefundScript() error

AddRefundScript creates a refund script to complete the escrow script.

func (*Contract) BuildRedeemTx

func (con *Contract) BuildRedeemTx(sigScriptAddSize int) error

func (*Contract) BuildRefundTx

func (con *Contract) BuildRefundTx() error

BuildRefundTx creates a refund transaction that spends escrowed funds.

func (*Contract) ExtractRedeemDataPushes

func (con *Contract) ExtractRedeemDataPushes(in uint32) ([][]byte, error)

func (*Contract) SetAddress

func (c *Contract) SetAddress(t addressRole, a, pk string) error

SetAddress sets an address in the contract according to the role specified by the address type. It panics when called with an incorrect address type, otherwise address is decoded and verified to be valid in the selected network.

func (*Contract) String

func (c *Contract) String() string

func (*Contract) VerifyRedeemTx

func (con *Contract) VerifyRedeemTx() error

func (*Contract) VerifyRefundTx

func (con *Contract) VerifyRefundTx() error

VerifyRefundTx makes sure that resulting refund script executes correctly.

Jump to

Keyboard shortcuts

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