Skip to content

Commit

Permalink
[FAB-11294] Prover Service - List Tokens
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
wenjianqiao committed Oct 30, 2018
1 parent 60f968d commit 7173857
Show file tree
Hide file tree
Showing 8 changed files with 637 additions and 99 deletions.
365 changes: 285 additions & 80 deletions protos/token/prover.pb.go

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion protos/token/prover.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ message RecipientTransferShare {
uint64 quantity = 2;
}

// TokenOutput is used to specify a token returned by ListRequest
message TokenOutput {
// ID is used to uniquely identify the token
bytes id = 1;

// Type is the type of the token
string type = 2;

// Quantity represents the number for this type of token
uint64 quantity = 3;
}

// UnspentTokens is used to hold the output of listRequest
message UnspentTokens {
repeated TokenOutput tokens = 1;
}

// ListRequest is used to request a list of unspent tokens
message ListRequest {
bytes credential = 1;
}

// ImportRequest is used to request creation of imports
message ImportRequest {
// Credential contains information about the party who is requesting the operation
Expand Down Expand Up @@ -82,6 +104,7 @@ message Command {
oneof payload {
ImportRequest import_request = 2;
TransferRequest transfer_request = 3;
ListRequest list_request = 4;
}
}

Expand Down Expand Up @@ -109,7 +132,7 @@ message CommandResponseHeader {
bytes creator = 3;
}

// Error reports an applicaton error
// Error reports an application error
message Error {
// Message associated with this response.
string message = 1;
Expand All @@ -127,6 +150,7 @@ message CommandResponse {
oneof payload {
Error err = 2;
TokenTransaction token_transaction = 3;
UnspentTokens unspent_tokens = 4;
}
}

Expand Down
6 changes: 6 additions & 0 deletions token/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ type Manager struct {
func (t *Manager) GetIssuer(channel string, privateCredential, publicCredential []byte) (Issuer, error) {
return &plain.Issuer{}, nil
}

// GetTransactor returns a Transactor bound to the passed channel and whose credential
// is the tuple (privateCredential, publicCredential).
func (t *Manager) GetTransactor(channel string, privateCredential, publicCredential []byte) (Transactor, error) {
panic("not implemented yet")
}
80 changes: 80 additions & 0 deletions token/server/mock/tms_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions token/server/mock/transactor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions token/server/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (s *Prover) ProcessCommand(ctx context.Context, sc *token.SignedCommand) (*
switch t := command.GetPayload().(type) {
case *token.Command_ImportRequest:
payload, err = s.RequestImport(ctx, command.Header, t.ImportRequest)
case *token.Command_ListRequest:
payload, err = s.ListUnspentTokens(ctx, command.Header, t.ListRequest)
default:
err = errors.Errorf("command type not recognized: %T", t)
}
Expand Down Expand Up @@ -82,6 +84,23 @@ func (s *Prover) RequestImport(ctx context.Context, header *token.Header, reques
return &token.CommandResponse_TokenTransaction{TokenTransaction: tokenTransaction}, nil
}

func (s *Prover) ListUnspentTokens(ctxt context.Context, header *token.Header, listRequest *token.ListRequest) (*token.CommandResponse_UnspentTokens, error) {
trasactor, err := s.TMSManager.GetTransactor(header.ChannelId, listRequest.Credential, header.Creator)
if err != nil {
return nil, err
}

tokens, err := trasactor.ListUnspentTokens()
if err != nil {
return nil, err
}

return &token.CommandResponse_UnspentTokens{
UnspentTokens: &token.UnspentTokens{
Tokens: tokens,
}}, nil
}

func (s *Prover) ValidateHeader(header *token.Header) error {
if header == nil {
return errors.New("command header is required")
Expand Down
Loading

0 comments on commit 7173857

Please sign in to comment.