txsender

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package txsender provides a common Sender interface for swapd instances. Each Sender implementation is responsible for signing and submitting transactions to the network. privateKeySender is the implementation using an ethereum private key directly managed by swapd. ExternalSender provides an API for interacting with an external entity like Metamask.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExternalSender

type ExternalSender struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ExternalSender represents a transaction signer and sender that is external to the daemon (ie. a front-end)

func NewExternalSender

func NewExternalSender(
	ctx context.Context,
	env common.Environment,
	ec *ethclient.Client,
	contractAddr ethcommon.Address,
	erc20Addr ethcommon.Address,
) (*ExternalSender, error)

NewExternalSender returns a new ExternalSender

func (*ExternalSender) Claim

func (s *ExternalSender) Claim(
	swap *contracts.SwapCreatorSwap,
	secret [32]byte,
) (*ethtypes.Receipt, error)

Claim prompts the external sender to sign a claim transaction

func (*ExternalSender) IncomingCh

func (s *ExternalSender) IncomingCh(_ types.Hash) chan<- ethcommon.Hash

IncomingCh returns the channel of incoming transaction hashes that have been signed and submitted

func (*ExternalSender) NewSwap

func (s *ExternalSender) NewSwap(
	claimCommitment [32]byte,
	refundCommitment [32]byte,
	claimer ethcommon.Address,
	timeoutDuration *big.Int,
	nonce *big.Int,
	amount coins.EthAssetAmount,
	saveNewSwapTxCallback func(txHash ethcommon.Hash) error,
) (*ethtypes.Receipt, error)

NewSwap prompts the external sender to sign a new_swap transaction

func (*ExternalSender) OngoingCh

func (s *ExternalSender) OngoingCh(_ types.Hash) <-chan *Transaction

OngoingCh returns the channel of outgoing transactions to be signed and submitted

func (*ExternalSender) Refund

func (s *ExternalSender) Refund(
	swap *contracts.SwapCreatorSwap,
	secret [32]byte,
) (*ethtypes.Receipt, error)

Refund prompts the external sender to sign a refund transaction

func (*ExternalSender) SetReady

SetReady prompts the external sender to sign a set_ready transaction

func (*ExternalSender) SetSwapCreator

func (s *ExternalSender) SetSwapCreator(_ *contracts.SwapCreator)

SetSwapCreator sets the bound contract for the SwapCreator

func (*ExternalSender) SetSwapCreatorAddr

func (s *ExternalSender) SetSwapCreatorAddr(addr ethcommon.Address)

SetSwapCreatorAddr sets the address of the SwapCreator contract

type Sender

type Sender interface {
	SetSwapCreator(*contracts.SwapCreator)
	SetSwapCreatorAddr(ethcommon.Address)
	NewSwap(
		claimCommitment [32]byte,
		refundCommitment [32]byte,
		claimer ethcommon.Address,
		timeoutDuration *big.Int,
		nonce *big.Int,
		amount coins.EthAssetAmount,
		saveNewSwapTxCallback func(txHash ethcommon.Hash) error,
	) (*ethtypes.Receipt, error)
	SetReady(swap *contracts.SwapCreatorSwap) (*ethtypes.Receipt, error)
	Claim(swap *contracts.SwapCreatorSwap, secret [32]byte) (*ethtypes.Receipt, error)
	Refund(swap *contracts.SwapCreatorSwap, secret [32]byte) (*ethtypes.Receipt, error)
}

Sender signs and submits transactions to the chain

func NewSenderWithPrivateKey

func NewSenderWithPrivateKey(
	ctx context.Context,
	ethClient extethclient.EthClient,
	swapCreatorAddr ethcommon.Address,
	swapCreator *contracts.SwapCreator,
	erc20Contract *contracts.IERC20,
) Sender

NewSenderWithPrivateKey returns a new *privateKeySender

type Transaction

type Transaction struct {
	To    ethcommon.Address
	Data  []byte
	Value *apd.Decimal // ETH (or ETH asset), not WEI
}

Transaction represents a transaction to be signed by the front-end

Jump to

Keyboard shortcuts

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