bot

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SwapInvalid = iota
	SwapLocked
	SwapUnlocked
	SwapRefunded
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bch2SbchRecord

type Bch2SbchRecord struct {
	gorm.Model
	BchLockHeight    uint64         `gorm:"not null"` // got from tx
	BchLockTxHash    string         `gorm:"unique"`   // got from tx
	Value            uint64         `gorm:"not null"` // got from tx, in Sats
	RecipientPkh     string         `gorm:"not null"` // got from retData
	SenderPkh        string         `gorm:"not null"` // got from retData
	HashLock         string         `gorm:"unique"`   // got from retData, in Blocks
	TimeLock         uint32         `gorm:"not null"` // got from retData
	PenaltyBPS       uint16         `gorm:"not null"` // got from retData
	SenderEvmAddr    string         `gorm:"not null"` // got from retData
	HtlcScriptHash   string         `gorm:"not null"` // calculated
	SbchLockTxTime   uint64         ``                // set when status changed to Bch2SbchStatusSbchLocked
	SbchLockTxHash   string         ``                // set when status changed to Bch2SbchStatusSbchLocked
	SbchUnlockTxHash string         ``                // set when status changed to Bch2SbchStatusSecretRevealed
	Secret           string         ``                // set when status changed to Bch2SbchStatusSecretRevealed
	BchUnlockTxHash  string         ``                // set when status changed to Bch2SbchStatusBchUnlocked
	SbchRefundTxHash string         ``                // set when status changed to Bch2SbchStatusSbchRefunded
	Status           Bch2SbchStatus `gorm:"not null"` //
}

func (*Bch2SbchRecord) UpdateStatusToBchUnlocked added in v0.1.0

func (record *Bch2SbchRecord) UpdateStatusToBchUnlocked(bchUnlockTxHash string) *Bch2SbchRecord

func (*Bch2SbchRecord) UpdateStatusToSbchLocked added in v0.1.0

func (record *Bch2SbchRecord) UpdateStatusToSbchLocked(sbchLockTxHash string, sbchLockTxTime uint64) *Bch2SbchRecord

func (*Bch2SbchRecord) UpdateStatusToSbchRefunded added in v0.1.0

func (record *Bch2SbchRecord) UpdateStatusToSbchRefunded(sbchRefundTxHash string) *Bch2SbchRecord

func (*Bch2SbchRecord) UpdateStatusToSecretRevealed added in v0.1.0

func (record *Bch2SbchRecord) UpdateStatusToSecretRevealed(secret, sbchUnlockTxHash string) *Bch2SbchRecord

type Bch2SbchStatus

type Bch2SbchStatus int
const (
	Bch2SbchStatusNew Bch2SbchStatus = iota
	Bch2SbchStatusSbchLocked
	Bch2SbchStatusSecretRevealed
	Bch2SbchStatusBchUnlocked
	Bch2SbchStatusSbchRefunded
	Bch2SbchStatusTooLateToLockSbch
)

type BchClient

type BchClient struct {
	// contains filtered or unexported fields
}

func NewBchClient added in v0.1.0

func NewBchClient(rpcUrlStr string, botAddr bchutil.Address) (*BchClient, error)

func (*BchClient) SendTx added in v0.1.0

func (c *BchClient) SendTx(tx *wire.MsgTx) (*chainhash.Hash, error)

type DB

type DB struct {
	// contains filtered or unexported fields
}

func OpenDB

func OpenDB(dbFile string) (DB, error)

func (DB) GetAllBch2SbchRecords

func (db DB) GetAllBch2SbchRecords() (records []*Bch2SbchRecord, err error)

func (DB) GetAllSbch2BchRecords

func (db DB) GetAllSbch2BchRecords() (records []*Sbch2BchRecord, err error)

type IBchClient

type IBchClient interface {
	SendTx(tx *wire.MsgTx) (*chainhash.Hash, error)
	// contains filtered or unexported methods
}

type ISbchClient

type ISbchClient interface {
	// contains filtered or unexported methods
}

type LastHeights

type LastHeights struct {
	gorm.Model
	LastBchHeight  uint64
	LastSbchHeight uint64
}

type MarketMakerBot

type MarketMakerBot struct {
	// contains filtered or unexported fields
}

func NewBot

func NewBot(
	dbFile string,
	bchPrivKeyWIF, sbchPrivKeyHex string,
	bchMasterAddr, sbchMasterAddr string,
	bchRpcUrl, sbchRpcUrl string,
	sbchHtlcAddr gethcmn.Address,
	sbchGasPrice *big.Int,
	bchConfirmations uint8,
	bchSendMinerFeeRate, bchReceiveMinerFeeRate, bchRefundMinerFeeRate uint64,
	sbchLockGasLimit, sbchUnlockGasLimit, sbchRefundGasLimit uint64,
	dbQueryLimit int,
	debugMode bool,
	slaveMode bool,
	lazyMaster bool,
) (*MarketMakerBot, error)

func (*MarketMakerBot) GetUTXOs

func (bot *MarketMakerBot) GetUTXOs() ([]btcjson.ListUnspentResult, error)

func (*MarketMakerBot) Loop

func (bot *MarketMakerBot) Loop()

func (*MarketMakerBot) PrepareDB

func (bot *MarketMakerBot) PrepareDB()

type MockBchClient

type MockBchClient struct {
	// contains filtered or unexported fields
}

func (*MockBchClient) SendTx added in v0.1.0

func (c *MockBchClient) SendTx(tx *wire.MsgTx) (*chainhash.Hash, error)

type MockSbchClient

type MockSbchClient struct {
	// contains filtered or unexported fields
}

type Sbch2BchRecord

type Sbch2BchRecord struct {
	gorm.Model
	SbchLockTime     uint64         `gorm:"not null"` // got from event
	SbchLockTxHash   string         `gorm:"unique"`   // got from event
	Value            uint64         `gorm:"not null"` // got from txValue, in Sats
	SbchSenderAddr   string         `gorm:"not null"` // got from event
	BchRecipientPkh  string         `gorm:"not null"` // got from event
	HashLock         string         `gorm:"unique"`   // got from event
	TimeLock         uint32         `gorm:"not null"` // got from event, in Seconds
	PenaltyBPS       uint16         `gorm:"not null"` // got from event
	HtlcScriptHash   string         `gorm:"not null"` // calculated by bot
	BchLockTxHash    string         ``                // set when status changed to Sbch2BchStatusBchLocked
	BchUnlockTxHash  string         ``                // set when status changed to Sbch2BchStatusSecretRevealed
	Secret           string         ``                // set when status changed to Sbch2BchStatusSecretRevealed
	SbchUnlockTxHash string         ``                // set when status changed to Sbch2BchStatusSbchUnlocked
	BchRefundTxHash  string         ``                // set when status changed to Sbch2BchStatusBchRefunded
	Status           Sbch2BchStatus `gorm:"not null"` //
}

func (*Sbch2BchRecord) UpdateStatusToBchLocked added in v0.1.0

func (record *Sbch2BchRecord) UpdateStatusToBchLocked(bchLockTxHash string) *Sbch2BchRecord

func (*Sbch2BchRecord) UpdateStatusToBchRefunded added in v0.1.0

func (record *Sbch2BchRecord) UpdateStatusToBchRefunded(bchRefundTxHash string) *Sbch2BchRecord

func (*Sbch2BchRecord) UpdateStatusToSbchUnlocked added in v0.1.0

func (record *Sbch2BchRecord) UpdateStatusToSbchUnlocked(sbchUnlockTxHash string) *Sbch2BchRecord

func (*Sbch2BchRecord) UpdateStatusToSecretRevealed added in v0.1.0

func (record *Sbch2BchRecord) UpdateStatusToSecretRevealed(secret, bchUnlockTxHash string) *Sbch2BchRecord

type Sbch2BchStatus

type Sbch2BchStatus int
const (
	Sbch2BchStatusNew Sbch2BchStatus = iota
	Sbch2BchStatusBchLocked
	Sbch2BchStatusSecretRevealed
	Sbch2BchStatusSbchUnlocked
	Sbch2BchStatusBchRefunded
	Sbch2BchStatusTooLateToLockBch
)

type SbchClient

type SbchClient struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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