witness

package
v0.0.0-...-865e8ec Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TransferNew stands for a new transfer
	TransferNew TransferStatus = "new"
	// TransferPending stands for a pending transfer
	TransferPending = "pending"
	// TransferReady stands for a new transfer ready to sign
	TransferReady = "ready"
	// SubmissionConfirmed stands for a confirmed witness
	SubmissionConfirmed = "confirmed"
	// TransferSettled stands for a settled transfer
	TransferSettled = "settled"
	// TransferInvalid stands for an invalid transfer
	TransferInvalid = "invalid"

	// NoPayload is version without payload
	NoPayload Version = "no-payload"
	// Payload is version with payload
	Payload Version = "payload"
	// ToSolana is version with payload to solana
	ToSolana Version = "to-solana"
)

Variables

This section is empty.

Functions

func NewService

func NewService(
	cashiers []TokenCashier,
	batchSize uint16,
	processInterval time.Duration,
	disableSubmit bool,
) (*service, error)

NewService creates a new witness service

func StartServer

func StartServer(srv *service, grpcPort int, grpcProxyPort int)

Types

type AbstractRecorder

type AbstractRecorder interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	AddTransfer(tx AbstractTransfer, status TransferStatus) error
	UpsertTransfer(tx AbstractTransfer) error
	TipHeight(id string) (uint64, error)
	UpdateSyncHeight(id string, height uint64) error
	Transfer(id common.Hash) (AbstractTransfer, error)
	UnsettledTransfers() ([]string, error)
	TransfersToSubmit(string) ([]AbstractTransfer, error)
	TransfersToSettle(string) ([]AbstractTransfer, error)
	SettleTransfer(tx AbstractTransfer) error
	ConfirmTransfer(tx AbstractTransfer) error
	MarkTransferAsPending(tx AbstractTransfer) error
}

type AbstractTransfer

type AbstractTransfer interface {
	Cashier() util.Address
	Token() util.Address
	CoToken() util.Address
	Index() *big.Int
	Sender() util.Address
	Recipient() util.Address
	Payload() []byte
	Amount() *big.Int
	ID() []byte
	SetID(common.Hash)
	Status() TransferStatus
	BlockHeight() uint64
	ToTypesTransfer() *types.Transfer
}

type Recorder

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

Recorder is a logger based on sql to record exchange events

func NewRecorder

func NewRecorder(
	store *db.SQLStore,
	transferTableName string,
	tokenPairs map[common.Address]util.Address,
	tokenWhitelists map[common.Address]map[common.Address]struct{},
	tokenMintPairs map[string]util.Address,
	tokenRound map[common.Address]int,
	addrDecoder util.AddressDecoder,
) *Recorder

NewRecorder returns a recorder for exchange

func (*Recorder) AddTransfer

func (recorder *Recorder) AddTransfer(at AbstractTransfer, status TransferStatus) error

AddTransfer creates a new transfer record

func (*Recorder) AmountOfTransferred

func (recorder *Recorder) AmountOfTransferred(cashier, token common.Address) (*big.Int, error)

func (*Recorder) ConfirmTransfer

func (recorder *Recorder) ConfirmTransfer(at AbstractTransfer) error

ConfirmTransfer marks a record as confirmed

func (*Recorder) MarkTransferAsPending

func (recorder *Recorder) MarkTransferAsPending(at AbstractTransfer) error

MarkTransferAsPending marks a record as pending

func (*Recorder) SettleTransfer

func (recorder *Recorder) SettleTransfer(at AbstractTransfer) error

SettleTransfer marks a record as settled

func (*Recorder) Start

func (recorder *Recorder) Start(ctx context.Context) error

Start starts the recorder

func (*Recorder) Stop

func (recorder *Recorder) Stop(ctx context.Context) error

Stop stops the recorder

func (*Recorder) TipHeight

func (recorder *Recorder) TipHeight(cashier string) (uint64, error)

TipHeight returns the tip height of all the transfers in the recorder

func (*Recorder) Transfer

func (recorder *Recorder) Transfer(_id common.Hash) (AbstractTransfer, error)

func (*Recorder) TransfersToSettle

func (recorder *Recorder) TransfersToSettle(cashier string) ([]AbstractTransfer, error)

TransfersToSettle returns the list of transfers to confirm

func (*Recorder) TransfersToSubmit

func (recorder *Recorder) TransfersToSubmit(cashier string) ([]AbstractTransfer, error)

TransfersToSubmit returns the list of transfers to submit

func (*Recorder) UnsettledTransfers

func (recorder *Recorder) UnsettledTransfers() ([]string, error)

func (*Recorder) UpdateSyncHeight

func (recorder *Recorder) UpdateSyncHeight(cashier string, height uint64) error

func (*Recorder) UpsertTransfer

func (recorder *Recorder) UpsertTransfer(at AbstractTransfer) error

type SOLRecorder

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

SOLRecorder is the recorder for Solana

func NewSOLRecorder

func NewSOLRecorder(
	store *db.SQLStore,
	transferTableName string,
	tokenPairs map[solcommon.PublicKey]util.Address,
	tokenRound map[solcommon.PublicKey]int,
	addrDecoder util.AddressDecoder,
) *SOLRecorder

NewSOLRecorder returns a recorder for exchange

func (*SOLRecorder) AddTransfer

func (recorder *SOLRecorder) AddTransfer(at AbstractTransfer, status TransferStatus) error

AddTransfer creates a new transfer record

func (*SOLRecorder) ConfirmTransfer

func (recorder *SOLRecorder) ConfirmTransfer(at AbstractTransfer) error

ConfirmTransfer marks a record as confirmed

func (*SOLRecorder) MarkTransferAsPending

func (recorder *SOLRecorder) MarkTransferAsPending(at AbstractTransfer) error

MarkTransferAsPending marks a record as pending

func (*SOLRecorder) SettleTransfer

func (recorder *SOLRecorder) SettleTransfer(at AbstractTransfer) error

SettleTransfer marks a record as settled

func (*SOLRecorder) Start

func (recorder *SOLRecorder) Start(ctx context.Context) error

Start starts the recorder

func (*SOLRecorder) Stop

func (recorder *SOLRecorder) Stop(ctx context.Context) error

Stop stops the recorder

func (*SOLRecorder) TipHeight

func (recorder *SOLRecorder) TipHeight(cashier string) (uint64, error)

TipHeight returns the tip height of all the transfers in the recorder

func (*SOLRecorder) Transfer

func (recorder *SOLRecorder) Transfer(_ common.Hash) (AbstractTransfer, error)

func (*SOLRecorder) TransfersToSettle

func (recorder *SOLRecorder) TransfersToSettle(string) ([]AbstractTransfer, error)

TransfersToSettle returns the list of transfers to confirm

func (*SOLRecorder) TransfersToSubmit

func (recorder *SOLRecorder) TransfersToSubmit(string) ([]AbstractTransfer, error)

TransfersToSubmit returns the list of transfers to submit

func (*SOLRecorder) UnsettledTransfers

func (recorder *SOLRecorder) UnsettledTransfers() ([]string, error)

UnsettledTransfers returns the list of unsettled transfers

func (*SOLRecorder) UpdateSyncHeight

func (recorder *SOLRecorder) UpdateSyncHeight(cashier string, height uint64) error

func (*SOLRecorder) UpsertTransfer

func (recorder *SOLRecorder) UpsertTransfer(at AbstractTransfer) error

type Service

type Service interface {
	// Start starts the service
	Start(context.Context) error
	// Stop stops the service
	Stop(context.Context) error
}

Service manages to exchange iotex coin to ERC20 token on ethereum

type SignHandler

type SignHandler func(AbstractTransfer, []byte) (common.Hash, []byte, []byte, error)

func NewEd25519SignHandler

func NewEd25519SignHandler(privateKey *ed25519.PrivateKey) SignHandler

func NewSecp256k1SignHandler

func NewSecp256k1SignHandler(privateKey *ecdsa.PrivateKey) SignHandler

type TokenCashier

type TokenCashier interface {
	Start(context.Context) error
	Stop(context.Context) error
	ID() string
	GetRecorder() AbstractRecorder
	PullTransfersByHeight(blockHeight uint64) error
	PullTransfers(blockCount uint16) error
	SubmitTransfers() error
	CheckTransfers() error
	ProcessStales() error
}

TokenCashier defines the interface to pull transfers from chain in a block range

func NewTokenCashierOnEthereum

func NewTokenCashierOnEthereum(
	id string,
	version Version,
	relayerURL string,
	ethereumClient *ethclient.Client,
	cashierContractAddr common.Address,
	previousCashierAddr common.Address,
	tokenSafeContractAddr common.Address,
	validatorContractAddr []byte,
	recorder *Recorder,
	startBlockHeight uint64,
	confirmBlockNumber uint8,
	signHandler SignHandler,
	reverseRecorder *Recorder,
	reverseCashierContractAddr common.Address,
) (TokenCashier, error)

NewTokenCashierOnEthereum creates a new TokenCashier on ethereum

func NewTokenCashierOnSolana

func NewTokenCashierOnSolana(
	id string,
	relayerURL string,
	solanaClient *client.Client,
	cashier solcommon.PublicKey,
	validatorAddr common.Address,
	recorder *SOLRecorder,
	startBlockHeight uint64,
	qpsLimit uint32,
	signHandler SignHandler,
	disablePull bool,
) (TokenCashier, error)

type Transfer

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

Transfer defines a record

func (*Transfer) Amount

func (t *Transfer) Amount() *big.Int

func (*Transfer) BlockHeight

func (t *Transfer) BlockHeight() uint64

func (*Transfer) Cashier

func (t *Transfer) Cashier() util.Address

func (*Transfer) CoToken

func (t *Transfer) CoToken() util.Address

func (*Transfer) ID

func (t *Transfer) ID() []byte

func (*Transfer) Index

func (t *Transfer) Index() *big.Int

func (*Transfer) Payload

func (t *Transfer) Payload() []byte

func (*Transfer) Recipient

func (t *Transfer) Recipient() util.Address

func (*Transfer) Sender

func (t *Transfer) Sender() util.Address

func (*Transfer) SetID

func (t *Transfer) SetID(id common.Hash)

func (*Transfer) Status

func (t *Transfer) Status() TransferStatus

func (*Transfer) ToTypesTransfer

func (t *Transfer) ToTypesTransfer() *types.Transfer

func (*Transfer) Token

func (t *Transfer) Token() util.Address

type TransferStatus

type TransferStatus string

TransferStatus is the status of a transfer

type Version

type Version string

Version

Jump to

Keyboard shortcuts

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