trans

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: Apache-2.0, MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockFil

type MockFil struct {
	Server *httptest.Server

	Lock sync.RWMutex

	Height     int
	PaychBals  map[string]*big.Int
	PaychStats map[string]*paych8.State
	// contains filtered or unexported fields
}

MockFil is a mocked filecoin network.

func NewMockFil

func NewMockFil(blockTime time.Duration) *MockFil

NewMockFil starts a new mocked filecoin network.

@output - mocked fil.

func (*MockFil) ChainHead

func (m *MockFil) ChainHead(ctx context.Context) (*types.TipSet, error)

Lotus API mock: ChainHead.

func (*MockFil) ChainReadObj

func (m *MockFil) ChainReadObj(ctx context.Context, cid cid.Cid) ([]byte, error)

Lotus API mock: ChainReadObj.

func (*MockFil) GasEstimateFeeCap

func (m *MockFil) GasEstimateFeeCap(context.Context, *types.Message, int64, types.TipSetKey) (types.BigInt, error)

Lotus API mock: GasEstimateFeeCap.

func (*MockFil) GasEstimateGasLimit

func (m *MockFil) GasEstimateGasLimit(context.Context, *types.Message, types.TipSetKey) (int64, error)

Lotus API mock: GasEstimateGasLimit.

func (*MockFil) GasEstimateGasPremium

func (m *MockFil) GasEstimateGasPremium(context.Context, uint64, address.Address, int64, types.TipSetKey) (types.BigInt, error)

Lotus API mock: GasEstimateGasPremium.

func (*MockFil) GetAPI

func (m *MockFil) GetAPI() string

GetAPI gets the API address.

@output - api address.

func (*MockFil) MpoolGetNonce

func (m *MockFil) MpoolGetNonce(context.Context, address.Address) (uint64, error)

Lotus API mock: MpoolGetNonce.

func (*MockFil) MpoolPush

func (m *MockFil) MpoolPush(ctx context.Context, msg *types.SignedMessage) (cid.Cid, error)

Lotus API mock: MpoolPush.

func (*MockFil) Shutdown

func (m *MockFil) Shutdown()

Shutdown shuts down the mocked filecoin network.

func (*MockFil) StateAccountKey

func (m *MockFil) StateAccountKey(ctx context.Context, addr address.Address, tx types.TipSetKey) (address.Address, error)

Lotus API mock: StateAccountKey.

func (*MockFil) StateGetActor

func (m *MockFil) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error)

Lotus API mock: StateGetActor.

func (*MockFil) StateWaitMsg

func (m *MockFil) StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64) (*api.MsgLookup, error)

Lotus API mock: StateWaitMsg.

type Opts

type Opts struct {
	/* Filecoin related */
	// Boolean indicate if Filecoin is enabled.
	FilecoinEnabled bool

	// Filecoin network API address.
	FilecoinAPI string

	// Filecoin API auth token (empty if using Infura).
	FilecoinAuthToken string

	// Filecoin confidence epoch.
	FilecoinConfidence *uint64
}

Opts is the options for the transactor.

type Transactor

type Transactor interface {
	// Create is used to create a payment chanel with given recipient and amount.
	//
	// @input - context, currency id, recipient address, amount.
	//
	// @output - channel address, error.
	Create(ctx context.Context, currencyID byte, toAddr string, amt *big.Int) (string, error)

	// Topup is used to topup a given payment channel with given amount.
	//
	// @input - context, currency id, channel address, amount.
	//
	// @output - error.
	Topup(ctx context.Context, currencyID byte, chAddr string, amt *big.Int) error

	// Check is used to check the status of a given payment channel.
	//
	// @input - context, currency id, channel address.
	//
	// @output - settling height, min settling height, current height, channel redeemed, channel balance, sender address, recipient address and error.
	Check(ctx context.Context, currencyID byte, chAddr string) (int64, int64, int64, *big.Int, *big.Int, string, string, error)

	// Update is used to update channel state with a voucher.
	//
	// @input - context, currency id, channel address, voucher.
	//
	// @output - error.
	Update(ctx context.Context, currencyID byte, chAddr string, voucher string) error

	// Settle is used to settle a payment channel.
	//
	// @input - context, currency id, channel address.
	//
	// @output - error.
	Settle(ctx context.Context, currencyID byte, chAddr string) error

	// Collect is used to collect a payment channel.
	//
	// @input - context, currency id, channel address.
	//
	// @output - error.
	Collect(ctx context.Context, currencyID byte, chAddr string) error

	// GenerateVoucher is used to generate a voucher.
	//
	// @input - context, currency id, channel address, lane number, nonce, redeemed amount.
	//
	// @output - voucher, error.
	GenerateVoucher(ctx context.Context, currencyID byte, chAddr string, lane uint64, nonce uint64, redeemed *big.Int) (string, error)

	// VerifyVoucher is used to decode a given voucher.
	//
	// @input - currency id, voucher.
	//
	// @output - sender address, channel address, lane number, nonce, redeemed, error.
	VerifyVoucher(currencyID byte, voucher string) (string, string, uint64, uint64, *big.Int, error)

	// GetHeight is used to get the current height of the chain.
	//
	// @input - context, currency id.
	//
	// @output - height, error.
	GetHeight(ctx context.Context, currencyID byte) (int64, error)

	// GetBalance is used to get the balance of a given address.
	//
	// @input - context, currency id, address.
	//
	// @output - balance, error.
	GetBalance(ctx context.Context, currencyID byte, addr string) (*big.Int, error)
}

Transactor is the interface for an on-chain transactor. For each currency id, it can be used to access payment channel related on-chain transactions. The transactor uses the private key stored in the signer to sign and send transactions.

type TransactorImpl

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

TransactorImpl is the implementation of the Transactor interface.

func NewTransactorImpl

func NewTransactorImpl(ctx context.Context, signer crypto.Signer, opts Opts) (*TransactorImpl, error)

NewTransactorImpl creates a new TransactorImpl.

@input - context, signer, options.

@output - store, error.

func (*TransactorImpl) Check

func (t *TransactorImpl) Check(ctx context.Context, currencyID byte, chAddr string) (int64, int64, int64, *big.Int, *big.Int, string, string, error)

Check is used to check the status of a given payment channel.

@input - context, currency id, channel address.

@output - settling height, min settling height, current height, channel redeemed, channel balance, sender address, recipient address and error.

func (*TransactorImpl) Collect

func (t *TransactorImpl) Collect(ctx context.Context, currencyID byte, chAddr string) error

Collect is used to collect a payment channel.

@input - context, currency id, channel address.

@output - error.

func (*TransactorImpl) Create

func (t *TransactorImpl) Create(ctx context.Context, currencyID byte, toAddr string, amt *big.Int) (string, error)

Create is used to create a payment chanel with given recipient and amount.

@input - context, currency id, recipient address, amount.

@output - channel address, error.

func (*TransactorImpl) GenerateVoucher

func (t *TransactorImpl) GenerateVoucher(ctx context.Context, currencyID byte, chAddr string, lane uint64, nonce uint64, redeemed *big.Int) (string, error)

GenerateVoucher is used to generate a voucher.

@input - context, currency id, channel address, lane number, nonce, redeemed amount.

@output - voucher, error.

func (*TransactorImpl) GetBalance

func (t *TransactorImpl) GetBalance(ctx context.Context, currencyID byte, addr string) (*big.Int, error)

GetBalance is used to get the balance of a given address.

@input - context, currency id, address.

@output - balance, error.

func (*TransactorImpl) GetHeight

func (t *TransactorImpl) GetHeight(ctx context.Context, currencyID byte) (int64, error)

GetHeight is used to get the current height of the chain.

@input - context, currency id.

@output - height, error.

func (*TransactorImpl) Settle

func (t *TransactorImpl) Settle(ctx context.Context, currencyID byte, chAddr string) error

Settle is used to settle a payment channel.

@input - context, currency id, channel address.

@output - error.

func (*TransactorImpl) Topup

func (t *TransactorImpl) Topup(ctx context.Context, currencyID byte, chAddr string, amt *big.Int) error

Topup is used to topup a given payment channel with given amount.

@input - context, currency id, channel address, amount.

@output - error.

func (*TransactorImpl) Update

func (t *TransactorImpl) Update(ctx context.Context, currencyID byte, chAddr string, voucher string) error

Update is used to update channel state with a voucher.

@input - context, currency id, channel address, voucher.

@output - error.

func (*TransactorImpl) VerifyVoucher

func (t *TransactorImpl) VerifyVoucher(currencyID byte, voucher string) (string, string, uint64, uint64, *big.Int, error)

VerifyVoucher is used to decode a given voucher.

@input - currency id, voucher.

@output - sender address, channel address, lane number, nonce, redeemed, error.

Jump to

Keyboard shortcuts

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