Commit graph

52 commits

Author SHA1 Message Date
Stanislav Jakuschevskij
40e627dcf5
Update README and ci
Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:48 +01:00
Stanislav Jakuschevskij
06c7445e91
Replace panic with error handling
Starting from the processor.Block.Process all methods now return errors
if something goes wrong with unpacking of the blocks and reading the
transactions. In each function where the error is being propagated back
to client it is wrapped in a message with the function name. This makes
it easier to track down the error and see the propagation chain. Finally
the error is logged to the terminal and the go routine shuts down
gracefully. The graceful shutdown executes all deferred functions which
close the context, the checkpointer and the gateway.

Before panics were used everywhere which was an issue because the
unpacking of the blocks happened in a go routine. When a panic happens
in a go routine only the deferred functions of the go routine are called
but not those of the client which lead to unexpected behavior.

The transact function is also executed in a go routine therefore the
same typo of error handling was implemented there.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:48 +01:00
Stanislav Jakuschevskij
1364645c6c
Fix simulated failure issue
Before all transactions were processed and when the failure was
simulated a message was printed and all the transactions still
processed. Now the store returns an error when the failure is simulated
which the listener expects so that it can gracefully shutdown the system
and close the context. The context must be closed correctly or the
checkpointer won't save the last processed transactionId to the file
system.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:48 +01:00
Stanislav Jakuschevskij
dfd860d8e9
Execute transactions in go routines concurrently
Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:48 +01:00
Stanislav Jakuschevskij
81efd2cc61
Refactor parser package, decompose files
Every struct was put in its own file. Every method which is not used
outside the parser package was given package scope. All interfaces were
removed, they are implemented by the structs which are now used
everywhere needed as return values. There is no clear benefit of using
interfaces in this sample.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:48 +01:00
Stanislav Jakuschevskij
624f65da12
Implement graceful shutdown of listen function
Before when pressing 'ctrl+c' and stopping the go program non of the
deferred functions in listen.go were called. A standard procedure for
stopping goroutines with context was implemented which shuts down the
program gracefully. Logs were added to notify the user that the shutdown
was successful.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:48 +01:00
Stanislav Jakuschevskij
b04bda5b11
Extract block processor and store from listener
Created packages for the flat file store and the processor and moved
functions, variables and constants from listener.go to those packages.
Encapsulated everything not used outside the packages, introduced
model.go files which later might be extracted into a model package and
renamed parser/parsedBlock.go to parser/block.go.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:47 +01:00
Stanislav Jakuschevskij
c4db079e0c
Implement caching
Added caching util function with tests and applied in:

- parser.Block.Transactions(),
- parser.Payload.ChannelHeader(),
- parser.Payload.SignatureHeader(),
- parser.NamespaceReadWriteSet.ReadWriteSet(),
- parser.EndorserTransaction.ReadWriteSets(),

methods, as it was in the typescript sample.

Corrected Println usage and added comments to util functions.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:47 +01:00
Stanislav Jakuschevskij
095bf304b4
Implement store
Persisting ledger writes to the file system into the store.log file in
the application-go directory. The write values are converted from bytes
to a string when the read write sets are unwrapped in the transaction
processor.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:47 +01:00
Stanislav Jakuschevskij
bd0c03356b
Implement block and transaction processor
Added block processor struct and the process method.
Implemented getting valid transactions from the last processed index.
Added data structures needed for the store.

Decomposed the parser.Block.Transactions() method into readable chunks.

Added transaction processor struct and process method. Unwrapping
read write set data from the transaction, mapping to a new "write"
data structure and passing down to the store.

Store is an empty function and will be implemented next.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:47 +01:00
Stanislav Jakuschevskij
8ae2909b9b
Implement block parsing
Removed Block and Transaction interfaces and unused statusCode function.
Using the struct instead of the interfaces now.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:47 +01:00
Stanislav Jakuschevskij
2c43e03591
Encapsulate block parser in a package
Created parser, contract and utils packages and extracted each piece of
functionality into its own files. Removed "Get" prefix from methods and
changed return values from interfaces to structs.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:47 +01:00
Stanislav Jakuschevskij
1eaf609711
Implement Transaction interface
For the GetCreator() method return the identity.Identity interface was
also implemented.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:47 +01:00
Stanislav Jakuschevskij
81743872bd
Implement payload interface
Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:47 +01:00
Stanislav Jakuschevskij
dc638199b1
Add endorser tx unwrapping test
Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:47 +01:00
Stanislav Jakuschevskij
7244639e7c
Add off-chain-data go client application
Created project structure, fixed typos. Implemented connect.go and
getAllAssets.go. The latter uses an assetTransferBasic struct which
provides a simple API for basic asset operations like create, transfer,
etc.

Added transact.go with some util functions. Using google uuid package to
generate random UUIDs for the transactions.

Implemented pretty printing of JSON results.

Implemented app.go entry point with error handling. The existing
commands are getAllAssets, transact and listen. They can be called from
the command line via: "go run . <command> <command> ...". They will be
executed in order and if a command is not known an the application
panics and aborts before executing any of the commands.

Implementing listen.go. Added checkpointer, context setups, call to
BlockEvents and all the interfaces needed for parsing. Started
implementing the interfaces needed to represent a block bottom up in
structs. Finished NamespaceReadWriteSet, ReadWriteSet and
EndorserTransaction.

Signed-off-by: Stanislav Jakuschevskij <stas@two-giants.com>
2025-02-24 13:14:46 +01:00
Mark S. Lewis
8538e32437
Update Gradle version and shadow plugin (#1278)
The shadow plugin is now maintained by the GradleUp organization. Change
to use the current plugin ID and latest version.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-12-11 08:04:56 -05:00
Mark S. Lewis
e23bc6714e Simplify Java client error-handling example
The latest fabric-gateway client API release (v1.7.0) includes the gRPC error
details in the GatewayExcetion stack trace so it is not necessary to
programmatically access them to demonstrate that they are present.

This change updates the asset-transfer-basic/application-gateway-java
sample to simplify the updateNonExistentAsset example method. It also:

- Updates all samples to use the latest fabric-gateway release.
- Adds equivalent Maven POM files for fabric-gateway application samples.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-10-24 23:45:04 -04:00
Mark S. Lewis
b931df3a5f Explicitly specify hash in client applications
For some signing implementations, such as ed25519, a non-default hash
implementation must be specified when creating the Gateway connection in
client applications. Rather than relying on the default hash algorithm,
it is probably good practice in general to specify an algorithm that is
compatible with your signing implementation.

This change explicitly specifies the hash algorithm to raise visibility
of the option to select the hash algorithm.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-10-07 12:25:40 -04:00
Mark S. Lewis
e37e991c4c Update applications to use fabric-gateway v1.6.0
Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-09-25 13:18:45 +09:00
Mark S. Lewis
76088d0273 Remove legacy sample applications
The removed samples make use of deprecated legacy client SDKs. They all
have equivalent samples implemented using the currently supported Fabric
Gateway client API, and are therefore redundant.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-06-19 10:38:52 -04:00
Mark S. Lewis
c077dae79c Update TypeScript implementations
- Dependency updates
- ESLint flat configuration format, replacing deprecated configuration
- Minor fixes to compile and lint issues
- Consistent TypeScript formatting with .editorconfig

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-06-18 06:51:58 -04:00
Mark S. Lewis
db86460086 Use latest v2.5 fabric-chaincode-java
- Update Gradle wrappers
- Update shadow plugin

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2024-02-25 22:13:26 -05:00
Mark S. Lewis
0f4f62c340 Use fabric-gateway v1.4
Also update some GitHub Actions versions.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2023-10-25 17:30:29 +09:00
Mark S. Lewis
6e71f634e2 Fixes for build breakages
Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2023-09-19 13:08:40 -04:00
Mark S. Lewis
e93cfacf1f Use Java gRPC instead of Netty API to establish TLS connections
Include specific gRPC TLS implementation in dependencies instead of relying on an appropriate one to be present as a transitive dependency.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
2023-05-08 14:17:21 -04:00
Dave Enyeart
97a400ea28
Bump couchdb to 3.2.2 (#1008)
Bump couchdb to 3.2.2.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
2023-03-17 13:08:55 +00:00
Mark S. Lewis
10e9377555 Avoid explicit import of grpc-js or fabric-protos in TypeScript apps
Rely on the dependencies of @hyperledger/fabric-gateway making these packages transitively available. Having explicit dependency versions in the application can cause type conflicts due to private member changes in the gRPC Client class across versions.

Also fix some missing or incorrect Node types and engines version contraints.

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
2023-02-10 11:36:41 -05:00
Mark S. Lewis
4109e741e4
Parse transaction creator to Identity in off_chain_data samples (#883)
Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
2022-12-13 13:18:50 +00:00
Mark S. Lewis
c323c95807
Update samples to use fabric-gateway v1.1.1 (#842)
Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
2022-10-20 17:43:55 +01:00
Mark S. Lewis
51397fe78a
Add getCreator() to parsed transaction in off_chain_data sample (#806)
Example of how the client identity that submitted a transaction can be obtained.

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
2022-08-03 11:35:31 +01:00
Mark S. Lewis
41717d76f2
Fix link in off_chain_data README (#793)
Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
2022-07-18 08:56:17 +01:00
Mark S. Lewis
f8e7bfe803
Update Gateway samples for v1.1 release (#779)
- Updated build to use Go 1.18 since Go 1.16 is no longer supported.
- Use Java 11 in updated samples, and take advantage of new language features.

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
2022-06-30 15:46:32 +01:00
Mark S. Lewis
adfd850e64 Use new default call options API in Java off_chain_data sample
Also use hyperlinks for easier navigation to code mentioned in the README.

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
2022-06-14 11:34:10 -04:00
Mark S. Lewis
636a273a48
Java off-chain data store sample using Fabric Gateway (#749)
Also minor implementation changes to TypeScript sample for better consistency between implementations.

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
2022-05-26 13:42:41 +01:00
Mark S. Lewis
05791d30bc
Off-chain data sample using Fabric Gateway client API (#736)
Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
2022-05-17 12:49:22 +01:00
Indranil Majumder
c1615b31ee Checking both the old and new lifecycle name
Signed-off-by: Indranil Majumder <indranil.majumder@navis.com>
2021-09-29 17:14:35 -04:00
Indranil Majumder
7a727eb69a changes to support couchdb 3.1.1
Signed-off-by: Indranil Majumder <indranil.majumder@navis.com>
2021-09-29 17:14:35 -04:00
Yuki Kondo
d5d8ff1539
Fix off_chain_data to put data to off-chain database (#457)
The off_chain_data sample fails to put data to the off-chain
database. The application does not read fetched blocks because
it uses the old interface of `addBlockListener()` to handle
block events.

This PR fixes the application to use the latest block listener
and build the off-chain database.

Signed-off-by: Yuki Kondo <yuki.kondo.ob@hitachi.com>
2021-07-07 16:40:46 -04:00
David Enyeart
cbf263dc3b Update "master" branch references to "main"
Update "master" branch references to "main".

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
2021-03-19 19:23:09 -04:00
Brett Logan
08aaaf0313
Update Javascript and Typescript Deps (#403)
Update all of the Node deps to 2.2.<latest>
and regenerate existing package-lock.json files

Signed-off-by: Brett Logan <brett.t.logan@ibm.com>

Co-authored-by: Brett Logan <brett.t.logan@ibm.com>
2021-01-13 12:19:31 -05:00
Nikhil Gupta
2e4a3275ce add full path to off chain data sample
Signed-off-by: Nikhil Gupta <ngupta@symbridge.com>
2020-12-14 10:33:11 -05:00
NIKHIL E GUPTA
6d196bd9df Move off chain data samples to basic chaincode
Signed-off-by: NIKHIL E GUPTA <ngupta@symbridge.com>
2020-10-07 03:20:07 -04:00
Arnaud J Le Hors
2e3683c419
Add missing Copyright in some files (#163)
Signed-off-by: Arnaud J Le Hors <lehors@us.ibm.com>
2020-05-19 15:50:48 +01:00
nikhil550
b0d73fefe1
[FAB-17818] Update documetation in Fabric samples repo (#170)
Signed-off-by: NIKHIL E GUPTA <negupta@us.ibm.com>

Co-authored-by: NIKHIL E GUPTA <negupta@us.ibm.com>
2020-04-30 17:54:51 +02:00
denyeart
11e4c23a35
Update samples to use v2.0 or later dependencies (#161)
Update application and chaincode dependendencies to use v2.0 or
later versions in package.json, build.gradle, pom.xml files.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
2020-04-17 14:29:37 +02:00
nikhil550
faac18e6da
[FAB-17461] Move off_chain_data sample to test network (#122)
Signed-off-by: NIKHIL E GUPTA <negupta@us.ibm.com>

Co-authored-by: NIKHIL E GUPTA <negupta@us.ibm.com>
2020-03-20 14:23:54 +00:00
harrisob
3dbe116a30
FAB-17456 fabric-samples read ccp (#117)
Have the application read the common connection profile to
build a JSON object used for the gateway connect and for
a fabric-ca client instance.

Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
2020-02-18 14:05:50 +00:00
Matthew B White
94ac8b6050 Update to use beta levels of modules (#88)
Signed-off-by: Matthew B White <whitemat@uk.ibm.com>
2019-12-13 20:20:58 +00:00
Varun Agarwal
91c720a7ff [FAB-16390] Added filter for invalid transactions
Signed-off-by: Varun Agarwal <varunagarwal315@gmail.com>
Change-Id: Idb6c57e047bba9a176b312f86d05c2ee21aeb175
(cherry picked from commit f86ec95726)
2019-08-25 19:09:06 +00:00