This plugin allows Cacti
to persist Fabric Block general data and basic information about transactions into some storage (currently to a PostgreSQL
database, but this concept can be extended further).
Data in the database can later be analyzed and viewed in a GUI tool.
GUI tool is in project root directory of Cacti project in GUI folder. cacti/packages/cacti-ledger-browser
- This plugin was only tested with small test ledgers. Running it to synchronize with old ledgers will take a lot of time.
- For now, the database schema is not considered public and can change over time (i.e., writing own application that reads data directly from the database is discouraged).
- All the methods must be called directly on the plugin instance for now.
Clone the git repository on your local machine. Follow these instructions that will get you a copy of the project up and running on your local machine for development and testing purposes.
In the root of the project, execute the command to install and build the dependencies. It will also build this persistence plugin:
yarn run configure
Instantiate a new PluginPersistenceFabrickBlock
instance:
import { PluginPersistenceFabric } from "../../../main/typescript/plugin-fabric-persistence-block";
import { v4 as uuidv4 } from "uuid";
PluginInstance = new PluginPersistenceFabric({
gatewayOptions,
apiClient,
logLevel: testLogLevel,
instanceId: uuidv4(),
connectionString:
"postgresql://postgres:your-super-secret-and-long-postgres-password@localhost:5432/postgres",
});
// Initialize the connection to the DB
PluginInstance.onPluginInit();
Alternatively, import PluginPersistenceFabric
from the plugin package and use it to create a plugin.
import { PluginPersistenceFabric } from "@hyperledger/plugin-fabric-persistence-block";
import { PluginImportType } from "@hyperledger/cactus-core-api";
import { v4 as uuidv4 } from "uuid";
const factory = new PluginFactoryPersistenceFabricBlock({
pluginImportType: PluginImportType.Local,
});
const persistencePlugin = await factory.create({
instanceId: uuidv4(),
apiClient: new SocketIOApiClient(apiConfigOptions),
logLevel: "info",
connectionString:
"postgresql://postgres:your-super-secret-and-long-postgres-password@localhost:5432/postgres",
});
// Initialize the connection to the DB
persistencePlugin.onPluginInit();
onPluginInit it also creates database structure if this is first time run
// Start synchronization with ledger. // To synchronize ledger
you individually
// Show current status of the plugin PluginInstance.getStatus();
- Most of the plugin functionalities are currently not available through OpenAPI interface, please use direct method calls instead.
- Should be called before using the plugin.
- Close the connection to the DB, cleanup any allocated resources.
- Get status report of this instance of persistence plugin.
- Start the block synchronization process. New blocks from the ledger will be parsed and pushed to the database.
- Start the block synchronization process. New blocks from the ledger will be parsed and pushed to the database. Should be used periodically.
- Stop the block synchronization process.
- Walk through all the blocks that could not be synchronized with the DB for some reasons and list them
- Walk through all the blocks that are listed as not be synchronized with the DB for some reasons and try push them into DB from ledger.
- can try many times to use this
- set the last block in ledger which we consider valid by our party and synchronize only to this point in ledger If some blocks above this number are already in database they will not be removed.
- Synchronize entire first N number of blocks of ledger state with the database. It is a good start and easy to check if everything is correctly set.
To run all the tests for this persistence fabric plugin to ensure it's working correctly execute the following from the root of the cactus
project:
npx jest cactus-plugin-fabric-persistence-block
We welcome contributions to Hyperledger Cacti in many forms, and there’s always plenty to do!
Please review CONTIRBUTING.md to get started.
- Contains reference token ABIs used to call and identify token transfers.
- Contains OpenAPI definition.
- Database schema for Ethereum data.
- Folder that contains web service endpoint definitions if present.
- Main persistent plugin logic file
- Integration test of various plugin functionalities.
- Current setup assume use of Supabase that has utility for generating types from the database schema.
- We use this tool to generate type definitions and store them in
./src/main/typescript/db-client/database.types.ts
- Upstream instructions: https://supabase.com/docs/guides/api/generating-types
- Step by step manual on updating the types (must be done after changing the database schema):
- Install
supabase
package - Init and start development supabase server:
npx supabase init
npx supabase start
- Fill in current schema:
-
psql -h localhost -p 54322 -U postgres -d postgres -a -f src/main/sql/schema.sql
(password:postgres
)
-
- Generate the file with type definitions:
npx supabase gen types typescript --schema public --local > src/main/typescript/db-client/database.types.ts
- Cleanup:
npx supabase stop
rm -rf ./supabase
- Install
- Can be used to test GUI applications without running entire ledger / persistence setup.
-
psql -h localhost -p 54322 -U postgres -d postgres -a -f src/test/sql/insert-test-data.sql
(password:postgres
)
This distribution is published under the Apache License Version 2.0 found in the LICENSE file.