fees

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FeeManagerDBFileName = "feemanager.db"
)

Variables

View Source
var (
	ErrMinimumFeeAmount    = errors.New("insufficient fee amount")
	ErrInsufficientBalance = errors.New("insufficient balance for transaction")
	ErrInvalidPartition    = errors.New("pending fee credit process for another partition")
)

Functions

This section is empty.

Types

type AddFeeCmd

type AddFeeCmd struct {
	AccountIndex   uint64
	Amount         uint64
	DisableLocking bool // if true then lockFC transaction is not sent before adding fee credit
}

type AddFeeCmdResponse

type AddFeeCmdResponse struct {
	Proofs []*AddFeeTxProofs
}

type AddFeeCreditCtx

type AddFeeCreditCtx struct {
	TargetPartitionID types.PartitionID       `json:"targetPartitionId"`           // target partition id where the fee is being added to
	TargetBillID      types.UnitID            `json:"targetBillId"`                // transferFC target bill id
	TargetBillCounter uint64                  `json:"targetBillCounter"`           // transferFC target bill counter
	TargetAmount      uint64                  `json:"targetAmount"`                // the amount to add to the fee credit record
	LockingDisabled   bool                    `json:"lockingDisabled,omitempty"`   // user defined flag if we should lock fee credit record when adding fees
	FeeCreditRecordID types.UnitID            `json:"feeCreditRecordId,omitempty"` // the fee credit record id used in current fee credit process
	LockFCTx          *types.TransactionOrder `json:"lockFCTx,omitempty"`
	LockFCProof       *types.TxRecordProof    `json:"lockFCProof,omitempty"`
	TransferFCTx      *types.TransactionOrder `json:"transferFCTx,omitempty"`
	TransferFCProof   *types.TxRecordProof    `json:"transferFCProof,omitempty"`
	AddFCTx           *types.TransactionOrder `json:"addFCTx,omitempty"`
	AddFCProof        *types.TxRecordProof    `json:"addFCProof,omitempty"`
}

type AddFeeTxProofs

type AddFeeTxProofs struct {
	LockFC     *types.TxRecordProof
	TransferFC *types.TxRecordProof
	AddFC      *types.TxRecordProof
}

func (*AddFeeTxProofs) GetFees

func (p *AddFeeTxProofs) GetFees() uint64

type BoltStore

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

func NewBoltStore

func NewBoltStore(dbFile string) (*BoltStore, error)

func NewFeeManagerDB

func NewFeeManagerDB(dir string) (*BoltStore, error)

func (*BoltStore) Close

func (s *BoltStore) Close() error

func (*BoltStore) DeleteAddFeeContext

func (s *BoltStore) DeleteAddFeeContext(accountID []byte) error

func (*BoltStore) DeleteReclaimFeeContext

func (s *BoltStore) DeleteReclaimFeeContext(accountID []byte) error

func (*BoltStore) GetAddFeeContext

func (s *BoltStore) GetAddFeeContext(accountID []byte) (*AddFeeCreditCtx, error)

func (*BoltStore) GetReclaimFeeContext

func (s *BoltStore) GetReclaimFeeContext(accountID []byte) (*ReclaimFeeCreditCtx, error)

func (*BoltStore) SetAddFeeContext

func (s *BoltStore) SetAddFeeContext(accountID []byte, feeCtx *AddFeeCreditCtx) error

func (*BoltStore) SetReclaimFeeContext

func (s *BoltStore) SetReclaimFeeContext(accountID []byte, feeCtx *ReclaimFeeCreditCtx) error

type FeeManager

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

func NewFeeManager

func NewFeeManager(
	networkID types.NetworkID,
	am account.Manager,
	db FeeManagerDB,
	moneyPartitionID types.PartitionID,
	moneyClient sdktypes.MoneyPartitionClient,
	moneyPartitionFcrIDFn GenerateFcrID,
	targetPartitionPartitionID types.PartitionID,
	targetPartitionClient sdktypes.PartitionClient,
	targetPartitionFcrIDFn GenerateFcrID,
	maxFee uint64,
	log *slog.Logger,
) *FeeManager

NewFeeManager creates new fee credit manager. Parameters: - account manager - fee manager db

- money partition:

  • partitionID
  • rpc node client
  • fee credit record id generation function
  • fee credit record unit type part

- target partition:

  • partitionID
  • rpc node client
  • fee credit record id generation function
  • fee credit record unit type part

func (*FeeManager) AddFeeCredit

func (w *FeeManager) AddFeeCredit(ctx context.Context, cmd AddFeeCmd) (*AddFeeCmdResponse, error)

AddFeeCredit creates fee credit for the given amount. If the wallet does not have a bill large enough for the required amount, multiple bills are used until the target amount is reached. In case of partial add (the add process was previously left in an incomplete state) only the partial bill is added to fee credit. Returns transaction proofs that were used to add credit.

func (*FeeManager) Close

func (w *FeeManager) Close()

Close propagates call to all dependencies

func (*FeeManager) GetFeeCredit

func (w *FeeManager) GetFeeCredit(ctx context.Context, cmd GetFeeCreditCmd) (*sdktypes.FeeCreditRecord, error)

GetFeeCredit returns fee credit record for given account, returns nil if fee credit record has not been created yet.

func (*FeeManager) LockFeeCredit

func (w *FeeManager) LockFeeCredit(ctx context.Context, cmd LockFeeCreditCmd) (*types.TxRecordProof, error)

LockFeeCredit locks fee credit record for given account, returns error if fee credit record has not been created yet or is already locked.

func (*FeeManager) MinAddFeeAmount

func (w *FeeManager) MinAddFeeAmount() uint64

func (*FeeManager) MinReclaimFeeAmount

func (w *FeeManager) MinReclaimFeeAmount() uint64

func (*FeeManager) ReclaimFeeCredit

func (w *FeeManager) ReclaimFeeCredit(ctx context.Context, cmd ReclaimFeeCmd) (*ReclaimFeeCmdResponse, error)

ReclaimFeeCredit reclaims fee credit i.e. reclaims entire fee credit record balance back to the main balance. Reclaimed fee credit is added to the largest bill in wallet. Returns transaction proofs that were used to reclaim fee credit.

func (*FeeManager) UnlockFeeCredit

func (w *FeeManager) UnlockFeeCredit(ctx context.Context, cmd UnlockFeeCreditCmd) (*types.TxRecordProof, error)

UnlockFeeCredit unlocks fee credit record for given account, returns error if fee credit record has not been created yet or is already unlocked.

type FeeManagerDB

type FeeManagerDB interface {
	GetAddFeeContext(accountID []byte) (*AddFeeCreditCtx, error)
	SetAddFeeContext(accountID []byte, feeCtx *AddFeeCreditCtx) error
	DeleteAddFeeContext(accountID []byte) error
	GetReclaimFeeContext(accountID []byte) (*ReclaimFeeCreditCtx, error)
	SetReclaimFeeContext(accountID []byte, feeCtx *ReclaimFeeCreditCtx) error
	DeleteReclaimFeeContext(accountID []byte) error
	Close() error
}

type GenerateFcrID

type GenerateFcrID func(shardPart, pubKey []byte, latestAdditionTime uint64) (types.UnitID, error)

GenerateFcrID function to generate fee credit record ID

type GetFeeCreditCmd

type GetFeeCreditCmd struct {
	AccountIndex uint64
}

type LockFeeCreditCmd

type LockFeeCreditCmd struct {
	AccountIndex uint64
	LockStatus   uint64
}

type ReclaimFeeCmd

type ReclaimFeeCmd struct {
	AccountIndex   uint64
	DisableLocking bool // if true then lock transaction is not sent before reclaiming fee credit
}

type ReclaimFeeCmdResponse

type ReclaimFeeCmdResponse struct {
	Proofs *ReclaimFeeTxProofs
}

type ReclaimFeeCreditCtx

type ReclaimFeeCreditCtx struct {
	TargetPartitionID types.PartitionID       `json:"targetPartitionId"` // target partition id where the fee credit is being reclaimed from
	TargetBillID      []byte                  `json:"targetBillId"`      // closeFC target bill id
	TargetBillCounter uint64                  `json:"targetBillCounter"` // closeFC target bill counter
	LockingDisabled   bool                    `json:"lockingDisabled,omitempty"`
	LockTx            *types.TransactionOrder `json:"lockTx,omitempty"`
	LockTxProof       *types.TxRecordProof    `json:"lockTxProof,omitempty"`
	CloseFCTx         *types.TransactionOrder `json:"closeFCTx,omitempty"`
	CloseFCProof      *types.TxRecordProof    `json:"closeFCProof,omitempty"`
	ReclaimFCTx       *types.TransactionOrder `json:"reclaimFCTx,omitempty"`
	ReclaimFCProof    *types.TxRecordProof    `json:"reclaimFCProof,omitempty"`
}

type ReclaimFeeTxProofs

type ReclaimFeeTxProofs struct {
	Lock      *types.TxRecordProof
	CloseFC   *types.TxRecordProof
	ReclaimFC *types.TxRecordProof
}

func (*ReclaimFeeTxProofs) GetFees

func (p *ReclaimFeeTxProofs) GetFees() uint64

type UnlockFeeCreditCmd

type UnlockFeeCreditCmd struct {
	AccountIndex uint64
}

Jump to

Keyboard shortcuts

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