Skip to content

Commit 8f5e3d7

Browse files
committed
Move transaction server integrations into own file
1 parent aae0ece commit 8f5e3d7

File tree

3 files changed

+55
-44
lines changed

3 files changed

+55
-44
lines changed

pkg/code/server/transaction/airdrop.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,6 @@ var (
5050
cachedAirdropStatus = cache.NewCache(10_000)
5151
)
5252

53-
type AirdropIntegration interface {
54-
// GetWelcomeBonusAmount returns the amount that should be paid for the
55-
// welcome bonus. Return 0 amount if the airdrop should not be sent.
56-
GetWelcomeBonusAmount(ctx context.Context, owner *common.Account) (float64, currency_lib.Code, error)
57-
}
58-
59-
type defaultAirdropIntegration struct{}
60-
61-
// NewDefaultAirdropIntegration retuns an AirdropIntegration that sends $1 USD
62-
// to everyone
63-
func NewDefaultAirdropIntegration() AirdropIntegration {
64-
return &defaultAirdropIntegration{}
65-
}
66-
67-
func (i *defaultAirdropIntegration) GetWelcomeBonusAmount(ctx context.Context, owner *common.Account) (float64, currency_lib.Code, error) {
68-
return 1.0, currency_lib.USD, nil
69-
}
70-
7153
func (s *transactionServer) Airdrop(ctx context.Context, req *transactionpb.AirdropRequest) (*transactionpb.AirdropResponse, error) {
7254
log := s.log.WithFields(logrus.Fields{
7355
"method": "Airdrop",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
}

pkg/code/server/transaction/intent.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,6 @@ import (
3737
"github.com/code-payments/code-server/pkg/solana/token"
3838
)
3939

40-
type SubmitIntentIntegration interface {
41-
// AllowCreation determines whether the new intent creation should be allowed
42-
// with app-specific validation rules
43-
AllowCreation(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata, actions []*transactionpb.Action) error
44-
45-
// OnSuccess is a best-effort callback when an intent has been successfully
46-
// submitted
47-
OnSuccess(ctx context.Context, intentRecord *intent.Record) error
48-
}
49-
50-
type defaultSubmitIntentIntegration struct {
51-
}
52-
53-
// NewDefaultSubmitIntentIntegration retuns a SubmitIntentIntegration that allows everything
54-
func NewDefaultSubmitIntentIntegration() SubmitIntentIntegration {
55-
return &defaultSubmitIntentIntegration{}
56-
}
57-
58-
func (i *defaultSubmitIntentIntegration) AllowCreation(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata, actions []*transactionpb.Action) error {
59-
return nil
60-
}
61-
62-
func (i *defaultSubmitIntentIntegration) OnSuccess(ctx context.Context, intentRecord *intent.Record) error {
63-
return nil
64-
}
65-
6640
func (s *transactionServer) SubmitIntent(streamer transactionpb.Transaction_SubmitIntentServer) error {
6741
// Bound the total RPC. Keeping the timeout higher to see where we land because
6842
// there's a lot of stuff happening in this method.

0 commit comments

Comments
 (0)