Skip to content

Commit

Permalink
Merge pull request #124 from hyperledger-labs/f-reduce-fab-dep
Browse files Browse the repository at this point in the history
introduce more abstractions
  • Loading branch information
adecaro committed Oct 22, 2021
2 parents 9907d56 + d553adc commit 33cacbc
Show file tree
Hide file tree
Showing 62 changed files with 977 additions and 1,659 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect
github.com/google/addlicense v1.0.0 // indirect
github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8 // indirect
github.com/hyperledger-labs/fabric-smart-client v0.0.0-20211015115528-782c5aee50b7
github.com/hyperledger-labs/fabric-smart-client v0.0.0-20211022125455-3c72131a3c4d
github.com/hyperledger/fabric v1.4.0-rc1.0.20210722174351-9815a7a8f0f7
github.com/hyperledger/fabric-chaincode-go v0.0.0-20210718160520-38d29fabecb9
github.com/hyperledger/fabric-protos-go v0.0.0-20210911123859-041d13f0980c
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,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-20211015115528-782c5aee50b7 h1:w+Da49/tLGTJIB8JChvEZLUb+knU4YBpbwSJ1tmt/8E=
github.com/hyperledger-labs/fabric-smart-client v0.0.0-20211015115528-782c5aee50b7/go.mod h1:5nb+I767ih87ABv96XRWxVXVncVdolPv3MvjlQ7hkIQ=
github.com/hyperledger-labs/fabric-smart-client v0.0.0-20211022125455-3c72131a3c4d h1:bA2WeOpFoZJTHLIpqnEuUuEJ/Hw3G6IpHICCR2WV63U=
github.com/hyperledger-labs/fabric-smart-client v0.0.0-20211022125455-3c72131a3c4d/go.mod h1:iGRusTQNJMc3GhHDpI1uaQRMqt61ZVDEOGjWteVJh8c=
github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go v1.2.3-alpha.1 h1:vBvo0PNm82ht7wpBjlYY4ZHxV3YprCfdVd3T4JG9vBw=
github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go v1.2.3-alpha.1/go.mod h1:POCGO/RK9YDfgdhuyqjoD9tRNtWfK7Rh5AYYmsb1Chc=
github.com/hyperledger-labs/weaver-dlt-interoperability/sdks/fabric/go-sdk v1.2.3-alpha.1.0.20210812140206-37f430515b8c h1:pKr8VnHlduEgdInwLWykYAw+lpUizjQJaJ8I5fVoRUo=
Expand Down Expand Up @@ -1478,8 +1478,8 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c h1:taxlMj0D/1sOAuv/CbSD+MMDof2vbyPTqz5FNYKpXt8=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211020174200-9d6173849985 h1:LOlKVhfDyahgmqa97awczplwkjzNaELFg3zRIJ13RYo=
golang.org/x/sys v0.0.0-20211020174200-9d6173849985/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
8 changes: 4 additions & 4 deletions integration/token/tcc/basic/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ func TestAll(network *integration.Infrastructure) {

// Transfer by IDs
txID := issueCash(network, "", "CHF", 17, "alice")
txID = transferCashByIDs(network, "alice", "", []*token2.Id{{TxId: txID, Index: 0}}, 17, "bob")
redeemCashByIDs(network, "bob", "", []*token2.Id{{TxId: txID, Index: 0}}, 17)
txID = transferCashByIDs(network, "alice", "", []*token2.ID{{TxId: txID, Index: 0}}, 17, "bob")
redeemCashByIDs(network, "bob", "", []*token2.ID{{TxId: txID, Index: 0}}, 17)
}

/*
Expand Down Expand Up @@ -347,7 +347,7 @@ func transferCash(network *integration.Infrastructure, id string, wallet string,
}
}

func transferCashByIDs(network *integration.Infrastructure, id string, wallet string, ids []*token2.Id, amount uint64, receiver string, errorMsgs ...string) string {
func transferCashByIDs(network *integration.Infrastructure, id string, wallet string, ids []*token2.ID, amount uint64, receiver string, errorMsgs ...string) string {
txid, err := network.Client(id).CallView("transfer", common.JSONMarshall(&views.Transfer{
Wallet: wallet,
Type: "",
Expand Down Expand Up @@ -397,7 +397,7 @@ func redeemCash(network *integration.Infrastructure, id string, wallet string, t
Expect(err).NotTo(HaveOccurred())
}

func redeemCashByIDs(network *integration.Infrastructure, id string, wallet string, ids []*token2.Id, amount uint64) {
func redeemCashByIDs(network *integration.Infrastructure, id string, wallet string, ids []*token2.ID, amount uint64) {
_, err := network.Client(id).CallView("redeem", common.JSONMarshall(&views.Redeem{
Wallet: wallet,
Type: "",
Expand Down
2 changes: 1 addition & 1 deletion integration/token/tcc/basic/views/redeem.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Redeem struct {
// Wallet is the identifier of the wallet that owns the tokens to redeem
Wallet string
// TokenIDs contains a list of token ids to redeem. If empty, tokens are selected on the spot.
TokenIDs []*token.Id
TokenIDs []*token.ID
// Type of tokens to redeem
Type string
// Amount to redeem
Expand Down
4 changes: 2 additions & 2 deletions integration/token/tcc/basic/views/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Transfer struct {
// Wallet is the identifier of the wallet that owns the tokens to transfer
Wallet string
// TokenIDs contains a list of token ids to transfer. If empty, tokens are selected on the spot.
TokenIDs []*token.Id
TokenIDs []*token.ID
// Type of tokens to transfer
Type string
// Amount to transfer
Expand Down Expand Up @@ -139,7 +139,7 @@ func (t *TransferWithSelectorView) Call(context view.Context) (interface{}, erro
// The sender tries to select the requested amount of tokens of the passed type.
// If a failure happens, the sender retries up to 5 times, waiting 10 seconds after each failure.
// This is just an example, any other policy can be implemented.
var ids []*token.Id
var ids []*token.ID
var sum token.Quantity

for i := 0; i < 5; i++ {
Expand Down
10 changes: 5 additions & 5 deletions token/certification.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ type CertificationManager struct {
c driver.CertificationService
}

func (c *CertificationManager) NewCertificationRequest(ids []*token2.Id) ([]byte, error) {
func (c *CertificationManager) NewCertificationRequest(ids []*token2.ID) ([]byte, error) {
return c.c.NewCertificationRequest(ids)
}

func (c *CertificationManager) Certify(wallet *CertifierWallet, ids []*token2.Id, tokens [][]byte, request []byte) ([][]byte, error) {
func (c *CertificationManager) Certify(wallet *CertifierWallet, ids []*token2.ID, tokens [][]byte, request []byte) ([][]byte, error) {
return c.c.Certify(wallet.w, ids, tokens, request)
}

func (c *CertificationManager) VerifyCertifications(ids []*token2.Id, certifications [][]byte) error {
func (c *CertificationManager) VerifyCertifications(ids []*token2.ID, certifications [][]byte) error {
return c.c.VerifyCertifications(ids, certifications)
}

type CertificationClient struct {
cc driver.CertificationClient
}

func (c *CertificationClient) IsCertified(id *token2.Id) bool {
func (c *CertificationClient) IsCertified(id *token2.ID) bool {
return c.cc.IsCertified(id)
}

func (c *CertificationClient) RequestCertification(ids ...*token2.Id) error {
func (c *CertificationClient) RequestCertification(ids ...*token2.ID) error {
return c.cc.RequestCertification(ids...)
}
6 changes: 3 additions & 3 deletions token/core/fabtoken/certification.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
)

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

func (s *Service) Certify(wallet driver.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
}

func (s *Service) VerifyCertifications(ids []*token2.Id, certifications [][]byte) error {
func (s *Service) VerifyCertifications(ids []*token2.ID, certifications [][]byte) error {
return nil
}
4 changes: 2 additions & 2 deletions token/core/fabtoken/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"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"
fabric3 "github.com/hyperledger-labs/fabric-token-sdk/token/services/fabric"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/vault"
)

Expand All @@ -40,11 +41,10 @@ func (d *Driver) NewTokenService(sp view2.ServiceProvider, publicParamsFetcher d
return nil, errors.WithMessagef(err, "fabric channel [%s:%s] does not exists", network, channel)
}

qe := vault.NewVault(sp, ch, namespace).QueryEngine()
qe := vault.New(sp, ch.Name(), namespace, fabric3.NewVault(ch)).QueryEngine()
nodeIdentity := view2.GetIdentityProvider(sp).DefaultIdentity()
return fabtoken.NewService(
sp,
ch,
namespace,
fabtoken.NewPublicParamsManager(&fabtoken.VaultPublicParamsLoader{
TokenVault: qe,
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 @@ -18,7 +18,7 @@ type VaultTokenLoader struct {
TokenVault api2.QueryEngine
}

func (s *VaultTokenLoader) GetTokens(ids []*token.Id) ([]string, []*token.Token, error) {
func (s *VaultTokenLoader) GetTokens(ids []*token.ID) ([]string, []*token.Token, error) {
return s.TokenVault.GetTokens(ids...)
}

Expand Down
2 changes: 1 addition & 1 deletion token/core/fabtoken/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
)

func (s *Service) Transfer(txID string, wallet driver.OwnerWallet, ids []*token2.Id, Outputs ...*token2.Token) (driver.TransferAction, *driver.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
16 changes: 4 additions & 12 deletions token/core/fabtoken/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,34 @@ Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package fabtoken

import (
"sync"

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

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

type Channel interface {
Name() string
Vault() *fabric.Vault
}

type PublicParamsLoader interface {
Load() (*PublicParams, error)
ForceFetch() (*PublicParams, error)
}

type QueryEngine interface {
IsMine(id *token2.Id) (bool, error)
IsMine(id *token2.ID) (bool, error)
ListUnspentTokens() (*token2.UnspentTokens, error)
ListAuditTokens(ids ...*token2.Id) ([]*token2.Token, error)
ListAuditTokens(ids ...*token2.ID) ([]*token2.Token, error)
ListHistoryIssuedTokens() (*token2.IssuedTokens, error)
PublicParams() ([]byte, error)
}

type TokenLoader interface {
GetTokens(ids []*token2.Id) ([]string, []*token2.Token, error)
GetTokens(ids []*token2.ID) ([]string, []*token2.Token, error)
}

type PublicParametersManager interface {
Expand All @@ -45,7 +40,6 @@ type PublicParametersManager interface {

type Service struct {
SP view2.ServiceProvider
Channel Channel
Namespace string
PPM PublicParametersManager
TokenLoader TokenLoader
Expand All @@ -61,7 +55,6 @@ type Service struct {

func NewService(
sp view2.ServiceProvider,
channel Channel,
namespace string,
ppm PublicParametersManager,
tokenLoader TokenLoader,
Expand All @@ -71,7 +64,6 @@ func NewService(
) *Service {
s := &Service{
SP: sp,
Channel: channel,
Namespace: namespace,
TokenLoader: tokenLoader,
QE: qe,
Expand Down
6 changes: 3 additions & 3 deletions token/core/zkatdlog/nogh/certifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
token3 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
)

func (s *Service) NewCertificationRequest(ids []*token3.Id) ([]byte, error) {
func (s *Service) NewCertificationRequest(ids []*token3.ID) ([]byte, error) {
return nil, nil
}

func (s *Service) Certify(wallet api3.CertifierWallet, ids []*token3.Id, tokens [][]byte, request []byte) ([][]byte, error) {
func (s *Service) Certify(wallet api3.CertifierWallet, ids []*token3.ID, tokens [][]byte, request []byte) ([][]byte, error) {
return nil, nil
}

func (s *Service) VerifyCertifications(ids []*token3.Id, certifications [][]byte) error {
func (s *Service) VerifyCertifications(ids []*token3.ID, certifications [][]byte) error {
return nil
}
5 changes: 3 additions & 2 deletions token/core/zkatdlog/nogh/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/validator"
zkatdlog "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
fabric3 "github.com/hyperledger-labs/fabric-token-sdk/token/services/fabric"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/vault"
)

Expand Down Expand Up @@ -49,8 +50,8 @@ func (d *Driver) NewTokenService(sp view2.ServiceProvider, publicParamsFetcher d
namespace,
sp,
publicParamsFetcher,
&zkatdlog.VaultTokenCommitmentLoader{TokenVault: vault.NewVault(sp, ch, namespace).QueryEngine()},
vault.NewVault(sp, ch, namespace).QueryEngine(),
&zkatdlog.VaultTokenCommitmentLoader{TokenVault: vault.New(sp, ch.Name(), namespace, fabric3.NewVault(ch)).QueryEngine()},
vault.New(sp, ch.Name(), namespace, fabric3.NewVault(ch)).QueryEngine(),
identity.NewProvider(
sp,
map[driver.IdentityUsage]identity.Mapper{
Expand Down
8 changes: 4 additions & 4 deletions token/core/zkatdlog/nogh/loaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ import (

type TokenVault interface {
PublicParams() ([]byte, error)
GetTokenInfos(ids []*token3.Id, callback api2.QueryCallbackFunc) error
GetTokenCommitments(ids []*token3.Id, callback api2.QueryCallbackFunc) error
GetTokenInfos(ids []*token3.ID, callback api2.QueryCallbackFunc) error
GetTokenCommitments(ids []*token3.ID, callback api2.QueryCallbackFunc) error
}

type VaultTokenCommitmentLoader struct {
TokenVault TokenVault
}

func (s *VaultTokenCommitmentLoader) GetTokenCommitments(ids []*token3.Id) ([]*token.Token, error) {
func (s *VaultTokenCommitmentLoader) GetTokenCommitments(ids []*token3.ID) ([]*token.Token, error) {
var tokens []*token.Token
if err := s.TokenVault.GetTokenCommitments(ids, func(id *token3.Id, bytes []byte) error {
if err := s.TokenVault.GetTokenCommitments(ids, func(id *token3.ID, bytes []byte) error {
if len(bytes) == 0 {
return errors.Errorf("failed getting state for id [%v], nil value", id)
}
Expand Down
11 changes: 6 additions & 5 deletions token/core/zkatdlog/nogh/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ package nogh
import (
"strconv"

"github.com/IBM/mathlib"
math "github.com/IBM/mathlib"
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/pkg/errors"

"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/token"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/transfer"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/vault/keys"
token3 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
"github.com/pkg/errors"
)

func (s *Service) Transfer(txID string, wallet driver.OwnerWallet, ids []*token3.Id, outputTokens ...*token3.Token) (driver.TransferAction, *driver.TransferMetadata, error) {
func (s *Service) Transfer(txID string, wallet driver.OwnerWallet, ids []*token3.ID, outputTokens ...*token3.Token) (driver.TransferAction, *driver.TransferMetadata, error) {
logger.Debugf("Prepare Transfer Action [%s,%v]", txID, ids)

var tokens []*token.Token
Expand All @@ -38,7 +39,7 @@ func (s *Service) Transfer(txID string, wallet driver.OwnerWallet, ids []*token3
pp := s.PublicParams()
for _, id := range ids {
// Token Info
outputID, err := keys.CreateFabtokenKey(id.TxId, int(id.Index))
outputID, err := keys.CreateFabtokenKey(id.TxId, id.Index)
if err != nil {
return nil, nil, errors.Wrapf(err, "error creating output ID: %v", id)
}
Expand All @@ -53,7 +54,7 @@ func (s *Service) Transfer(txID string, wallet driver.OwnerWallet, ids []*token3
}

// Token and InputID
outputID, err = keys.CreateTokenKey(id.TxId, int(id.Index))
outputID, err = keys.CreateTokenKey(id.TxId, id.Index)
if err != nil {
return nil, nil, errors.Wrapf(err, "error creating output ID: %v", id)
}
Expand Down
11 changes: 6 additions & 5 deletions token/core/zkatdlog/nogh/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ package nogh
import (
"sync"

"github.com/IBM/mathlib"
math "github.com/IBM/mathlib"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
"github.com/pkg/errors"

"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/ppm"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/token"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/crypto/validator"
api3 "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
"github.com/hyperledger-labs/fabric-token-sdk/token/services/vault/keys"
token3 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
"github.com/pkg/errors"
)

const (
Expand All @@ -32,13 +33,13 @@ type Channel interface {
}

type TokenCommitmentLoader interface {
GetTokenCommitments(ids []*token3.Id) ([]*token.Token, error)
GetTokenCommitments(ids []*token3.ID) ([]*token.Token, error)
}

type QueryEngine interface {
IsMine(id *token3.Id) (bool, error)
IsMine(id *token3.ID) (bool, error)
ListUnspentTokens() (*token3.UnspentTokens, error)
ListAuditTokens(ids ...*token3.Id) ([]*token3.Token, error)
ListAuditTokens(ids ...*token3.ID) ([]*token3.Token, error)
ListHistoryIssuedTokens() (*token3.IssuedTokens, error)
}

Expand Down
Loading

0 comments on commit 33cacbc

Please sign in to comment.