types

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypePaymentContractAuthorisation = "payment_contract_authorisation"
	EventTypeCreatePaymentTemplate        = "create_payment_template"
	EventTypeCreatePaymentContract        = "create_payment_contract"
	EventTypeCreateSubscription           = "create_subscription"
	EventTypeGrantDiscount                = "grant_discount"
	EventTypeRevokeDiscount               = "revoke_discount"
	EventTypeEffectPayment                = "effect_payment"

	AttributeKeyPayerDid          = "payer_did"
	AttributeKeyPaymentContractId = "payment_contract-id"
	AttributeKeyAuthorised        = "authorised"
	AttributeKeyCreatorDid        = "creator_did"
	AttributeKeyPaymentTemplateId = "payment_template_id"
	AttributeKeyPayer             = "payer"
	AttributeKeyRecipients        = "recipients"
	AttributeKeyCanDeauthorise    = "can_deauthorise"
	AttributeKeyDiscountId        = "discount_id"
	AttributeKeySubscriptionId    = "attribute_key"
	AttributeKeyMaxPeriods        = "max_periods"
	AttributeKeyPeriod            = "period"
	AttributeKeySenderDid         = "sender_did"
	AttributeKeyRecipient         = "recipient"
	AttributeKeyHolder            = "holder"
	AttributeKeyAttributeKeyId    = "payment_id"
	AttributeKeyPaymentAmount     = "payment_amount"
	AttributeKeyPaymentMinimum    = "payment_minimum"
	AttributeKeyPaymentMaximum    = "payment_maximum"
	AttributeKeyDiscounts         = "discounts"

	AttributeKeyInputFromPayRemainderPool = "input_from_pay_remainder_pool"
	AttributeKeyInputFromPayer            = "input_from_payer"
	AttributeKeyOutputToPayRemainderPool  = "output_to_pay_remainder_pool"
	AttributeKeyOutputToPayees            = "output_to_payees"

	AttributeValueCategory = ModuleName
)
View Source
const (
	ModuleName        = "payments"
	DefaultParamspace = ModuleName
	StoreKey          = ModuleName
	RouterKey         = ModuleName
	QuerierRoute      = ModuleName

	PayRemainderPool = "pay_remainder_pool"

	PaymentIdPrefix         = "payment:"
	PaymentTemplateIdPrefix = PaymentIdPrefix + "template:"
	PaymentContractIdPrefix = PaymentIdPrefix + "contract:"
	SubscriptionIdPrefix    = PaymentIdPrefix + "subscription:"
)
View Source
const (
	TypeMsgCreatePaymentTemplate           = "create-payment-template"
	TypeMsgCreatePaymentContract           = "create-payment-contract"
	TypeMsgCreateSubscription              = "create-subscription"
	TypeMsgSetPaymentContractAuthorisation = "set-payment-contract-authorisation"
	TypeMsgGrantDiscount                   = "grant-discount"
	TypeMsgRevokeDiscount                  = "revoke-discount"
	TypeMsgEffectPayment                   = "effect-payment"
)
View Source
const (
	BlockPeriodUnit = "block"
	TimePeriodUnit  = "time"
)
View Source
const (
	DefaultCodespace = ModuleName
)

Variables

View Source
var (
	ErrNegativeSharePercentage                      = sdkerrors.Register(DefaultCodespace, 2, "payment distribution share percentage must be positive")
	ErrDistributionPercentagesNot100                = sdkerrors.Register(DefaultCodespace, 3, "payment distribution percentages should add up to 100")
	ErrInvalidPeriod                                = sdkerrors.Register(DefaultCodespace, 4, "period is invalid")
	ErrPaymentContractCannotBeDeauthorised          = sdkerrors.Register(DefaultCodespace, 5, "payment contract cannot be deauthorised")
	ErrDiscountIDsBeSequentialFrom1                 = sdkerrors.Register(DefaultCodespace, 6, "discount IDs must be sequential starting with 1")
	ErrNegativeDiscountPercentage                   = sdkerrors.Register(DefaultCodespace, 7, "discount percentage must be positive")
	ErrDiscountPercentageGreaterThan100             = sdkerrors.Register(DefaultCodespace, 8, "discount percentage cannot exceed 100")
	ErrDiscountIdIsNotInTemplate                    = sdkerrors.Register(DefaultCodespace, 9, "discount ID specified is not one of the template's discounts")
	ErrInvalidPaymentTemplate                       = sdkerrors.Register(DefaultCodespace, 10, "payment template invalid")
	ErrTriedToEffectSubscriptionPaymentWhenShouldnt = sdkerrors.Register(DefaultCodespace, 11, "tried to effect subscription payment when shouldn't")
	ErrInvalidId                                    = sdkerrors.Register(DefaultCodespace, 12, "id is invalid")
	ErrInvalidArgument                              = sdkerrors.Register(DefaultCodespace, 13, "invalid argument")
	ErrAlreadyExists                                = sdkerrors.Register(DefaultCodespace, 14, "already exist")
)
View Source
var (
	PaymentTemplateKeyPrefix = []byte{0x00}
	PaymentContractKeyPrefix = []byte{0x01}
	SubscriptionKeyPrefix    = []byte{0x02}
)
View Source
var (
	ValidPaymentTemplateId = regexp.MustCompile(`^payment:template:[a-zA-Z][a-zA-Z0-9/_:-]*$`)
	ValidPaymentContractId = regexp.MustCompile(`^payment:contract:[a-zA-Z][a-zA-Z0-9/_:-]*$`)
	ValidSubscriptionId    = regexp.MustCompile(`^payment:subscription:[a-zA-Z][a-zA-Z0-9/_:-]*$`)

	IsValidPaymentTemplateId = ValidPaymentTemplateId.MatchString
	IsValidPaymentContractId = ValidPaymentContractId.MatchString
	IsValidSubscriptionId    = ValidSubscriptionId.MatchString
)
View Source
var ModuleCdc *codec.Codec

ModuleCdc is the codec for the module

Functions

func CheckNotEmpty

func CheckNotEmpty(value string, name string) (valid bool, err error)

func GetPaymentContractKey

func GetPaymentContractKey(contractId string) []byte

func GetPaymentTemplateKey

func GetPaymentTemplateKey(templateId string) []byte

func GetSubscriptionKey

func GetSubscriptionKey(subscriptionId string) []byte

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

func ValidateGenesis

func ValidateGenesis(data GenesisState) error

Types

type BlockPeriod

type BlockPeriod struct {
	PeriodLength     int64 `json:"period_length" yaml:"period_length"`
	PeriodStartBlock int64 `json:"period_start_block" yaml:"period_start_block"`
}

func NewBlockPeriod

func NewBlockPeriod(periodLength, periodStartBlock int64) BlockPeriod

func (BlockPeriod) GetPeriodUnit

func (p BlockPeriod) GetPeriodUnit() string

func (BlockPeriod) Validate

func (p BlockPeriod) Validate() error

type Discount

type Discount struct {
	Id      sdk.Uint `json:"id" yaml:"id"`
	Percent sdk.Dec  `json:"percent" yaml:"percent"`
}

func NewDiscount

func NewDiscount(id sdk.Uint, percent sdk.Dec) Discount

func (Discount) Validate

func (d Discount) Validate() error

type Discounts

type Discounts []Discount

func NewDiscounts

func NewDiscounts(discounts ...Discount) Discounts

func (Discounts) Validate

func (ds Discounts) Validate() error

type Distribution

type Distribution []DistributionShare

func NewDistribution

func NewDistribution(shares ...DistributionShare) Distribution

func (Distribution) GetDistributionsFor

func (d Distribution) GetDistributionsFor(amount sdk.Coins) []sdk.DecCoins

func (Distribution) Validate

func (d Distribution) Validate() error

type DistributionShare

type DistributionShare struct {
	Address    sdk.AccAddress `json:"address" yaml:"address"`
	Percentage sdk.Dec        `json:"percentage" yaml:"percentage"`
}

func NewDistributionShare

func NewDistributionShare(address sdk.AccAddress, percentage sdk.Dec) DistributionShare

func NewFullDistributionShare added in v0.13.0

func NewFullDistributionShare(address sdk.AccAddress) DistributionShare

func (DistributionShare) GetShareOf

func (d DistributionShare) GetShareOf(amount sdk.DecCoins) sdk.DecCoins

func (DistributionShare) Validate

func (d DistributionShare) Validate() error

type FeeType

type FeeType string
const (
	FeeClaimTransaction      FeeType = "ClaimTransactionFee"
	FeeEvaluationTransaction FeeType = "FeeEvaluationTransaction"
)

type GenesisState

type GenesisState struct {
	PaymentTemplates []PaymentTemplate `json:"payment_templates" yaml:"payment_templates"`
	PaymentContracts []PaymentContract `json:"payment_contracts" yaml:"payment_contracts"`
	Subscriptions    []Subscription    `json:"subscriptions" yaml:"subscriptions"`
}

func DefaultGenesisState

func DefaultGenesisState() GenesisState

func NewGenesisState

func NewGenesisState(templates []PaymentTemplate, contracts []PaymentContract,
	subscriptions []Subscription) GenesisState

type MsgCreatePaymentContract

type MsgCreatePaymentContract struct {
	CreatorDid        did.Did        `json:"creator_did" yaml:"creator_did"`
	PaymentTemplateId string         `json:"payment_template_id" yaml:"payment_template_id"`
	PaymentContractId string         `json:"payment_contract_id" yaml:"payment_contract_id"`
	Payer             sdk.AccAddress `json:"payer" yaml:"payer"`
	Recipients        Distribution   `json:"recipients" yaml:"recipients"`
	CanDeauthorise    bool           `json:"can_deauthorise" yaml:"can_deauthorise"`
	DiscountId        sdk.Uint       `json:"discount_id" yaml:"discount_id"`
}

func NewMsgCreatePaymentContract

func NewMsgCreatePaymentContract(templateId, contractId string,
	payer sdk.AccAddress, recipients Distribution, canDeauthorise bool,
	discountId sdk.Uint, creatorDid did.Did) MsgCreatePaymentContract

func (MsgCreatePaymentContract) GetSignBytes

func (msg MsgCreatePaymentContract) GetSignBytes() []byte

func (MsgCreatePaymentContract) GetSignerDid

func (msg MsgCreatePaymentContract) GetSignerDid() did.Did

func (MsgCreatePaymentContract) GetSigners

func (msg MsgCreatePaymentContract) GetSigners() []sdk.AccAddress

func (MsgCreatePaymentContract) Route

func (msg MsgCreatePaymentContract) Route() string

func (MsgCreatePaymentContract) String

func (msg MsgCreatePaymentContract) String() string

func (MsgCreatePaymentContract) Type

func (msg MsgCreatePaymentContract) Type() string

func (MsgCreatePaymentContract) ValidateBasic

func (msg MsgCreatePaymentContract) ValidateBasic() error

type MsgCreatePaymentTemplate

type MsgCreatePaymentTemplate struct {
	CreatorDid      did.Did         `json:"creator_did" yaml:"creator_did"`
	PaymentTemplate PaymentTemplate `json:"payment_template" yaml:"payment_template"`
}

func NewMsgCreatePaymentTemplate

func NewMsgCreatePaymentTemplate(template PaymentTemplate,
	creatorDid did.Did) MsgCreatePaymentTemplate

func (MsgCreatePaymentTemplate) GetSignBytes

func (msg MsgCreatePaymentTemplate) GetSignBytes() []byte

func (MsgCreatePaymentTemplate) GetSignerDid

func (msg MsgCreatePaymentTemplate) GetSignerDid() did.Did

func (MsgCreatePaymentTemplate) GetSigners

func (msg MsgCreatePaymentTemplate) GetSigners() []sdk.AccAddress

func (MsgCreatePaymentTemplate) Route

func (msg MsgCreatePaymentTemplate) Route() string

func (MsgCreatePaymentTemplate) String

func (msg MsgCreatePaymentTemplate) String() string

func (MsgCreatePaymentTemplate) Type

func (msg MsgCreatePaymentTemplate) Type() string

func (MsgCreatePaymentTemplate) ValidateBasic

func (msg MsgCreatePaymentTemplate) ValidateBasic() error

type MsgCreateSubscription

type MsgCreateSubscription struct {
	CreatorDid        did.Did  `json:"creator_did" yaml:"creator_did"`
	SubscriptionId    string   `json:"subscription_id" yaml:"subscription_id"`
	PaymentContractId string   `json:"payment_contract_id" yaml:"payment_contract_id"`
	MaxPeriods        sdk.Uint `json:"max_periods" yaml:"max_periods"`
	Period            Period   `json:"period" yaml:"period"`
}

func NewMsgCreateSubscription

func NewMsgCreateSubscription(subscriptionId, contractId string, maxPeriods sdk.Uint,
	period Period, creatorDid did.Did) MsgCreateSubscription

func (MsgCreateSubscription) GetSignBytes

func (msg MsgCreateSubscription) GetSignBytes() []byte

func (MsgCreateSubscription) GetSignerDid

func (msg MsgCreateSubscription) GetSignerDid() did.Did

func (MsgCreateSubscription) GetSigners

func (msg MsgCreateSubscription) GetSigners() []sdk.AccAddress

func (MsgCreateSubscription) Route

func (msg MsgCreateSubscription) Route() string

func (MsgCreateSubscription) String

func (msg MsgCreateSubscription) String() string

func (MsgCreateSubscription) Type

func (msg MsgCreateSubscription) Type() string

func (MsgCreateSubscription) ValidateBasic

func (msg MsgCreateSubscription) ValidateBasic() error

type MsgEffectPayment

type MsgEffectPayment struct {
	SenderDid         did.Did `json:"sender_did" yaml:"sender_did"`
	PaymentContractId string  `json:"payment_contract_id" yaml:"payment_contract_id"`
}

func NewMsgEffectPayment

func NewMsgEffectPayment(contractId string, creatorDid did.Did) MsgEffectPayment

func (MsgEffectPayment) GetSignBytes

func (msg MsgEffectPayment) GetSignBytes() []byte

func (MsgEffectPayment) GetSignerDid

func (msg MsgEffectPayment) GetSignerDid() did.Did

func (MsgEffectPayment) GetSigners

func (msg MsgEffectPayment) GetSigners() []sdk.AccAddress

func (MsgEffectPayment) Route

func (msg MsgEffectPayment) Route() string

func (MsgEffectPayment) String

func (msg MsgEffectPayment) String() string

func (MsgEffectPayment) Type

func (msg MsgEffectPayment) Type() string

func (MsgEffectPayment) ValidateBasic

func (msg MsgEffectPayment) ValidateBasic() error

type MsgGrantDiscount

type MsgGrantDiscount struct {
	SenderDid         did.Did        `json:"sender_did" yaml:"sender_did"`
	PaymentContractId string         `json:"payment_contract_id" yaml:"payment_contract_id"`
	DiscountId        sdk.Uint       `json:"discount_id" yaml:"discount_id"`
	Recipient         sdk.AccAddress `json:"recipient" yaml:"recipient"`
}

func NewMsgGrantDiscount

func NewMsgGrantDiscount(contractId string, discountId sdk.Uint,
	recipient sdk.AccAddress, creatorDid did.Did) MsgGrantDiscount

func (MsgGrantDiscount) GetSignBytes

func (msg MsgGrantDiscount) GetSignBytes() []byte

func (MsgGrantDiscount) GetSignerDid

func (msg MsgGrantDiscount) GetSignerDid() did.Did

func (MsgGrantDiscount) GetSigners

func (msg MsgGrantDiscount) GetSigners() []sdk.AccAddress

func (MsgGrantDiscount) Route

func (msg MsgGrantDiscount) Route() string

func (MsgGrantDiscount) String

func (msg MsgGrantDiscount) String() string

func (MsgGrantDiscount) Type

func (msg MsgGrantDiscount) Type() string

func (MsgGrantDiscount) ValidateBasic

func (msg MsgGrantDiscount) ValidateBasic() error

type MsgRevokeDiscount

type MsgRevokeDiscount struct {
	SenderDid         did.Did        `json:"sender_did" yaml:"sender_did"`
	PaymentContractId string         `json:"payment_contract_id" yaml:"payment_contract_id"`
	Holder            sdk.AccAddress `json:"holder" yaml:"holder"`
}

func NewMsgRevokeDiscount

func NewMsgRevokeDiscount(contractId string, holder sdk.AccAddress,
	creatorDid did.Did) MsgRevokeDiscount

func (MsgRevokeDiscount) GetSignBytes

func (msg MsgRevokeDiscount) GetSignBytes() []byte

func (MsgRevokeDiscount) GetSignerDid

func (msg MsgRevokeDiscount) GetSignerDid() did.Did

func (MsgRevokeDiscount) GetSigners

func (msg MsgRevokeDiscount) GetSigners() []sdk.AccAddress

func (MsgRevokeDiscount) Route

func (msg MsgRevokeDiscount) Route() string

func (MsgRevokeDiscount) String

func (msg MsgRevokeDiscount) String() string

func (MsgRevokeDiscount) Type

func (msg MsgRevokeDiscount) Type() string

func (MsgRevokeDiscount) ValidateBasic

func (msg MsgRevokeDiscount) ValidateBasic() error

type MsgSetPaymentContractAuthorisation

type MsgSetPaymentContractAuthorisation struct {
	PayerDid          did.Did `json:"payer_did" yaml:"payer_did"`
	PaymentContractId string  `json:"payment_contract_id" yaml:"payment_contract_id"`
	Authorised        bool    `json:"authorised" yaml:"authorised"`
}

func NewMsgSetPaymentContractAuthorisation

func NewMsgSetPaymentContractAuthorisation(contractId string, authorised bool,
	payerDid did.Did) MsgSetPaymentContractAuthorisation

func (MsgSetPaymentContractAuthorisation) GetSignBytes

func (msg MsgSetPaymentContractAuthorisation) GetSignBytes() []byte

func (MsgSetPaymentContractAuthorisation) GetSignerDid

func (msg MsgSetPaymentContractAuthorisation) GetSignerDid() did.Did

func (MsgSetPaymentContractAuthorisation) GetSigners

func (MsgSetPaymentContractAuthorisation) Route

func (MsgSetPaymentContractAuthorisation) String

func (MsgSetPaymentContractAuthorisation) Type

func (MsgSetPaymentContractAuthorisation) ValidateBasic

func (msg MsgSetPaymentContractAuthorisation) ValidateBasic() error

type PaymentContract

type PaymentContract struct {
	Id                string         `json:"id" yaml:"id"`
	PaymentTemplateId string         `json:"payment_template_id" yaml:"payment_template_id"`
	Creator           sdk.AccAddress `json:"creator" yaml:"creator"`
	Payer             sdk.AccAddress `json:"payer" yaml:"payer"`
	Recipients        Distribution   `json:"recipients" yaml:"recipients"`
	CumulativePay     sdk.Coins      `json:"cumulative_pay" yaml:"cumulative_pay"`
	CurrentRemainder  sdk.Coins      `json:"current_remainder" yaml:"current_remainder"`
	CanDeauthorise    bool           `json:"can_deauthorise" yaml:"can_deauthorise"`
	Authorised        bool           `json:"authorised" yaml:"authorised"`
	DiscountId        sdk.Uint       `json:"discount_id" yaml:"discount_id"`
}

func NewPaymentContract

func NewPaymentContract(id, templateId string, creator, payer sdk.AccAddress,
	recipients Distribution, canDeauthorise, authorised bool,
	discountId sdk.Uint) PaymentContract

func NewPaymentContractNoDiscount

func NewPaymentContractNoDiscount(id, templateId string, creator,
	payer sdk.AccAddress, recipients Distribution, canDeauthorise,
	authorised bool) PaymentContract

func (PaymentContract) CanEffectPayment

func (pc PaymentContract) CanEffectPayment(template PaymentTemplate) bool

CanEffectPayment False if not authorised or the (non-zero!) max has been reached

func (PaymentContract) IsFirstPayment

func (pc PaymentContract) IsFirstPayment() bool

func (PaymentContract) Validate

func (pc PaymentContract) Validate() error

type PaymentTemplate

type PaymentTemplate struct {
	Id             string    `json:"id" yaml:"id"`
	PaymentAmount  sdk.Coins `json:"payment_amount" yaml:"payment_amount"`
	PaymentMinimum sdk.Coins `json:"payment_minimum" yaml:"payment_minimum"`
	PaymentMaximum sdk.Coins `json:"payment_maximum" yaml:"payment_maximum"`
	Discounts      Discounts `json:"discounts" yaml:"discounts"`
}

func NewPaymentTemplate

func NewPaymentTemplate(id string, paymentAmount, paymentMinimum,
	paymentMaximum sdk.Coins, discounts Discounts) PaymentTemplate

func (PaymentTemplate) GetDiscountPercent

func (pt PaymentTemplate) GetDiscountPercent(discountId sdk.Uint) (sdk.Dec, error)

func (PaymentTemplate) Validate

func (pt PaymentTemplate) Validate() error

type Period

type Period interface {
	GetPeriodUnit() string
	Validate() error
	// contains filtered or unexported methods
}

type Subscription

type Subscription struct {
	Id                 string   `json:"id" yaml:"id"`
	PaymentContractId  string   `json:"payment_contract_id" yaml:"payment_contract_id"`
	PeriodsSoFar       sdk.Uint `json:"periods_so_far" yaml:"periods_so_far"`
	MaxPeriods         sdk.Uint `json:"max_periods" yaml:"max_periods"`
	PeriodsAccumulated sdk.Uint `json:"periods_accumulated" yaml:"periods_accumulated"`
	Period             Period   `json:"period" yaml:"period"`
}

func NewSubscription

func NewSubscription(id, contractId string, maxPeriods sdk.Uint, period Period) Subscription

func (Subscription) IsComplete

func (s Subscription) IsComplete() bool

IsComplete True if we have reached the max number of periods and there are no accumulated periods

func (Subscription) MaxPeriodsReached

func (s Subscription) MaxPeriodsReached() bool

MaxPeriodsReached True if max number of periods has been reached

func (*Subscription) NextPeriod

func (s *Subscription) NextPeriod(periodPaid bool)

NextPeriod Proceed to the next period

func (Subscription) ShouldEffect

func (s Subscription) ShouldEffect(ctx sdk.Context) bool

ShouldEffect True if the subscription has started and

(A) the max no. of periods has not been reached and the period has ended, or
(B) the max no. of periods has been reached but we have accumulated periods

This means that accumulated periods only get tackled once the max number of periods has been reached.

func (Subscription) Validate

func (s Subscription) Validate() error

type TestPeriod

type TestPeriod struct {
	PeriodLength     int64 `json:"period_length" yaml:"period_length"`
	PeriodStartBlock int64 `json:"period_start_block" yaml:"period_start_block"`
}

TestPeriod Is identical to BlockPeriod but does not take into consideration the context in periodEnded() and periodStarted()

func NewTestPeriod

func NewTestPeriod(periodLength, periodStartBlock int64) TestPeriod

func (TestPeriod) GetPeriodUnit

func (p TestPeriod) GetPeriodUnit() string

func (TestPeriod) Validate

func (p TestPeriod) Validate() error

type TimePeriod

type TimePeriod struct {
	PeriodDurationNs time.Duration `json:"period_duration_ns" yaml:"period_duration_ns"`
	PeriodStartTime  time.Time     `json:"period_start_time" yaml:"period_start_time"`
}

func NewTimePeriod

func NewTimePeriod(periodDurationNs time.Duration, periodStartTime time.Time) TimePeriod

func (TimePeriod) GetPeriodUnit

func (p TimePeriod) GetPeriodUnit() string

func (TimePeriod) Validate

func (p TimePeriod) Validate() error

Jump to

Keyboard shortcuts

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