Skip to content

Commit

Permalink
Merge pull request #19 from hyperledger-labs/f-16
Browse files Browse the repository at this point in the history
Refactor Platform Folder Structure #16
  • Loading branch information
adecaro committed Jun 18, 2021
2 parents 8e292a6 + 33899c3 commit 7ec05a6
Show file tree
Hide file tree
Showing 74 changed files with 278 additions and 286 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/consensys/gurvy v0.3.9-0.20210209011448-37644c45f955
github.com/dgraph-io/badger/v3 v3.2011.1
github.com/golang/protobuf v1.5.2
github.com/hyperledger-labs/fabric-smart-client v0.0.0-20210609074109-b623df1c373b
github.com/hyperledger-labs/fabric-smart-client v0.0.0-20210617155513-59855c1b94e7
github.com/hyperledger/fabric v1.4.0-rc1.0.20200930182727-344fda602252
github.com/hyperledger/fabric-amcl v0.0.0-20200424173818-327c9e2cf77a
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200424173110-d7076418f212
Expand All @@ -30,8 +30,6 @@ require (
github.com/stretchr/testify v1.7.0
github.com/tedsuo/ifrit v0.0.0-20191009134036-9a97d0632f00
go.uber.org/atomic v1.7.0
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
golang.org/x/tools v0.1.3 // indirect
google.golang.org/grpc v1.36.1 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo=
github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
github.com/hyperledger-labs/fabric-smart-client v0.0.0-20210609074109-b623df1c373b h1:h2sfr5gLBvJPx4OnCIoaxDb5l3KWmz2NrnCvAOB+xos=
github.com/hyperledger-labs/fabric-smart-client v0.0.0-20210609074109-b623df1c373b/go.mod h1:qTt4y3ljZl2fasmPkDijbmXFrYXjnF/sNAKx0c57Wco=
github.com/hyperledger-labs/fabric-smart-client v0.0.0-20210617155513-59855c1b94e7 h1:cYqYVmmzsx/BH/g2m+pPrKVYoiWxUECnzx/7webFM/0=
github.com/hyperledger-labs/fabric-smart-client v0.0.0-20210617155513-59855c1b94e7/go.mod h1:8SLl0HXRHyIdwkvEbFt2xVQW5j+7bW26kiZqVS7EK94=
github.com/hyperledger/fabric v1.4.0-rc1.0.20200930182727-344fda602252 h1:lQq/yygTbHWPfjFZ1VgINd1TJY7rOJ/zglcl9nE/s9Q=
github.com/hyperledger/fabric v1.4.0-rc1.0.20200930182727-344fda602252/go.mod h1:+kicKDn5xa88tOpOY/o6/7iB/RD7oOs2INzwVg2ARmM=
github.com/hyperledger/fabric-amcl v0.0.0-20200128223036-d1aa2665426a/go.mod h1:X+DIyUsaTmalOpmpQfIvFZjKHQedrURQ5t4YqquX7lE=
Expand Down Expand Up @@ -899,8 +899,6 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210608053332-aa57babbf139 h1:C+AwYEtBp/VQwoLntUmQ/yx3MS9vmZaKNdw5eOpoQe8=
golang.org/x/sys v0.0.0-20210608053332-aa57babbf139/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
Expand Down Expand Up @@ -933,8 +931,6 @@ golang.org/x/tools v0.0.0-20200131233409-575de47986ce/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20201105001634-bc3cf281b174/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
6 changes: 3 additions & 3 deletions token/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ SPDX-License-Identifier: Apache-2.0
*/
package token

import "github.com/hyperledger-labs/fabric-token-sdk/token/api"
import "github.com/hyperledger-labs/fabric-token-sdk/token/driver"

type IssueAction struct {
a api.IssueAction
a driver.IssueAction
}

func (i *IssueAction) Serialize() ([]byte, error) {
Expand All @@ -32,7 +32,7 @@ func (i *IssueAction) GetIssuer() []byte {
}

type TransferAction struct {
a api.TransferAction
a driver.TransferAction
}

func (t *TransferAction) Serialize() ([]byte, error) {
Expand Down
6 changes: 3 additions & 3 deletions token/certification.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ SPDX-License-Identifier: Apache-2.0
package token

import (
"github.com/hyperledger-labs/fabric-token-sdk/token/api"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
)

type CertificationManager struct {
c api.CertificationService
c driver.CertificationService
}

func (c *CertificationManager) NewCertificationRequest(ids []*token2.Id) ([]byte, error) {
Expand All @@ -27,7 +27,7 @@ func (c *CertificationManager) VerifyCertifications(ids []*token2.Id, certificat
}

type CertificationClient struct {
cc api.CertificationClient
cc driver.CertificationClient
}

func (c *CertificationClient) IsCertified(id *token2.Id) bool {
Expand Down
2 changes: 1 addition & 1 deletion token/core/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sort"
"sync"

api2 "github.com/hyperledger-labs/fabric-token-sdk/token/api"
api2 "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
)

var (
Expand Down
10 changes: 5 additions & 5 deletions token/core/fabtoken/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"

"github.com/hyperledger-labs/fabric-token-sdk/token/api"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
)

type TokenInformation struct {
Expand Down Expand Up @@ -68,8 +68,8 @@ func (i *IssueAction) GetSerializedOutputs() ([][]byte, error) {
return res, nil
}

func (i *IssueAction) GetOutputs() []api.Output {
var res []api.Output
func (i *IssueAction) GetOutputs() []driver.Output {
var res []driver.Output
for _, output := range i.Outputs {
res = append(res, output)
}
Expand Down Expand Up @@ -110,8 +110,8 @@ func (t *TransferAction) GetSerializedOutputs() ([][]byte, error) {
return res, nil
}

func (t *TransferAction) GetOutputs() []api.Output {
var res []api.Output
func (t *TransferAction) GetOutputs() []driver.Output {
var res []driver.Output
for _, output := range t.Outputs {
res = append(res, output)
}
Expand Down
18 changes: 9 additions & 9 deletions token/core/fabtoken/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ import (
fabric2 "github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view"

"github.com/hyperledger-labs/fabric-token-sdk/token/api"
"github.com/hyperledger-labs/fabric-token-sdk/token/core"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/identity"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/identity/fabric"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/vault"
)

type Driver struct {
}

func (d *Driver) PublicParametersFromBytes(params []byte) (api.PublicParameters, error) {
func (d *Driver) PublicParametersFromBytes(params []byte) (driver.PublicParameters, error) {
pp, err := fabtoken.NewPublicParamsFromBytes(params)
if err != nil {
return nil, err
}
return pp, nil
}

func (d *Driver) NewTokenService(sp view2.ServiceProvider, publicParamsFetcher api.PublicParamsFetcher, network string, channel api.Channel, namespace string) (api.TokenManagerService, error) {
func (d *Driver) NewTokenService(sp view2.ServiceProvider, publicParamsFetcher driver.PublicParamsFetcher, network string, channel driver.Channel, namespace string) (driver.TokenManagerService, error) {
qe := vault.NewVault(sp, channel, namespace).QueryEngine()
nodeIdentity := view2.GetIdentityProvider(sp).DefaultIdentity()
return fabtoken.NewService(
Expand All @@ -43,20 +43,20 @@ func (d *Driver) NewTokenService(sp view2.ServiceProvider, publicParamsFetcher a
qe,
identity.NewProvider(
sp,
map[api.IdentityUsage]identity.Mapper{
api.IssuerRole: fabric.NewMapper(fabric.X509MSPIdentity, nodeIdentity, fabric2.GetFabricNetworkService(sp, network).LocalMembership()),
api.AuditorRole: fabric.NewMapper(fabric.X509MSPIdentity, nodeIdentity, fabric2.GetFabricNetworkService(sp, network).LocalMembership()),
api.OwnerRole: fabric.NewMapper(fabric.X509MSPIdentity, nodeIdentity, fabric2.GetFabricNetworkService(sp, network).LocalMembership()),
map[driver.IdentityUsage]identity.Mapper{
driver.IssuerRole: fabric.NewMapper(fabric.X509MSPIdentity, nodeIdentity, fabric2.GetFabricNetworkService(sp, network).LocalMembership()),
driver.AuditorRole: fabric.NewMapper(fabric.X509MSPIdentity, nodeIdentity, fabric2.GetFabricNetworkService(sp, network).LocalMembership()),
driver.OwnerRole: fabric.NewMapper(fabric.X509MSPIdentity, nodeIdentity, fabric2.GetFabricNetworkService(sp, network).LocalMembership()),
},
),
), nil
}

func (d *Driver) NewValidator(params api.PublicParameters) (api.Validator, error) {
func (d *Driver) NewValidator(params driver.PublicParameters) (driver.Validator, error) {
return fabtoken.NewValidator(params.(*fabtoken.PublicParams)), nil
}

func (d *Driver) NewPublicParametersManager(params api.PublicParameters) (api.PublicParamsManager, error) {
func (d *Driver) NewPublicParametersManager(params driver.PublicParameters) (driver.PublicParamsManager, error) {
return fabtoken.NewPublicParamsManager(params.(*fabtoken.PublicParams)), nil
}

Expand Down
2 changes: 1 addition & 1 deletion token/core/fabtoken/loaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPDX-License-Identifier: Apache-2.0
package fabtoken

import (
api2 "github.com/hyperledger-labs/fabric-token-sdk/token/api"
api2 "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
)

type TokenVault interface {
Expand Down
4 changes: 2 additions & 2 deletions token/core/fabtoken/ppm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SPDX-License-Identifier: Apache-2.0
*/
package fabtoken

import "github.com/hyperledger-labs/fabric-token-sdk/token/api"
import "github.com/hyperledger-labs/fabric-token-sdk/token/driver"

type PublicParamsManager struct {
pp *PublicParams
Expand Down Expand Up @@ -42,7 +42,7 @@ func (v *PublicParamsManager) SetCertifier(bytes []byte) ([]byte, error) {
panic("SetCertifier cannot be called from fabtoken")
}

func (v *PublicParamsManager) PublicParameters() api.PublicParameters {
func (v *PublicParamsManager) PublicParameters() driver.PublicParameters {
return v.pp
}

Expand Down
38 changes: 19 additions & 19 deletions token/core/fabtoken/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/hash"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
"github.com/hyperledger-labs/fabric-token-sdk/token/api"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/vault/keys"
)

Expand All @@ -43,11 +43,11 @@ type service struct {
channel Channel
namespace string
pp *PublicParams
publicParamsFetcher api.PublicParamsFetcher
publicParamsFetcher driver.PublicParamsFetcher
publicParamsLoader PublicParamsLoader
qe QueryEngine

identityProvider api.IdentityProvider
identityProvider driver.IdentityProvider
ownerWallets []*ownerWallet
issuerWallets []*issuerWallet
auditorWallets []*auditorWallet
Expand All @@ -58,10 +58,10 @@ func NewService(
sp view2.ServiceProvider,
channel Channel,
namespace string,
publicParamsFetcher api.PublicParamsFetcher,
publicParamsFetcher driver.PublicParamsFetcher,
publicParamsLoader PublicParamsLoader,
qe QueryEngine,
identityProvider api.IdentityProvider,
identityProvider driver.IdentityProvider,
) *service {
return &service{
sp: sp,
Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *service) RegisterRecipientIdentity(id view.Identity, auditInfo []byte,
return nil
}

func (s *service) GenerateIssuerKeyPair(tokenType string) (api.Key, api.Key, error) {
func (s *service) GenerateIssuerKeyPair(tokenType string) (driver.Key, driver.Key, error) {
panic("implement me")
}

Expand All @@ -128,7 +128,7 @@ func (s *service) RegisterAuditInfo(id view.Identity, auditInfo []byte) error {
return nil
}

func (s *service) RegisterIssuer(label string, sk api.Key, pk api.Key) error {
func (s *service) RegisterIssuer(label string, sk driver.Key, pk driver.Key) error {
panic("implement me")
}

Expand All @@ -144,7 +144,7 @@ func (s *service) GetEnrollmentID(auditInfo []byte) (string, error) {
return string(auditInfo), nil
}

func (s *service) Issue(issuerIdentity view.Identity, typ string, values []uint64, owners [][]byte) (api.IssueAction, [][]byte, view.Identity, error) {
func (s *service) Issue(issuerIdentity view.Identity, typ string, values []uint64, owners [][]byte) (driver.IssueAction, [][]byte, view.Identity, error) {
for _, owner := range owners {
if len(owner) == 0 {
return nil, nil, nil, errors.Errorf("all recipients should be defined")
Expand Down Expand Up @@ -180,20 +180,20 @@ func (s *service) Issue(issuerIdentity view.Identity, typ string, values []uint6
nil
}

func (s *service) VerifyIssue(tr api.IssueAction, tokenInfos [][]byte) error {
func (s *service) VerifyIssue(tr driver.IssueAction, tokenInfos [][]byte) error {
// TODO:
return nil
}

func (s *service) DeserializeIssueAction(raw []byte) (api.IssueAction, error) {
func (s *service) DeserializeIssueAction(raw []byte) (driver.IssueAction, error) {
issue := &IssueAction{}
if err := issue.Deserialize(raw); err != nil {
return nil, errors.Wrap(err, "failed deserializing issue action")
}
return issue, nil
}

func (s *service) Transfer(txID string, wallet api.OwnerWallet, ids []*token2.Id, Outputs ...*token2.Token) (api.TransferAction, *api.TransferMetadata, error) {
func (s *service) Transfer(txID string, wallet driver.OwnerWallet, ids []*token2.Id, Outputs ...*token2.Token) (driver.TransferAction, *driver.TransferMetadata, error) {
id, err := wallet.GetRecipientIdentity()
if err != nil {
return nil, nil, errors.WithMessagef(err, "failed getting sender identity")
Expand Down Expand Up @@ -305,7 +305,7 @@ func (s *service) Transfer(txID string, wallet api.OwnerWallet, ids []*token2.Id
receiverIsSender[i] = s.ownerWallet(receiver) != nil
}

metadata := &api.TransferMetadata{
metadata := &driver.TransferMetadata{
Outputs: outputs,
Senders: signerIds,
SenderAuditInfos: senderAuditInfos,
Expand All @@ -319,12 +319,12 @@ func (s *service) Transfer(txID string, wallet api.OwnerWallet, ids []*token2.Id
return transfer, metadata, nil
}

func (s *service) VerifyTransfer(tr api.TransferAction, tokenInfos [][]byte) error {
func (s *service) VerifyTransfer(tr driver.TransferAction, tokenInfos [][]byte) error {
// TODO:
return nil
}

func (s *service) DeserializeTransferAction(raw []byte) (api.TransferAction, error) {
func (s *service) DeserializeTransferAction(raw []byte) (driver.TransferAction, error) {
t := &TransferAction{}
if err := t.Deserialize(raw); err != nil {
return nil, errors.Wrap(err, "failed deserializing transfer action")
Expand Down Expand Up @@ -354,28 +354,28 @@ func (s *service) DeserializeToken(outputRaw []byte, tokenInfoRaw []byte) (*toke
return tok, tokInfo.Issuer, nil
}

func (s *service) AuditorCheck(tokenRequest *api.TokenRequest, tokenRequestMetadata *api.TokenRequestMetadata, txID string) error {
func (s *service) AuditorCheck(tokenRequest *driver.TokenRequest, tokenRequestMetadata *driver.TokenRequestMetadata, txID string) error {
// TODO:
return nil
}

func (s *service) IdentityProvider() api.IdentityProvider {
func (s *service) IdentityProvider() driver.IdentityProvider {
return s.identityProvider
}

func (s *service) Validator() api.Validator {
func (s *service) Validator() driver.Validator {
return NewValidator(s.publicParams())
}

func (s *service) PublicParamsManager() api.PublicParamsManager {
func (s *service) PublicParamsManager() driver.PublicParamsManager {
return NewPublicParamsManager(s.publicParams())
}

func (s *service) NewCertificationRequest(ids []*token2.Id) ([]byte, error) {
return nil, nil
}

func (s *service) Certify(wallet api.CertifierWallet, ids []*token2.Id, tokens [][]byte, request []byte) ([][]byte, error) {
func (s *service) Certify(wallet driver.CertifierWallet, ids []*token2.Id, tokens [][]byte, request []byte) ([][]byte, error) {
return nil, nil
}

Expand Down
6 changes: 3 additions & 3 deletions token/core/fabtoken/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/pkg/errors"

"github.com/hyperledger-labs/fabric-token-sdk/token/api"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
)

const Coin = uint64(1000000000)
Expand Down Expand Up @@ -59,14 +59,14 @@ func (pp *PublicParams) Serialize() ([]byte, error) {
if err != nil {
return nil, err
}
return json.Marshal(&api.SerializedPublicParameters{
return json.Marshal(&driver.SerializedPublicParameters{
Identifier: PublicParameters,
Raw: raw,
})
}

func (pp *PublicParams) Deserialize(raw []byte) error {
publicParams := &api.SerializedPublicParameters{}
publicParams := &driver.SerializedPublicParameters{}
if err := json.Unmarshal(raw, publicParams); err != nil {
return err
}
Expand Down
Loading

0 comments on commit 7ec05a6

Please sign in to comment.