|
| 1 | +package transaction_v2 |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + transactionpb "github.com/code-payments/code-protobuf-api/generated/go/transaction/v2" |
| 7 | + |
| 8 | + "github.com/code-payments/code-server/pkg/code/common" |
| 9 | + "github.com/code-payments/code-server/pkg/code/data/intent" |
| 10 | + currency_lib "github.com/code-payments/code-server/pkg/currency" |
| 11 | +) |
| 12 | + |
| 13 | +type SubmitIntentIntegration interface { |
| 14 | + // AllowCreation determines whether the new intent creation should be allowed |
| 15 | + // with app-specific validation rules |
| 16 | + AllowCreation(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata, actions []*transactionpb.Action) error |
| 17 | + |
| 18 | + // OnSuccess is a best-effort callback when an intent has been successfully |
| 19 | + // submitted |
| 20 | + OnSuccess(ctx context.Context, intentRecord *intent.Record) error |
| 21 | +} |
| 22 | + |
| 23 | +type defaultSubmitIntentIntegration struct { |
| 24 | +} |
| 25 | + |
| 26 | +// NewDefaultSubmitIntentIntegration retuns a SubmitIntentIntegration that allows everything |
| 27 | +func NewDefaultSubmitIntentIntegration() SubmitIntentIntegration { |
| 28 | + return &defaultSubmitIntentIntegration{} |
| 29 | +} |
| 30 | + |
| 31 | +func (i *defaultSubmitIntentIntegration) AllowCreation(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata, actions []*transactionpb.Action) error { |
| 32 | + return nil |
| 33 | +} |
| 34 | + |
| 35 | +func (i *defaultSubmitIntentIntegration) OnSuccess(ctx context.Context, intentRecord *intent.Record) error { |
| 36 | + return nil |
| 37 | +} |
| 38 | + |
| 39 | +type AirdropIntegration interface { |
| 40 | + // GetWelcomeBonusAmount returns the amount that should be paid for the |
| 41 | + // welcome bonus. Return 0 amount if the airdrop should not be sent. |
| 42 | + GetWelcomeBonusAmount(ctx context.Context, owner *common.Account) (float64, currency_lib.Code, error) |
| 43 | +} |
| 44 | + |
| 45 | +type defaultAirdropIntegration struct{} |
| 46 | + |
| 47 | +// NewDefaultAirdropIntegration retuns an AirdropIntegration that sends $1 USD |
| 48 | +// to everyone |
| 49 | +func NewDefaultAirdropIntegration() AirdropIntegration { |
| 50 | + return &defaultAirdropIntegration{} |
| 51 | +} |
| 52 | + |
| 53 | +func (i *defaultAirdropIntegration) GetWelcomeBonusAmount(ctx context.Context, owner *common.Account) (float64, currency_lib.Code, error) { |
| 54 | + return 1.0, currency_lib.USD, nil |
| 55 | +} |
0 commit comments