Skip to content

Commit 7173857

Browse files
committed
[FAB-11294] Prover Service - List Tokens
This change-set does the following: - Update prover.proto to support ListUnspentTokens command - Implement ListUnspentTokens for Prover service - Add transactor interface to reduce dependency on TMS Change-Id: Ib8b9d8564933aadd85aacc05267f10ca3a1274b8 Signed-off-by: Wenjian Qiao <wenjianq@gmail.com>
1 parent 60f968d commit 7173857

File tree

8 files changed

+637
-99
lines changed

8 files changed

+637
-99
lines changed

protos/token/prover.pb.go

Lines changed: 285 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/token/prover.proto

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@ message RecipientTransferShare {
3535
uint64 quantity = 2;
3636
}
3737

38+
// TokenOutput is used to specify a token returned by ListRequest
39+
message TokenOutput {
40+
// ID is used to uniquely identify the token
41+
bytes id = 1;
42+
43+
// Type is the type of the token
44+
string type = 2;
45+
46+
// Quantity represents the number for this type of token
47+
uint64 quantity = 3;
48+
}
49+
50+
// UnspentTokens is used to hold the output of listRequest
51+
message UnspentTokens {
52+
repeated TokenOutput tokens = 1;
53+
}
54+
55+
// ListRequest is used to request a list of unspent tokens
56+
message ListRequest {
57+
bytes credential = 1;
58+
}
59+
3860
// ImportRequest is used to request creation of imports
3961
message ImportRequest {
4062
// Credential contains information about the party who is requesting the operation
@@ -82,6 +104,7 @@ message Command {
82104
oneof payload {
83105
ImportRequest import_request = 2;
84106
TransferRequest transfer_request = 3;
107+
ListRequest list_request = 4;
85108
}
86109
}
87110

@@ -109,7 +132,7 @@ message CommandResponseHeader {
109132
bytes creator = 3;
110133
}
111134

112-
// Error reports an applicaton error
135+
// Error reports an application error
113136
message Error {
114137
// Message associated with this response.
115138
string message = 1;
@@ -127,6 +150,7 @@ message CommandResponse {
127150
oneof payload {
128151
Error err = 2;
129152
TokenTransaction token_transaction = 3;
153+
UnspentTokens unspent_tokens = 4;
130154
}
131155
}
132156

token/server/manager.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ type Manager struct {
2121
func (t *Manager) GetIssuer(channel string, privateCredential, publicCredential []byte) (Issuer, error) {
2222
return &plain.Issuer{}, nil
2323
}
24+
25+
// GetTransactor returns a Transactor bound to the passed channel and whose credential
26+
// is the tuple (privateCredential, publicCredential).
27+
func (t *Manager) GetTransactor(channel string, privateCredential, publicCredential []byte) (Transactor, error) {
28+
panic("not implemented yet")
29+
}

token/server/mock/tms_manager.go

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/server/mock/transactor.go

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/server/prover.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ func (s *Prover) ProcessCommand(ctx context.Context, sc *token.SignedCommand) (*
5555
switch t := command.GetPayload().(type) {
5656
case *token.Command_ImportRequest:
5757
payload, err = s.RequestImport(ctx, command.Header, t.ImportRequest)
58+
case *token.Command_ListRequest:
59+
payload, err = s.ListUnspentTokens(ctx, command.Header, t.ListRequest)
5860
default:
5961
err = errors.Errorf("command type not recognized: %T", t)
6062
}
@@ -82,6 +84,23 @@ func (s *Prover) RequestImport(ctx context.Context, header *token.Header, reques
8284
return &token.CommandResponse_TokenTransaction{TokenTransaction: tokenTransaction}, nil
8385
}
8486

87+
func (s *Prover) ListUnspentTokens(ctxt context.Context, header *token.Header, listRequest *token.ListRequest) (*token.CommandResponse_UnspentTokens, error) {
88+
trasactor, err := s.TMSManager.GetTransactor(header.ChannelId, listRequest.Credential, header.Creator)
89+
if err != nil {
90+
return nil, err
91+
}
92+
93+
tokens, err := trasactor.ListUnspentTokens()
94+
if err != nil {
95+
return nil, err
96+
}
97+
98+
return &token.CommandResponse_UnspentTokens{
99+
UnspentTokens: &token.UnspentTokens{
100+
Tokens: tokens,
101+
}}, nil
102+
}
103+
85104
func (s *Prover) ValidateHeader(header *token.Header) error {
86105
if header == nil {
87106
return errors.New("command header is required")

0 commit comments

Comments
 (0)