fees

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FeeManagerDBFileName = "feemanager.db"
)
View Source
const (
	MinimumFeeAmount = 4 * txbuilder.MaxFee
)

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.SystemID          `json:"targetPartitionId"`         // target partition id where the fee is being added to
	TargetBillID       []byte                  `json:"targetBillId"`              // transferFC target bill id
	TargetBillBacklink []byte                  `json:"targetBillBacklink"`        // transferFC target bill backlink
	TargetAmount       uint64                  `json:"targetAmount"`              // the amount to add to the fee credit bill
	LockingDisabled    bool                    `json:"lockingDisabled,omitempty"` // user defined flag if we should lock fee credit record when adding fees
	LockFCTx           *types.TransactionOrder `json:"lockFCTx,omitempty"`
	LockFCProof        *wallet.Proof           `json:"lockFCProof,omitempty"`
	TransferFCTx       *types.TransactionOrder `json:"transferFCTx,omitempty"`
	TransferFCProof    *wallet.Proof           `json:"transferFCProof,omitempty"`
	AddFCTx            *types.TransactionOrder `json:"addFCTx,omitempty"`
	AddFCProof         *wallet.Proof           `json:"addFCProof,omitempty"`
}

type AddFeeTxProofs

type AddFeeTxProofs struct {
	LockFC     *wallet.Proof
	TransferFC *wallet.Proof
	AddFC      *wallet.Proof
}

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(
	am account.Manager,
	db FeeManagerDB,
	moneySystemID types.SystemID,
	moneyClient RpcClient,
	moneyPartitionFcrIDFn GenerateFcrIDFromPublicKey,
	targetPartitionSystemID types.SystemID,
	targetPartitionClient RpcClient,
	fcrIDFn GenerateFcrIDFromPublicKey,
	log *slog.Logger,
) *FeeManager

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

- money partition:

  • systemID
  • rpc node client
  • fee credit record id generation function

- target partition:

  • systemID
  • rpc node client
  • fee credit record id generation function

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) (*api.FeeCreditBill, error)

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

func (*FeeManager) LockFeeCredit

func (w *FeeManager) LockFeeCredit(ctx context.Context, cmd LockFeeCreditCmd) (*wallet.Proof, error)

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

func (*FeeManager) ReclaimFeeCredit

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

ReclaimFeeCredit reclaims fee credit i.e. reclaims entire fee credit bill 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) (*wallet.Proof, error)

UnlockFeeCredit unlocks fee credit bill for given account, returns error if fee credit bill 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 GenerateFcrIDFromPublicKey

type GenerateFcrIDFromPublicKey func(shardPart, pubKey []byte) types.UnitID

GenerateFcrIDFromPublicKey function to generate fee credit UnitID from shard number nad public key

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.SystemID          `json:"targetPartitionId"`  // target partition id where the fee credit is being reclaimed from
	TargetBillID       []byte                  `json:"targetBillId"`       // closeFC target bill id
	TargetBillBacklink []byte                  `json:"targetBillBacklink"` // closeFC target bill backlink
	LockingDisabled    bool                    `json:"lockingDisabled,omitempty"`
	LockTx             *types.TransactionOrder `json:"lockTx,omitempty"`
	LockTxProof        *wallet.Proof           `json:"lockTxProof,omitempty"`
	CloseFCTx          *types.TransactionOrder `json:"closeFCTx,omitempty"`
	CloseFCProof       *wallet.Proof           `json:"closeFCProof,omitempty"`
	ReclaimFCTx        *types.TransactionOrder `json:"reclaimFCTx,omitempty"`
	ReclaimFCProof     *wallet.Proof           `json:"reclaimFCProof,omitempty"`
}

type ReclaimFeeTxProofs

type ReclaimFeeTxProofs struct {
	Lock      *wallet.Proof
	CloseFC   *wallet.Proof
	ReclaimFC *wallet.Proof
}

func (*ReclaimFeeTxProofs) GetFees

func (p *ReclaimFeeTxProofs) GetFees() uint64

type RpcClient added in v0.4.0

type RpcClient interface {
	GetRoundNumber(ctx context.Context) (uint64, error)
	GetBill(ctx context.Context, unitID types.UnitID, includeStateProof bool) (*api.Bill, error)
	GetFeeCreditRecord(ctx context.Context, unitID types.UnitID, includeStateProof bool) (*api.FeeCreditBill, error)
	GetUnitsByOwnerID(ctx context.Context, ownerID types.Bytes) ([]types.UnitID, error)
	SendTransaction(ctx context.Context, tx *types.TransactionOrder) ([]byte, error)
	GetTransactionProof(ctx context.Context, txHash types.Bytes) (*types.TransactionRecord, *types.TxProof, error)
}

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