Skip to content

Commit 1447a3d

Browse files
committed
Implement RequestToGiveBill message
1 parent d155872 commit 1447a3d

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
filippo.io/edwards25519 v1.1.0
77
github.com/aws/aws-sdk-go-v2 v0.17.0
88
github.com/bits-and-blooms/bloom/v3 v3.1.0
9-
github.com/code-payments/code-protobuf-api v1.19.1-0.20251002160322-79d89fadd0fe
9+
github.com/code-payments/code-protobuf-api v1.19.1-0.20251006190631-c7955e3a049a
1010
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba
1111
github.com/emirpasic/gods v1.12.0
1212
github.com/envoyproxy/protoc-gen-validate v1.2.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
8080
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
8181
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
8282
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
83-
github.com/code-payments/code-protobuf-api v1.19.1-0.20251002160322-79d89fadd0fe h1:f/jZbdX74ZNSRY9O+KRPNr3Cr3ukserXuImtsVzq+no=
84-
github.com/code-payments/code-protobuf-api v1.19.1-0.20251002160322-79d89fadd0fe/go.mod h1:fl4xu32MeNpGZR3wFhwEeKO0qVDuxYBNkqnvuADt6cA=
83+
github.com/code-payments/code-protobuf-api v1.19.1-0.20251006190631-c7955e3a049a h1:es8YUC/il/9wYpNIh/BkckPIaNDonGiiiehUE0q+mA0=
84+
github.com/code-payments/code-protobuf-api v1.19.1-0.20251006190631-c7955e3a049a/go.mod h1:fl4xu32MeNpGZR3wFhwEeKO0qVDuxYBNkqnvuADt6cA=
8585
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba h1:Bkp+gmeb6Y2PWXfkSCTMBGWkb2P1BujRDSjWeI+0j5I=
8686
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba/go.mod h1:jSiifpiBpyBQ8q2R0MGEbkSgWC6sbdRTyDBntmW+j1E=
8787
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=

pkg/code/server/messaging/message_handler.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,42 @@ func (h *RequestToGrabBillMessageHandler) Validate(ctx context.Context, rendezvo
6363
func (h *RequestToGrabBillMessageHandler) OnSuccess(ctx context.Context) error {
6464
return nil
6565
}
66+
67+
// todo: This message type needs tests
68+
type RequestToGiveBillMessageHandler struct {
69+
data code_data.Provider
70+
}
71+
72+
func NewRequestToGiveBillMessageHandler(data code_data.Provider) MessageHandler {
73+
return &RequestToGiveBillMessageHandler{
74+
data: data,
75+
}
76+
}
77+
78+
func (h *RequestToGiveBillMessageHandler) Validate(ctx context.Context, rendezvous *common.Account, untypedMessage *messagingpb.Message) error {
79+
typedMessage := untypedMessage.GetRequestToGiveBill()
80+
if typedMessage == nil {
81+
return errors.New("invalid message type")
82+
}
83+
84+
//
85+
// Part 1: Mint account must be the Core Mint or a Launchpad Currency
86+
//
87+
88+
mintAccount, err := common.NewAccountFromProto(typedMessage.Mint)
89+
if err != nil {
90+
return err
91+
}
92+
93+
switch mintAccount.PublicKey().ToBase58() {
94+
case common.CoreMintAccount.PublicKey().ToBase58(), "52MNGpgvydSwCtC2H4qeiZXZ1TxEuRVCRGa8LAfk2kSj":
95+
default:
96+
return newMessageValidationError("mint account must be the core mint or a launcpad currency")
97+
}
98+
99+
return nil
100+
}
101+
102+
func (h *RequestToGiveBillMessageHandler) OnSuccess(ctx context.Context) error {
103+
return nil
104+
}

pkg/code/server/messaging/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,10 @@ func (s *server) SendMessage(ctx context.Context, req *messagingpb.SendMessageRe
658658
log = log.WithField("message_type", "request_to_grab_bill")
659659
messageHandler = NewRequestToGrabBillMessageHandler(s.data)
660660

661+
case *messagingpb.Message_RequestToGiveBill:
662+
log = log.WithField("message_type", "request_to_give_bill")
663+
messageHandler = NewRequestToGiveBillMessageHandler(s.data)
664+
661665
default:
662666
return nil, status.Error(codes.InvalidArgument, "message.kind must be set")
663667
}

0 commit comments

Comments
 (0)