Skip to content

Commit

Permalink
token and audit db (hyperledger-labs#542)
Browse files Browse the repository at this point in the history
Signed-off-by: Arne Rutjes <arne123@gmail.com>
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
  • Loading branch information
arner authored Feb 22, 2024
1 parent 7d79529 commit 5d2adde
Show file tree
Hide file tree
Showing 109 changed files with 5,227 additions and 4,376 deletions.
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ jobs:
dlog-fabric-t1-extras,
dlog-fabric-t2,
dlog-fabric-t3,
dlog-fabric-t4,
fabtoken-dlog-fabric,
dloghsm-fabric-t1,
dloghsm-fabric-t2,
Expand Down
39 changes: 37 additions & 2 deletions docs/core-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,44 @@ token:
network: default # the name of the network this TMS refers to (Fabric, Orion, etc)
channel: testchannel # the name of the network's channel this TMS refers to, if applicable
namespace: tns # the name of the channel's namespace this TMS refers to, if applicable
# sections dedicated to the databases definitions.
# These databases are used to keep track of transactions, tokens, and audit records where it applies.
# Three databases are available:
# ttxdb: store records of transactions
# tokendb: store information about the available tokens
# auditdb: store audit records about the audited transactions
# The databases can be instantiated in isolation. a different backend for each db, or with a shared backend, depending on the driver used.
# In the following example, we have ttxdb and auditdb using the same backed, via the `unity` dirver, and the tokendb having its own separated backed

# configuration for the unity db driver. It uses the `sql` driver as backend
unitydb:
persistence:
opts:
createSchema: true
driver: sqlite
maxOpenConns: 10
dataSource: /some/path/unitydb
ttxdb:
persistence:
type: unity
auditdb:
persistence:
type: unity
tokendb:
persistence:
# The sql driver uses golangs database/sql package internally.
# In theory you can use any driver if you import it in your application;
# for instance `import _ "github.com/mattn/go-sqlite3"` for the cgo version of sqlite.
# See https://github.com/golang/go/wiki/SQLDrivers. We only tested with github.com/lib/pq
# and modernc.org/sqlite, and it's likely that other drivers don't work exactly the same.
# To try a new sql driver, add a test here: token/services/db/sql/transactions_test.go.
type: sql # type can be one of unity, sql or memory.
opts:
createSchema: true # create tables programmatically
driver: sqlite # in the application, `import _ "modernc.org/sqlite"`
maxOpenConns: 10 # by default this is 0 (unlimited), sets the maximum number of open connections to the database
dataSource: /some/path/tokendb
# sections dedicated to the definition of the wallets
publicParameters:
path: # path to the file containing the public parameters. This field is optional
wallets:
# Default cache size reference that can be used by any wallet that support caching
defaultCacheSize: 3
Expand Down
4 changes: 0 additions & 4 deletions fungible.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ integration-tests-dlog-fabric-t2:
integration-tests-dlog-fabric-t3:
cd ./integration/token/fungible/dlog; export FAB_BINS=$(FAB_BINS); ginkgo $(GINKGO_TEST_OPTS) --focus "T3" .

.PHONY: integration-tests-dlog-fabric-t4
integration-tests-dlog-fabric-t4:
cd ./integration/token/fungible/dlog; export FAB_BINS=$(FAB_BINS); ginkgo $(GINKGO_TEST_OPTS) --focus "T4" .

.PHONY: integration-tests-fabtoken-dlog-fabric
integration-tests-fabtoken-dlog-fabric:
cd ./integration/token/fungible/mixed; export FAB_BINS=$(FAB_BINS); ginkgo $(GINKGO_TEST_OPTS) .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package fabric
package common

import (
"bytes"
Expand Down
75 changes: 75 additions & 0 deletions integration/nwo/token/common/ne.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package common

import (
"fmt"
"os"
"path/filepath"
"time"

api2 "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common"
sfcnode "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/generators"
topology2 "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/topology"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)

type TokenPlatform interface {
TokenGen(keygen common.Command) (*gexec.Session, error)
PublicParametersFile(tms *topology2.TMS) string
GetContext() api2.Context
PublicParameters(tms *topology2.TMS) []byte
GetPublicParamsGenerators(driver string) generators.PublicParamsGenerator
PublicParametersDir() string
GetBuilder() api2.Builder
TokenDir() string
UpdatePublicParams(tms *topology2.TMS, pp []byte)
}

type NetworkHandler struct {
TokenPlatform TokenPlatform
CryptoMaterialGenerators map[string]generators.CryptoMaterialGenerator
CASupports map[string]CAFactory

EventuallyTimeout time.Duration
ColorIndex int
}

func (p *NetworkHandler) TTXDBSQLDataSourceDir(peer *sfcnode.Node) string {
return filepath.Join(p.TokenPlatform.GetContext().RootDir(), "fsc", "nodes", peer.ID(), "ttxdb")
}

func (p *NetworkHandler) TokensDBSQLDataSourceDir(peer *sfcnode.Node) string {
return filepath.Join(p.TokenPlatform.GetContext().RootDir(), "fsc", "nodes", peer.ID(), "tokensdb")
}

func (p *NetworkHandler) AuditDBSQLDataSourceDir(peer *sfcnode.Node) string {
return filepath.Join(p.TokenPlatform.GetContext().RootDir(), "fsc", "nodes", peer.ID(), "auditdb")
}

func (p *NetworkHandler) DBPath(root string, tms *topology2.TMS) string {
return "file:" +
filepath.Join(
root,
fmt.Sprintf("%s_%s_%s", tms.Network, tms.Channel, tms.Namespace)+"_db.sqlite",
) + "?_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)"
}

func (p *NetworkHandler) FSCNodeKVSDir(peer *sfcnode.Node) string {
return filepath.Join(p.TokenPlatform.GetContext().RootDir(), "fsc", "nodes", peer.ID(), "kvs")
}

func (p *NetworkHandler) DeleteDBs(node *sfcnode.Node) {
for _, path := range []string{p.TokensDBSQLDataSourceDir(node)} {
logger.Infof("remove all [%s]", path)
Expect(os.RemoveAll(path)).ToNot(HaveOccurred())
Expect(os.MkdirAll(path, 0775)).ToNot(HaveOccurred(), "failed to create [%s]", path)
}
}
Loading

0 comments on commit 5d2adde

Please sign in to comment.