├── .gitignore
├── .travis.yml
├── CONTRIBUTING.rst
├── LICENSE
├── LICENSE-docs
├── README.md
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── media
├── repo-banner.sketch
└── repo-banner@2x.png
├── pom.xml
├── settings.gradle
└── src
├── main
└── java
│ ├── META-INF
│ └── MANIFEST.MF
│ └── com
│ └── bigchaindb
│ ├── annotations
│ └── Exclude.java
│ ├── api
│ ├── AbstractApi.java
│ ├── AccountApi.java
│ ├── AssetsApi.java
│ ├── BlocksApi.java
│ ├── MetaDataApi.java
│ ├── OutputsApi.java
│ ├── TransactionsApi.java
│ └── ValidatorsApi.java
│ ├── builders
│ ├── BigchainDbConfigBuilder.java
│ └── BigchainDbTransactionBuilder.java
│ ├── constants
│ ├── BigchainDbApi.java
│ └── Operations.java
│ ├── exceptions
│ └── TransactionNotFoundException.java
│ ├── json
│ ├── factory
│ │ └── GsonEmptyCheckTypeAdapterFactory.java
│ └── strategy
│ │ ├── AssetSerializer.java
│ │ ├── AssetsDeserializer.java
│ │ ├── CustomExclusionStrategy.java
│ │ ├── InputSerializer.java
│ │ ├── MetaDataDeserializer.java
│ │ ├── MetaDataSerializer.java
│ │ ├── OutputsDeserializer.java
│ │ ├── TransactionDeserializer.java
│ │ ├── TransactionIdExclusionStrategy.java
│ │ ├── TransactionsDeserializer.java
│ │ └── ValidatorDeserializer.java
│ ├── model
│ ├── Account.java
│ ├── ApiEndpoints.java
│ ├── Asset.java
│ ├── Assets.java
│ ├── BigChainDBGlobals.java
│ ├── Block.java
│ ├── Condition.java
│ ├── Connection.java
│ ├── DataModel.java
│ ├── Details.java
│ ├── FulFill.java
│ ├── GenericCallback.java
│ ├── Input.java
│ ├── MetaData.java
│ ├── MetaDatas.java
│ ├── Output.java
│ ├── Outputs.java
│ ├── Transaction.java
│ ├── Transactions.java
│ ├── ValidTransaction.java
│ ├── Validator.java
│ ├── ValidatorPubKey.java
│ └── Validators.java
│ ├── util
│ ├── Base58.java
│ ├── DriverUtils.java
│ ├── JsonUtils.java
│ ├── KeyPairUtils.java
│ ├── NetworkUtils.java
│ ├── ScannerUtil.java
│ └── TypeAdapter.java
│ └── ws
│ ├── BigchainDbWSSessionManager.java
│ └── MessageHandler.java
└── test
├── java
└── com
│ └── bigchaindb
│ ├── AbstractTest.java
│ ├── api
│ ├── AbstractApiTest.java
│ ├── AccountApiTest.java
│ ├── AssetsApiTest.java
│ ├── BlocksApiTest.java
│ ├── MetaDataApiTest.java
│ ├── OutputsApiTest.java
│ ├── TransactionCreateApiTest.java
│ ├── TransactionTransferApiTest.java
│ └── ValidatorsApiTest.java
│ ├── builders
│ └── BigchainDBConnectionManagerTest.java
│ ├── keys
│ ├── PrivateKeyTest.java
│ └── PublicKeyTest.java
│ ├── util
│ ├── KeyPairUtilsTest.java
│ └── ScannerUtilsTest.java
│ └── ws
│ ├── ValidTransactionMessageHandler.java
│ └── WsMonitorTest.java
└── resources
├── log4j.properties
└── test.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | # Gradle specific .gitignore, see https://github.com/github/gitignore/blob/master/Gradle.gitignore
2 | .gradle
3 | /build/
4 |
5 | # Ignore Gradle GUI config
6 | gradle-app.setting
7 |
8 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
9 | !gradle-wrapper.jar
10 |
11 | # Cache of project
12 | .gradletasknamecache
13 |
14 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
15 | # gradle/wrapper/gradle-wrapper.properties
16 |
17 | # IntelliJ specific files
18 | .idea
19 | *.iml
20 | out
21 |
22 |
23 | # Maven
24 | target/
25 |
26 | # Eclipse specific
27 | .classpath
28 | .project
29 | .settings/
30 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # Copyright BigchainDB GmbH and BigchainDB contributors
2 | # SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
3 | # Code is Apache-2.0 and docs are CC-BY-4.0
4 |
5 | language: java
6 | sudo: required
7 | jdk:
8 | - oraclejdk8
9 | install: true
10 |
11 | services:
12 | - docker
13 |
14 | install:
15 | - docker pull bigchaindb/bigchaindb
16 | - docker run --interactive --rm --tty --volume $HOME/bigchaindb_docker:/data --env BIGCHAINDB_DATABASE_HOST=172.17.0.1 bigchaindb/bigchaindb -y configure localmongodb
17 | - docker run --detach --name=mongodb --publish=27017:27017 --restart=always --volume=$HOME/mongodb_docker/db:/data/db --volume=$HOME/mongodb_docker/configdb:/data/configdb mongo:3.4.9 --replSet=bigchain-rs
18 | - docker run --detach --name=bigchaindb --publish=9984:9984 --restart=always --volume=$HOME/bigchaindb_docker:/data bigchaindb/bigchaindb start
19 |
20 | #before_script:
21 | # - mvn install:install-file -Dfile=$TRAVIS_BUILD_DIR/libs/java-crypto-conditions-2.0.0-SNAPSHOT.jar -DgroupId=org.interledger -DartifactId=java-crypto-conditions -Dversion=2.0.0-SNAPSHOT -Dpackaging=jar
22 |
23 | cache:
24 | directories:
25 | - $HOME/.m2
26 |
27 | branches:
28 | only:
29 | - master
30 |
31 | script:
32 | - mvn clean install
33 | - ./gradlew clean install
34 |
--------------------------------------------------------------------------------
/CONTRIBUTING.rst:
--------------------------------------------------------------------------------
1 |
2 | .. Copyright BigchainDB GmbH and BigchainDB contributors
3 | SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | Code is Apache-2.0 and docs are CC-BY-4.0
5 |
6 | .. highlight:: shell
7 |
8 | ============
9 | Contributing
10 | ============
11 |
12 | Contributions are welcome, and they are greatly appreciated! Every
13 | little bit helps, and credit will always be given.
14 |
15 | You can contribute in many ways:
16 |
17 | Types of Contributions
18 | ----------------------
19 |
20 | Report Bugs
21 | ~~~~~~~~~~~
22 |
23 | Report bugs at https://github.com/bigchaindb/java-bigchaindb-driver/issues.
24 |
25 | If you are reporting a bug, please include:
26 |
27 | * Your operating system name and version.
28 | * Any details about your local setup that might be helpful in troubleshooting.
29 | * Detailed steps to reproduce the bug.
30 |
31 | Fix Bugs
32 | ~~~~~~~~
33 |
34 | Look through the GitHub issues for bugs. Anything tagged with "bug"
35 | and "help wanted" is open to whoever wants to implement it.
36 |
37 | Implement Features
38 | ~~~~~~~~~~~~~~~~~~
39 |
40 | Look through the GitHub issues for features. Anything tagged with "enhancement"
41 | and "help wanted" is open to whoever wants to implement it.
42 |
43 | Write Documentation
44 | ~~~~~~~~~~~~~~~~~~~
45 |
46 | bigchaindb-driver could always use more documentation, whether as part of the
47 | official bigchaindb-driver docs, in docstrings, or even on the web in blog posts,
48 | articles, and such.
49 |
50 | Submit Feedback
51 | ~~~~~~~~~~~~~~~
52 |
53 | The best way to send feedback is to file an issue at https://github.com/bigchaindb/java-bigchaindb-driver/issues.
54 |
55 | If you are proposing a feature:
56 |
57 | * Explain in detail how it would work.
58 | * Keep the scope as narrow as possible, to make it easier to implement.
59 | * Remember that this is a volunteer-driven project, and that contributions
60 | are welcome :)
61 |
62 | Get Started!
63 | ------------
64 |
65 | Ready to contribute? Here's how to set up `java-bigchaindb-driver`_ for local
66 | development.
67 |
68 | 1. Fork the `java-bigchaindb-driver`_ repo on GitHub.
69 | 2. Clone your fork locally and enter into the project::
70 |
71 | $ git clone git@github.com:your_name_here/java-bigchaindb-driver.git
72 | $ cd java-bigchaindb-driver/
73 |
74 | 3. Create a branch for local development::
75 |
76 | $ git checkout -b name-of-your-bugfix-or-feature
77 |
78 | Now you can make your changes locally.
79 |
80 | 4. Write tests ;-)
81 |
82 | 5. Test!
83 |
84 | 6. Commit your changes and push your branch to GitHub::
85 |
86 | $ git add .
87 | $ git commit -m "Your detailed description of your changes."
88 | $ git push origin name-of-your-bugfix-or-feature
89 |
90 | 7. Submit a pull request through the GitHub website.
91 |
92 |
93 | Pull Request Guidelines
94 | -----------------------
95 |
96 | Before you submit a pull request, check that it meets these guidelines:
97 |
98 | 1. The pull request should include tests.
99 | 2. If the pull request adds functionality, the docs should be updated. Put
100 | your new functionality into a function with a docstring, and add the
101 | feature to the list in README.rst.
102 | 3. The pull request should work for JS and node. Travis or others would be an interesting
103 | way for automate the tests...
104 |
105 |
106 | Dependency on Bigchaindb
107 | ~~~~~~~~~~~~~~~~~~~~~~~~
108 |
109 | This version is compatible from BigchainDB server v1.00
110 |
111 | .. _bigchaindb-driver: https://github.com/bigchaindb/java-bigchaindb-driver
112 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
--------------------------------------------------------------------------------
/LICENSE-docs:
--------------------------------------------------------------------------------
1 | The official BigchainDB documentation,
2 | except for the short code snippets embedded within it,
3 | is licensed under a Creative Commons Attribution-ShareAlike 4.0 International license,
4 | the full text of which can be found
5 | at http://creativecommons.org/licenses/by-sa/4.0/legalcode
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
6 |
7 | [](https://travis-ci.com/bigchaindb/java-bigchaindb-driver)
8 | [](https://gitter.im/bigchaindb/bigchaindb)
9 | [](https://www.bigchaindb.com)
10 |
11 | # Official Java and Android Driver for BigchainDB
12 |
13 | **Please note**: This driver is compatible with Android API 23 and later.
14 |
15 | ## Compatibility
16 |
17 | | BigchainDB Server | BigchainDB Java Driver |
18 | | ----------------- |------------------------------|
19 | | `2.x` | `1.x` |
20 |
21 | ## Contents
22 |
23 | * [Installation](#installation)
24 | * [Usage](#usage)
25 | * [API Wrappers](#api-wrappers)
26 | * [BigchainDB Documentation](#bigchaindb-documentation)
27 | * [Authors](#authors)
28 | * [Licenses](#licenses)
29 |
30 | ## Installation
31 |
32 | The build system supports both Maven and Gradle.
33 |
34 | ### Maven Users
35 |
36 | In your `pom.xml` file, add `bigchaindb-driver` as a dependency:
37 |
38 | ```xml
39 |
40 | com.bigchaindb
41 | bigchaindb-driver
42 | 1.0
43 |
44 | ```
45 |
46 | then
47 |
48 | ```
49 | mvn clean install
50 | ```
51 |
52 | ### Gradle Users
53 |
54 | In your `build.gradle` file, add `bigchaindb-driver` as a dependency:
55 |
56 | ```
57 | dependencies {
58 | implementation 'com.bigchaindb.bigchaindb-driver:1.2'
59 | }
60 | ```
61 |
62 | then
63 |
64 | ```
65 | ./gradlew install
66 | ```
67 |
68 | ## Usage
69 |
70 | > A sample of an end-to-end CREATE and TRANSFER operation is available in the gist [https://gist.github.com/innoprenuer/d4c6798fe5c0581c05a7e676e175e515](https://gist.github.com/innoprenuer/d4c6798fe5c0581c05a7e676e175e515)
71 |
72 | ### Set Up Your Configuration
73 |
74 | #### Single-Node Setup
75 |
76 | ```java
77 | BigchainDbConfigBuilder
78 | .baseUrl("https://node1.example.com/")
79 | .addToken("header1", )
80 | .addToken("header2", ).setup();
81 | ```
82 |
83 | #### Multi-Node Setup (More Robust and Reliable)
84 |
85 | > **Note** - multi-node setup is only available in version 1.2 and later
86 | >
87 | > **Assumption** - The following setup assumes that all nodes are all connected within same BigchainDB network.
88 |
89 | ```java
90 | //define connections
91 | Map conn1Config = new HashMap(),
92 | conn2Config = new HashMap();
93 |
94 | //define headers for connections
95 | Map headers1 = new HashMap();
96 | Map headers2 = new HashMap();
97 |
98 | //config header for connection 1
99 | headers1.put("app_id", "");
100 | headers1.put("app_key", "");
101 |
102 | //config header for connection 2
103 | headers2.put("app_id", "");
104 | headers2.put("app_key", "");
105 |
106 | //config connection 1
107 | conn1Config.put("baseUrl", "https://node1.mysite.com/");
108 | conn1Config.put("headers", headers1);
109 | Connection conn1 = new Connection(conn1Config);
110 |
111 | //config connection 2
112 | conn2Config.put("baseUrl", "https://node2.mysite.com/");
113 | conn2Config.put("headers", headers2);
114 | Connection conn2 = new Connection(conn2Config);
115 |
116 | //add connections
117 | List connections = new ArrayList();
118 | connections.add(conn1);
119 | connections.add(conn2);
120 | //...You can add as many nodes as you want
121 |
122 | BigchainDbConfigBuilder
123 | .addConnections(connections)
124 | .setTimeout(60000) //override default timeout of 20000 milliseconds
125 | .setup();
126 |
127 | }
128 | ```
129 |
130 | ### Example: Prepare Keys, Assets and Metadata
131 |
132 | ```java
133 | // prepare your keys
134 | net.i2p.crypto.eddsa.KeyPairGenerator edDsaKpg = new net.i2p.crypto.eddsa.KeyPairGenerator();
135 | KeyPair keyPair = edDsaKpg.generateKeyPair();
136 |
137 | // New asset
138 | Map assetData = new TreeMap() {{
139 | put("city", "Berlin, DE");
140 | put("temperature", "22");
141 | put("datetime", new Date().toString());
142 | }};
143 |
144 | // New metadata
145 | MetaData metaData = new MetaData();
146 | metaData.setMetaData("what", "My first BigchainDB transaction");
147 | ```
148 |
149 | ### Example: Create an Asset
150 |
151 | Performing a CREATE transaction in BigchainDB allocates or issues a digital asset.
152 |
153 | ```java
154 | // Set up, sign, and send your transaction
155 | Transaction createTransaction = BigchainDbTransactionBuilder
156 | .init()
157 | .addAssets(assetData, TreeMap.class)
158 | .addMetaData(metaData)
159 | .operation(Operations.CREATE)
160 | .buildAndSign((EdDSAPublicKey) keyPair.getPublic(), (EdDSAPrivateKey) keyPair.getPrivate())
161 | .sendTransaction();
162 | ```
163 |
164 | ### Example: Transfer an Asset
165 |
166 | Performing a TRANSFER transaction in BigchainDB changes an asset's ownership (or, more accurately, authorized signers):
167 |
168 | ```java
169 | // Generate a new keypair to TRANSFER the asset to
170 | KeyPair targetKeypair = edDsaKpg.generateKeyPair();
171 |
172 | // Describe the output you are fulfilling on the previous transaction
173 | final FulFill spendFrom = new FulFill();
174 | spendFrom.setTransactionId(createTransaction.getId());
175 | spendFrom.setOutputIndex(0);
176 |
177 | // Change the metadata if you want
178 | MetaData transferMetadata = new MetaData();
179 | metaData.setMetaData("what2", "My first BigchainDB transaction");
180 |
181 | // the asset's ID is equal to the ID of the transaction that created it
182 | String assetId = createTransaction.getId();
183 |
184 | // By default, the 'amount' of a created digital asset == "1". So we spend "1" in our TRANSFER.
185 | String amount = "1";
186 |
187 | // Use the previous transaction's asset and TRANSFER it
188 | Transaction transferTransaction = BigchainDbTransactionBuilder
189 | .init()
190 | .addMetaData(metaData)
191 |
192 | // source keypair is used in the input, because the current owner is "spending" the output to transfer it
193 | .addInput(null, spendFrom, (EdDSAPublicKey) keyPair.getPublic())
194 |
195 | // after this transaction, the target 'owns' the asset, so, the new output includes the target's public key
196 | .addOutput(output, (EdDSAPublicKey) targetKeypair.getPublic())
197 |
198 | // reference the asset by ID when doing a transfer
199 | .addAssets(assetId, String.class)
200 | .operation(Operations.TRANSFER)
201 |
202 | // the source key signs the transaction to authorize the transfer
203 | .buildAndSign((EdDSAPublicKey) keyPair.getPublic(), (EdDSAPrivateKey) keyPair.getPrivate())
204 | .sendTransaction();
205 | ```
206 |
207 | ### Example: Setup Config with WebSocket Listener
208 |
209 | ```java
210 | public class MyCustomMonitor implements MessageHandler {
211 | @Override
212 | public void handleMessage(String message) {
213 | ValidTransaction validTransaction = JsonUtils.fromJson(message, ValidTransaction.class);
214 | }
215 | }
216 |
217 | // config
218 | BigchainDbConfigBuilder
219 | .baseUrl("https://api.example.net")
220 | .addToken("app_id", "2bbaf3ff")
221 | .addToken("app_key", "c929b708177dcc8b9d58180082029b8d")
222 | .webSocketMonitor(new MyCustomMonitor())
223 | .setup();
224 | ```
225 |
226 | ### More Examples
227 |
228 | #### Example: Create a Transaction (without signing and without sending)
229 |
230 | ```java
231 | // Set up your transaction but only build it
232 | Transaction transaction = BigchainDbTransactionBuilder
233 | .init()
234 | .addAssets(assetData, TreeMap.class)
235 | .addMetaData(metaData)
236 | .operation(Operations.CREATE)
237 | .buildOnly((EdDSAPublicKey) keyPair.getPublic());
238 | ```
239 |
240 | #### Example: Create and Sign Transaction (without sending it to the ledger)
241 |
242 | ```java
243 | // Set up your transaction
244 | Transaction transaction = BigchainDbTransactionBuilder
245 | .init()
246 | .addAssets(assetData, TreeMap.class)
247 | .addMetaData(metaData)
248 | .operation(Operations.CREATE)
249 | .buildAndSignOnly((EdDSAPublicKey) keyPair.getPublic(), (EdDSAPrivateKey) keyPair.getPrivate());
250 | ```
251 |
252 | ## API Wrappers
253 |
254 | ### Transactions
255 |
256 | #### Send a Transaction
257 |
258 | ```java
259 | TransactionsApi.sendTransaction(Transaction transaction) throws IOException
260 | ```
261 |
262 | #### Send a Transaction with Callback
263 |
264 | ```java
265 | TransactionsApi.sendTransaction(Transaction transaction, final GenericCallback callback)
266 | ```
267 |
268 | #### Get Transaction given a Transaction Id
269 |
270 | ```java
271 | Transaction TransactionsApi.getTransactionById(String id) throws IOException
272 | ```
273 |
274 | #### Get Transaction given an Asset Id
275 |
276 | ```java
277 | Transactions TransactionsApi.getTransactionsByAssetId(String assetId, Operations operation)
278 | ```
279 |
280 | ### Outputs
281 |
282 | #### Get Outputs given a public key
283 |
284 | ```java
285 | Outputs getOutputs(String publicKey) throws IOException
286 | ```
287 |
288 | #### Get Spent Outputs given a public key
289 |
290 | ```java
291 | Outputs getSpentOutputs(String publicKey) throws IOException
292 | ```
293 |
294 | #### Get Unspent Outputs given a public key
295 |
296 | ```java
297 | Outputs getUnspentOutputs(String publicKey) throws IOException
298 | ```
299 |
300 | ### Assets
301 |
302 | #### Get Assets given search key
303 |
304 | ```java
305 | Assets getAssets(String searchKey) throws IOException
306 | ```
307 |
308 | #### Get Assets given search key and limit
309 |
310 | ```java
311 | Assets getAssetsWithLimit(String searchKey, String limit) throws IOException
312 | ```
313 |
314 | ### Blocks
315 |
316 | #### Get Blocks given block id
317 |
318 | ```java
319 | Block getBlock(String blockId) throws IOException
320 | ```
321 |
322 | #### Get Blocks given transaction id
323 |
324 | ```java
325 | List getBlocksByTransactionId(String transactionId) throws IOException
326 | ```
327 |
328 | ### MetaData
329 |
330 | #### Get MetaData given search key
331 |
332 | ```java
333 | MetaDatas getMetaData(String searchKey) throws IOException
334 | ```
335 |
336 | #### Get MetaData given search key and limit
337 |
338 | ```java
339 | MetaDatas getMetaDataWithLimit(String searchKey, String limit) throws IOException
340 | ```
341 |
342 | ### Validators
343 |
344 | #### Gets the the local validators set of a given node
345 |
346 | ```java
347 | Validators getValidators() throws IOException
348 | ```
349 |
350 | ## BigchainDB Documentation
351 |
352 | * [HTTP API Reference](https://docs.bigchaindb.com/projects/server/en/latest/http-client-server-api.html)
353 | * [The Transaction Model](https://docs.bigchaindb.com/projects/server/en/latest/metadata-models/transaction-model.html?highlight=crypto%20conditions)
354 | * [Inputs and Outputs](https://docs.bigchaindb.com/projects/server/en/latest/metadata-models/inputs-outputs.html)
355 | * [Asset Transfer](https://docs.bigchaindb.com/projects/py-driver/en/latest/usage.html#asset-transfer)
356 | * [All BigchainDB Documentation](https://docs.bigchaindb.com/)
357 |
358 | ## Authors
359 |
360 | Inspired by [http://github.com/authenteq/java-bigchaindb-driver](http://github.com/authenteq/java-bigchaindb-driver).
361 |
362 | The [BigchainDB](https://bigchaindb.com) team and others including:
363 |
364 | * @bodia
365 | * @alvin-reyes
366 | * @agwego
367 | * @nf-PostQuantum
368 | * @Rokko11
369 | * @tzclucian
370 | * @kremalicious
371 | * @avanaur
372 | * @GerardoGa
373 | * @bakaoh
374 | * @innoprenuer
375 |
376 | ## Release Process
377 |
378 | To execute a release build with Maven, define `performRelease` to enable GPG signing:
379 |
380 | `mvn clean package install -DperformRelease`
381 |
382 | ## Licenses
383 |
384 | See [LICENSE](LICENSE) and [LICENSE-docs](LICENSE-docs).
385 |
386 | Exception: `src/main/java/com/bigchaindb/util/Base58.java` has a different license; see the comments at the top of that file for more information.
387 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'eclipse'
3 | apply plugin: 'maven'
4 | apply plugin: 'checkstyle'
5 |
6 | targetCompatibility = 1.8
7 | sourceCompatibility = 1.8
8 |
9 | group = 'com.bigchaindb'
10 | version = '0.1'
11 | description = 'Java Driver for Bigchaindb'
12 |
13 | jar {
14 | manifest {
15 | attributes 'Implementation-Title': description,
16 | 'Implementation-Version': version,
17 | 'Main-Class': 'com.bigchaindb.Main'
18 | }
19 | }
20 |
21 | repositories {
22 | maven { url "http://repo.maven.apache.org/maven2" }
23 | mavenLocal()
24 | }
25 |
26 | dependencies {
27 | compile 'com.squareup.okhttp3:okhttp:3.9.0'
28 | compile 'net.i2p.crypto:eddsa:0.2.0'
29 | compile 'commons-codec:commons-codec:1.10'
30 | compile 'com.google.code.gson:gson:2.8.2'
31 | compile 'org.slf4j:slf4j-api:1.7.25'
32 | compile 'com.bigchaindb:cryptoconditions:1.0'
33 | compile 'org.bouncycastle:bcprov-jdk15on:1.54'
34 | compile 'org.glassfish.tyrus.bundles:tyrus-standalone-client:1.9'
35 |
36 | testCompile 'junit:junit:4.12'
37 | testCompile 'org.apache.logging.log4j:log4j-core:2.9.1'
38 | testCompile 'org.slf4j:slf4j-log4j12:1.7.25'
39 | testCompile group: 'net.jadler', name: 'jadler-all', version: '1.3.0'
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bigchaindb/java-bigchaindb-driver/54372a3d29eef5ce43cf5e76ab4b879fb616a8a3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jul 28 23:55:35 SAST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/media/repo-banner.sketch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bigchaindb/java-bigchaindb-driver/54372a3d29eef5ce43cf5e76ab4b879fb616a8a3/media/repo-banner.sketch
--------------------------------------------------------------------------------
/media/repo-banner@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bigchaindb/java-bigchaindb-driver/54372a3d29eef5ce43cf5e76ab4b879fb616a8a3/media/repo-banner@2x.png
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | 4.0.0
7 | com.bigchaindb
8 | bigchaindb-driver
9 | 1.2
10 | jar
11 |
12 | bigchaindb-driver
13 | Official Java driver for bigchaindb
14 | http://github.com/bigchaindb/java-bigchaindb-driver
15 |
16 |
17 |
18 | The Apache Software License, Version 2.0
19 | http://www.apache.org/licenses/LICENSE-2.0.txt
20 | repo
21 |
22 |
23 |
24 |
25 |
26 | Manan Patel
27 | manan@bigchaindb.com
28 | Bigchaindb
29 | http://www.bigchaindb.com
30 |
31 |
32 |
33 |
34 | scm:git:git://github.com/bigchaindb/java-crypto-conditions.git
35 | scm:git:ssh://github.com:bigchaindb/java-crypto-conditions.git
36 | http://github.com/bigchaindb/java-crypto-conditions/tree/master
37 |
38 |
39 |
40 | true
41 | 1.8
42 | UTF-8
43 | 1.8
44 |
45 |
46 |
47 |
48 | release-sign-artifacts
49 |
50 |
51 | performRelease
52 | true
53 |
54 |
55 |
56 |
57 |
58 | org.apache.maven.plugins
59 | maven-gpg-plugin
60 | 1.6
61 |
62 |
63 | sign-artifacts
64 | verify
65 |
66 | sign
67 |
68 |
69 |
70 | --pinentry-mode
71 | loopback
72 |
73 | ${gpg.keyname}
74 | ${gpg.keyname}
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | maven-assembly-plugin
88 |
89 |
90 | package
91 |
92 | single
93 |
94 |
95 |
96 |
97 |
98 | jar-with-dependencies
99 |
100 |
101 |
102 |
103 | org.apache.maven.plugins
104 | maven-compiler-plugin
105 | 3.6.2
106 |
107 | 1.8
108 | 1.8
109 |
110 |
111 |
112 | org.apache.maven.plugins
113 | maven-source-plugin
114 | 2.2.1
115 |
116 |
117 | attach-sources
118 |
119 | jar-no-fork
120 |
121 |
122 |
123 |
124 |
125 | org.apache.maven.plugins
126 | maven-javadoc-plugin
127 |
128 |
129 | attach-javadocs
130 |
131 | jar
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 | com.squareup.okhttp3
142 | okhttp
143 | 3.9.0
144 |
145 |
146 | net.i2p.crypto
147 | eddsa
148 | 0.2.0
149 |
150 |
151 | com.google.api-client
152 | google-api-client
153 | 1.23.0
154 |
155 |
156 | commons-codec
157 | commons-codec
158 | 1.10
159 | test
160 |
161 |
162 | com.google.code.gson
163 | gson
164 | 2.8.2
165 |
166 |
167 |
168 | org.slf4j
169 | slf4j-api
170 | 1.7.25
171 |
172 |
173 |
174 | org.apache.logging.log4j
175 | log4j-core
176 | 2.9.1
177 | test
178 |
179 |
180 |
181 | org.slf4j
182 | slf4j-log4j12
183 | 1.7.25
184 | test
185 |
186 |
187 |
188 | com.bigchaindb
189 | cryptoconditions
190 | 1.0
191 |
192 |
193 | org.bouncycastle
194 | bcprov-jdk15on
195 | 1.54
196 |
197 |
198 | junit
199 | junit
200 | 4.12
201 | test
202 |
203 |
204 | org.glassfish.tyrus.bundles
205 | tyrus-standalone-client
206 | 1.9
207 |
208 |
209 | net.jadler
210 | jadler-all
211 | 1.3.0
212 | test
213 |
214 |
215 |
216 |
217 |
218 |
219 | oss.sonatype.org
220 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
221 |
222 |
223 | oss.sonatype.org
224 | https://oss.sonatype.org/content/repositories/snapshots
225 |
226 |
227 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'java-bigchaindb-driver'
2 |
--------------------------------------------------------------------------------
/src/main/java/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: com.bigchaindb.Main
3 |
4 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/annotations/Exclude.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.annotations;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * The Interface Exclude.
15 | */
16 | @Retention(RetentionPolicy.RUNTIME)
17 | @Target({ElementType.FIELD})
18 | public @interface Exclude {
19 |
20 | }
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/api/AbstractApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.api;
7 | import okhttp3.MediaType;
8 |
9 |
10 |
11 | /**
12 | * The Class AbstractApi.
13 | */
14 | public abstract class AbstractApi {
15 |
16 |
17 | /** The Constant JSON. */
18 | protected static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/api/AccountApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.api;
7 |
8 | import java.security.KeyPair;
9 | import java.security.PrivateKey;
10 | import java.security.PublicKey;
11 | import java.security.spec.InvalidKeySpecException;
12 | import java.security.spec.PKCS8EncodedKeySpec;
13 | import java.security.spec.X509EncodedKeySpec;
14 |
15 | import net.i2p.crypto.eddsa.EdDSAPrivateKey;
16 | import net.i2p.crypto.eddsa.EdDSAPublicKey;
17 | import net.i2p.crypto.eddsa.Utils;
18 | import org.slf4j.LoggerFactory;
19 |
20 | import com.bigchaindb.model.Account;
21 |
22 | /**
23 | * The Class AccountApi.
24 | */
25 | public class AccountApi extends AbstractApi {
26 |
27 | private static final org.slf4j.Logger log = LoggerFactory.getLogger( AccountApi.class );
28 |
29 | /**
30 | * Creates the account.
31 | *
32 | * @return the account
33 | */
34 | public static Account createAccount() {
35 | log.debug( "createAccount Call" );
36 | Account newAccount = new Account();
37 | net.i2p.crypto.eddsa.KeyPairGenerator edDsaKpg = new net.i2p.crypto.eddsa.KeyPairGenerator();
38 | KeyPair keyPair = edDsaKpg.generateKeyPair();
39 | newAccount.setPrivateKey(keyPair.getPrivate());
40 | newAccount.setPublicKey(keyPair.getPublic());
41 | log.debug( "createAccount Call : " + newAccount.getPublicKey().toString() );
42 | return newAccount;
43 | }
44 |
45 | /**
46 | * Load account.
47 | *
48 | * @param publicKey
49 | * the public key
50 | * @param privateKey
51 | * the private key
52 | * @return the account
53 | * @throws InvalidKeySpecException
54 | * the invalid key spec exception
55 | */
56 | public static Account loadAccount(String publicKey, String privateKey) throws InvalidKeySpecException {
57 | log.debug( "loadAccount Call" );
58 | Account newAccount = new Account();
59 |
60 | final X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(Utils.hexToBytes(publicKey));
61 | final PublicKey pubKey = new EdDSAPublicKey(pubKeySpec);
62 |
63 | final PKCS8EncodedKeySpec encoded = new PKCS8EncodedKeySpec(Utils.hexToBytes(privateKey));
64 | final PrivateKey privKey = new EdDSAPrivateKey(encoded);
65 |
66 | KeyPair keyPair = new KeyPair(pubKey, privKey);
67 | newAccount.setPrivateKey(keyPair.getPrivate());
68 | newAccount.setPublicKey(keyPair.getPublic());
69 | log.debug( "loadAccount Call : " + newAccount.getPublicKey().toString() );
70 | return newAccount;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/api/AssetsApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.api;
7 |
8 | import com.bigchaindb.constants.BigchainDbApi;
9 | import com.bigchaindb.model.Assets;
10 | import com.bigchaindb.model.BigChainDBGlobals;
11 | import com.bigchaindb.util.JsonUtils;
12 | import com.bigchaindb.util.NetworkUtils;
13 |
14 | import okhttp3.Response;
15 | import org.slf4j.LoggerFactory;
16 |
17 | import java.io.IOException;
18 |
19 | /**
20 | * The Class AssetsApi.
21 | */
22 | public class AssetsApi {
23 |
24 | private static final org.slf4j.Logger log = LoggerFactory.getLogger( AssetsApi.class );
25 | /**
26 | * Gets the assets.
27 | *
28 | * @param searchKey the search key
29 | * @return the assets
30 | * @throws IOException Signals that an I/O exception has occurred.
31 | */
32 | public static Assets getAssets(String searchKey) throws IOException {
33 | log.debug( "getAssets Call :" + searchKey );
34 | Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.ASSETS + "/?search="+ searchKey);
35 | String body = response.body().string();
36 | response.close();
37 | return JsonUtils.fromJson(body, Assets.class);
38 | }
39 |
40 | /**
41 | * Gets the assets with limit.
42 | *
43 | * @param searchKey the search key
44 | * @param limit the limit
45 | * @return the assets with limit
46 | * @throws IOException Signals that an I/O exception has occurred.
47 | */
48 | public static Assets getAssetsWithLimit(String searchKey, String limit) throws IOException {
49 | log.debug( "getAssetsWithLimit Call :" + searchKey + " limit " + limit );
50 | Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.ASSETS + "/?search="+ searchKey+ "&limit=" + limit);
51 | String body = response.body().string();
52 | response.close();
53 | return JsonUtils.fromJson(body, Assets.class);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/api/BlocksApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.api;
7 |
8 | import com.bigchaindb.constants.BigchainDbApi;
9 | import com.bigchaindb.model.BigChainDBGlobals;
10 | import com.bigchaindb.model.Block;
11 | import com.bigchaindb.util.JsonUtils;
12 | import com.bigchaindb.util.NetworkUtils;
13 | import com.google.gson.reflect.TypeToken;
14 | import okhttp3.Response;
15 | import org.slf4j.LoggerFactory;
16 |
17 | import java.io.IOException;
18 | import java.util.List;
19 |
20 |
21 | /**
22 | * The Class BlocksApi.
23 | */
24 | public class BlocksApi {
25 |
26 | private static final org.slf4j.Logger log = LoggerFactory.getLogger(BlocksApi.class);
27 |
28 | /**
29 | * Gets the block.
30 | *
31 | * @param blockId the block id
32 | * @return the block
33 | * @throws IOException Signals that an I/O exception has occurred.
34 | */
35 | public static Block getBlock(String blockId) throws IOException {
36 | log.debug("getBlock Call :" + blockId);
37 | Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.BLOCKS + "/" + blockId);
38 | String body = response.body().string();
39 | response.close();
40 | return JsonUtils.fromJson(body, Block.class);
41 | }
42 |
43 | /**
44 | * Gets a list of block ids that contain the transaction
45 | *
46 | * @param transactionId the transaction id
47 | * @return the block ids
48 | * @throws IOException Signals that an I/O exception has occurred.
49 | */
50 | public static List getBlocksByTransactionId(String transactionId) throws IOException {
51 | log.debug("getBlocks Call :" + transactionId);
52 | Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.BLOCKS + "?transaction_id=" + transactionId);
53 | String body = response.body().string();
54 | response.close();
55 | return JsonUtils.getGson().fromJson(body, new TypeToken>() {
56 | }.getType());
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/api/MetaDataApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.api;
7 |
8 | import com.bigchaindb.constants.BigchainDbApi;
9 | import com.bigchaindb.model.BigChainDBGlobals;
10 | import com.bigchaindb.model.MetaDatas;
11 | import com.bigchaindb.util.JsonUtils;
12 | import com.bigchaindb.util.NetworkUtils;
13 |
14 | import okhttp3.Response;
15 | import org.slf4j.LoggerFactory;
16 |
17 | import java.io.IOException;
18 |
19 | /**
20 | * The Class MetaDataApi.
21 | */
22 | public class MetaDataApi {
23 |
24 | private static final org.slf4j.Logger log = LoggerFactory.getLogger( MetaDataApi.class );
25 | /**
26 | * Gets the metadata.
27 | *
28 | * @param searchKey the search key
29 | * @return the metadata
30 | * @throws IOException Signals that an I/O exception has occurred.
31 | */
32 | public static MetaDatas getMetaData(String searchKey) throws IOException {
33 | log.debug( "getMetaData Call :" + searchKey );
34 | Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.METADATA + "/?search="+ searchKey);
35 | String body = response.body().string();
36 | response.close();
37 | return JsonUtils.fromJson(body, MetaDatas.class);
38 | }
39 |
40 | /**
41 | * Gets the metadata with limit.
42 | *
43 | * @param searchKey the search key
44 | * @param limit the limit
45 | * @return the metadata with limit
46 | * @throws IOException Signals that an I/O exception has occurred.
47 | */
48 | public static MetaDatas getMetaDataWithLimit(String searchKey, String limit) throws IOException {
49 | log.debug( "getMetaDataWithLimit Call :" + searchKey + " limit " + limit );
50 | Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.METADATA + "/?search="+ searchKey+ "&limit=" + limit);
51 | String body = response.body().string();
52 | response.close();
53 | return JsonUtils.fromJson(body, MetaDatas.class);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/api/OutputsApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.api;
7 |
8 | import com.bigchaindb.constants.BigchainDbApi;
9 | import com.bigchaindb.model.BigChainDBGlobals;
10 | import com.bigchaindb.model.Outputs;
11 | import com.bigchaindb.util.JsonUtils;
12 | import com.bigchaindb.util.NetworkUtils;
13 |
14 | import okhttp3.Response;
15 | import org.slf4j.LoggerFactory;
16 |
17 | import java.io.IOException;
18 |
19 | /**
20 | * The Class OutputsApi.
21 | */
22 | public class OutputsApi {
23 |
24 | private static final org.slf4j.Logger log = LoggerFactory.getLogger( OutputsApi.class );
25 | /**
26 | * Gets the outputs.
27 | *
28 | * @param publicKey the public key
29 | * @return the outputs
30 | * @throws IOException Signals that an I/O exception has occurred.
31 | */
32 | public static Outputs getOutputs(String publicKey) throws IOException {
33 | log.debug( "getOutputs Call :" + publicKey );
34 | Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.OUTPUTS + "?public_key="+ publicKey);
35 | String body = response.body().string();
36 | response.close();
37 | return JsonUtils.fromJson(body, Outputs.class);
38 | }
39 |
40 | /**
41 | * Gets the spent outputs.
42 | *
43 | * @param publicKey the public key
44 | * @return the spent outputs
45 | * @throws IOException Signals that an I/O exception has occurred.
46 | */
47 | public static Outputs getSpentOutputs(String publicKey) throws IOException {
48 | log.debug( "getSpentOutputs Call :" + publicKey );
49 | Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.OUTPUTS + "?public_key="+ publicKey+ "&spent=true");
50 | String body = response.body().string();
51 | response.close();
52 | return JsonUtils.fromJson(body, Outputs.class);
53 | }
54 |
55 | /**
56 | * Gets the unspent outputs.
57 | *
58 | * @param publicKey the public key
59 | * @return the unspent outputs
60 | * @throws IOException Signals that an I/O exception has occurred.
61 | */
62 | public static Outputs getUnspentOutputs(String publicKey) throws IOException {
63 | log.debug( "getUnspentOutputs Call :" + publicKey );
64 | Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.OUTPUTS + "?public_key="+ publicKey+ "&spent=false");
65 | String body = response.body().string();
66 | response.close();
67 | return JsonUtils.fromJson(body, Outputs.class);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/api/TransactionsApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.api;
7 |
8 | import com.bigchaindb.constants.BigchainDbApi;
9 | import com.bigchaindb.constants.Operations;
10 | import com.bigchaindb.exceptions.TransactionNotFoundException;
11 | import com.bigchaindb.model.BigChainDBGlobals;
12 | import com.bigchaindb.model.GenericCallback;
13 | import com.bigchaindb.model.Transaction;
14 | import com.bigchaindb.model.Transactions;
15 | import com.bigchaindb.util.JsonUtils;
16 | import com.bigchaindb.util.NetworkUtils;
17 |
18 | import okhttp3.RequestBody;
19 | import okhttp3.Response;
20 | import org.apache.http.HttpStatus;
21 | import org.slf4j.Logger;
22 | import org.slf4j.LoggerFactory;
23 |
24 | import java.io.IOException;
25 |
26 | /**
27 | * The Class TransactionsApi.
28 | */
29 | public class TransactionsApi extends AbstractApi {
30 |
31 | private static final Logger log = LoggerFactory.getLogger( TransactionsApi.class );
32 |
33 | /**
34 | * Send transaction.
35 | *
36 | * @param transaction
37 | * the transaction
38 | * @param callback
39 | * the callback
40 | */
41 | public static void sendTransaction(Transaction transaction, final GenericCallback callback) {
42 | log.debug( "sendTransaction Call :" + transaction );
43 | RequestBody body = RequestBody.create(JSON, transaction.toString());
44 | NetworkUtils.sendPostRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.TRANSACTIONS, body, callback);
45 | }
46 |
47 | /**
48 | * Sends the transaction.
49 | *
50 | * @param transaction
51 | * the transaction
52 | * @throws IOException
53 | * Signals that an I/O exception has occurred.
54 | */
55 | public static void sendTransaction(Transaction transaction) throws IOException {
56 | log.debug( "sendTransaction Call :" + transaction );
57 | RequestBody body = RequestBody.create(JSON, JsonUtils.toJson(transaction));
58 | Response response = NetworkUtils.sendPostRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.TRANSACTIONS, body);
59 | response.close();
60 | }
61 |
62 | /**
63 | * Gets the transaction by id.
64 | *
65 | * @param id
66 | * the id
67 | * @return the transaction by id
68 | * @throws IOException
69 | * Signals that an I/O exception has occurred.
70 | */
71 | public static Transaction getTransactionById(String id)
72 | throws IOException, TransactionNotFoundException {
73 | log.debug( "getTransactionById Call :" + id );
74 | Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.TRANSACTIONS + "/" + id);
75 | if(!response.isSuccessful()){
76 | if(response.code() == HttpStatus.SC_NOT_FOUND)
77 | throw new TransactionNotFoundException("Transaction with id " + id + " not present");
78 | }
79 | String body = response.body().string();
80 | response.close();
81 | return JsonUtils.fromJson(body, Transaction.class);
82 | }
83 |
84 | /**
85 | * Gets the transactions by asset id.
86 | *
87 | * @param assetId
88 | * the asset id
89 | * @param operation
90 | * the operation
91 | * @return the transactions by asset id
92 | * @throws IOException
93 | * Signals that an I/O exception has occurred.
94 | */
95 | public static Transactions getTransactionsByAssetId(String assetId, Operations operation)
96 | throws IOException {
97 | log.debug( "getTransactionsByAssetId Call :" + assetId + " operation " + operation );
98 | Response response = NetworkUtils.sendGetRequest(
99 | BigChainDBGlobals.getBaseUrl() + BigchainDbApi.TRANSACTIONS + "?asset_id=" + assetId + "&operation=" + operation);
100 | String body = response.body().string();
101 | response.close();
102 | return JsonUtils.fromJson(body, Transactions.class);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/api/ValidatorsApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.api;
7 |
8 | import com.bigchaindb.constants.BigchainDbApi;
9 | import com.bigchaindb.model.BigChainDBGlobals;
10 | import com.bigchaindb.model.Validators;
11 | import com.bigchaindb.util.JsonUtils;
12 | import com.bigchaindb.util.NetworkUtils;
13 |
14 | import okhttp3.Response;
15 | import org.slf4j.LoggerFactory;
16 |
17 | import java.io.IOException;
18 |
19 | /**
20 | * The Class ValidatorsApi.
21 | */
22 | public class ValidatorsApi {
23 |
24 | private static final org.slf4j.Logger log = LoggerFactory.getLogger( ValidatorsApi.class );
25 |
26 | /**
27 | * Gets the the local validators set of a given node.
28 | *
29 | * @return the validators
30 | * @throws IOException Signals that an I/O exception has occurred.
31 | */
32 | public static Validators getValidators() throws IOException {
33 | log.debug( "getValidators Call" );
34 | Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.VALIDATORS);
35 | String body = response.body().string();
36 | response.close();
37 | return JsonUtils.fromJson(body, Validators.class);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/constants/BigchainDbApi.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.constants;
7 |
8 |
9 |
10 | /**
11 | * The Enum BigchainDbApi.
12 | */
13 | public enum BigchainDbApi {
14 |
15 | /** The api version. */
16 | // version.
17 | API_VERSION("/v1"),
18 |
19 | /** The streams. */
20 | // Websocket
21 | STREAMS("/streams/valid_transactions"),
22 |
23 | /** The assets. */
24 | // Core models
25 | ASSETS("/assets"),
26 |
27 | /** The metadata. */
28 | METADATA("/metadata"),
29 |
30 | /** The outputs. */
31 | OUTPUTS("/outputs"),
32 |
33 | /** The blocks. */
34 | BLOCKS("/blocks"),
35 |
36 | /** The validators. */
37 | VALIDATORS("/validators"),
38 |
39 | /** The transactions. */
40 | TRANSACTIONS("/transactions");
41 |
42 | /** The value. */
43 | private final String value;
44 |
45 |
46 | /**
47 | * Instantiates a new bigchain db api.
48 | *
49 | * @param value the value
50 | */
51 | BigchainDbApi(final String value) {
52 | this.value = value;
53 | }
54 |
55 | /* (non-Javadoc)
56 | * @see java.lang.Enum#toString()
57 | */
58 | @Override
59 | public String toString() {
60 | return this.value;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/constants/Operations.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.constants;
7 |
8 |
9 |
10 | /**
11 | * The Enum Operations.
12 | */
13 | public enum Operations {
14 |
15 | /** The create. */
16 | CREATE("CREATE"),
17 |
18 | /** The transfer. */
19 | TRANSFER("TRANSFER");
20 |
21 | /** The value. */
22 | private final String value;
23 |
24 | /**
25 | * Instantiates a new operations.
26 | *
27 | * @param value the value
28 | */
29 | Operations(final String value) {
30 | this.value = value;
31 | }
32 |
33 | /* (non-Javadoc)
34 | * @see java.lang.Enum#toString()
35 | */
36 | @Override
37 | public String toString() {
38 | return this.value;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/exceptions/TransactionNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.bigchaindb.exceptions;
2 |
3 | public class TransactionNotFoundException extends Exception {
4 |
5 | public TransactionNotFoundException(String message) {
6 | super(message);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/json/factory/GsonEmptyCheckTypeAdapterFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.json.factory;
7 |
8 | import com.google.gson.Gson;
9 | import com.google.gson.TypeAdapterFactory;
10 | import com.google.gson.TypeAdapter;
11 | import com.google.gson.reflect.TypeToken;
12 | import com.google.gson.JsonElement;
13 | import com.google.gson.JsonObject;
14 | import com.google.gson.stream.JsonReader;
15 | import com.google.gson.stream.JsonWriter;
16 |
17 | import java.io.IOException;
18 | import java.util.Map;
19 |
20 | /**
21 | * Change empty Maps to null
22 | * Source http://chrisjenx.com/gson-empty-json-to-null/
23 | */
24 | public class GsonEmptyCheckTypeAdapterFactory implements TypeAdapterFactory {
25 |
26 | @Override
27 | public TypeAdapter create(final Gson gson, final TypeToken type) {
28 | // We filter out the EmptyCheckTypeAdapter as we need to check this for emptiness!
29 | if (Map.class.isAssignableFrom(type.getRawType())) {
30 | final TypeAdapter delegate = gson.getDelegateAdapter(this, type);
31 | final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
32 | return new EmptyCheckTypeAdapter<>(delegate, elementAdapter).nullSafe();
33 | }
34 | return null;
35 | }
36 |
37 | static public class EmptyCheckTypeAdapter extends TypeAdapter {
38 | private final TypeAdapter delegate;
39 | private final TypeAdapter elementAdapter;
40 |
41 | public EmptyCheckTypeAdapter(final TypeAdapter delegate, final TypeAdapter elementAdapter) {
42 | this.delegate = delegate;
43 | this.elementAdapter = elementAdapter;
44 | }
45 |
46 | @Override
47 | public void write(final JsonWriter out, final T value) throws IOException {
48 | this.delegate.write(out, value);
49 | }
50 |
51 | @Override
52 | public T read(final JsonReader in) throws IOException {
53 | final JsonObject asJsonObject = elementAdapter.read(in).getAsJsonObject();
54 | if (asJsonObject.entrySet().isEmpty()) return null;
55 | return this.delegate.fromJsonTree(asJsonObject);
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/json/strategy/AssetSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.json.strategy;
7 |
8 | import com.bigchaindb.model.Asset;
9 | import com.bigchaindb.util.JsonUtils;
10 | import com.google.gson.*;
11 |
12 | import java.lang.reflect.Type;
13 |
14 | public class AssetSerializer implements JsonSerializer
15 | {
16 | /**
17 | * Serialize an asset object to json object
18 | * Note: given the type of the asset.data it maybe necessary to
19 | * to add a type adapter {@link JsonSerializer} and/or {@link JsonDeserializer} with {@link JsonUtils} and
20 | * {@link com.bigchaindb.util.JsonUtils#addTypeAdapterSerializer}
21 | *
22 | * TODO test user.data with custom serializer
23 | *
24 | * @param src object to serialize
25 | * @param typeOfSrc type of src
26 | * @param context the json context
27 | * @return the json object
28 | */
29 | public JsonElement serialize( Asset src, Type typeOfSrc, JsonSerializationContext context )
30 | {
31 | Gson gson = JsonUtils.getGson();
32 | JsonObject asset = new JsonObject();
33 |
34 | if (src.getData() != null) {
35 | asset.add( "data", gson.toJsonTree( src.getData(), src.getDataClass() ) );
36 | } else {
37 | asset.add("id", gson.toJsonTree( src.getId() ));
38 | }
39 |
40 | return asset;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/json/strategy/AssetsDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.json.strategy;
7 |
8 | import com.bigchaindb.model.Asset;
9 | import com.bigchaindb.model.Assets;
10 | import com.bigchaindb.util.JsonUtils;
11 | import com.google.gson.JsonDeserializationContext;
12 | import com.google.gson.JsonDeserializer;
13 | import com.google.gson.JsonElement;
14 | import com.google.gson.JsonParseException;
15 |
16 | import java.lang.reflect.Type;
17 |
18 | /**
19 | * The Class AssetsDeserializer.
20 | */
21 | public class AssetsDeserializer implements JsonDeserializer {
22 |
23 | /* (non-Javadoc)
24 | * @see com.google.gson.JsonDeserializer#deserialize(com.google.gson.JsonElement, java.lang.reflect.Type, com.google.gson.JsonDeserializationContext)
25 | */
26 | @Override
27 | public Assets deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
28 | throws JsonParseException {
29 |
30 | Assets assets = new Assets();
31 | for( JsonElement jElement: json.getAsJsonArray() ) {
32 | assets.addAsset(JsonUtils.fromJson(jElement.getAsJsonObject().toString(), Asset.class));
33 | }
34 | return assets;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/json/strategy/CustomExclusionStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.json.strategy;
7 |
8 | import com.bigchaindb.annotations.Exclude;
9 | import com.google.gson.ExclusionStrategy;
10 | import com.google.gson.FieldAttributes;
11 |
12 |
13 |
14 | /**
15 | * The Class CustomExclusionStrategy.
16 | */
17 | public class CustomExclusionStrategy implements ExclusionStrategy {
18 |
19 | /* (non-Javadoc)
20 | * @see com.google.gson.ExclusionStrategy#shouldSkipField(com.google.gson.FieldAttributes)
21 | */
22 | public boolean shouldSkipField(FieldAttributes f) {
23 | if(f.getAnnotation(Exclude.class)!=null){
24 | return true;
25 | }
26 | return false;
27 | }
28 |
29 | /* (non-Javadoc)
30 | * @see com.google.gson.ExclusionStrategy#shouldSkipClass(java.lang.Class)
31 | */
32 | public boolean shouldSkipClass(Class clazz) {
33 | return false;
34 | }
35 |
36 | }
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/json/strategy/InputSerializer.java:
--------------------------------------------------------------------------------
1 | package com.bigchaindb.json.strategy;
2 |
3 | import com.bigchaindb.model.Input;
4 | import com.bigchaindb.util.JsonUtils;
5 | import com.google.gson.*;
6 |
7 | import java.lang.reflect.Type;
8 |
9 |
10 | /**
11 | * Serialize an input record.
12 | */
13 | public class InputSerializer implements JsonSerializer
14 | {
15 | /**
16 | * Serialize an input object.
17 | *
18 | * @param src object to serialize
19 | * @param typeOfSrc type of src
20 | * @param context the json context
21 | * @return the json object
22 | */
23 | public JsonElement serialize(Input src, Type typeOfSrc, JsonSerializationContext context )
24 | {
25 | Gson gson = JsonUtils.getGson();
26 | JsonObject asset = new JsonObject();
27 |
28 |
29 | if (src.getFullFillment() != null) {
30 | asset.add( "fulfillment", gson.toJsonTree( src.getFullFillment() ) );
31 | } else {
32 | asset.add( "fulfillment", gson.toJsonTree( src.getFullFillmentDetails() ) );
33 | }
34 | asset.add( "fulfills", gson.toJsonTree( src.getFulFills() ) );
35 | asset.add( "owners_before", gson.toJsonTree( src.getOwnersBefore() ) );
36 |
37 | return asset;
38 | }
39 | }
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/json/strategy/MetaDataDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.json.strategy;
7 |
8 | import com.bigchaindb.model.MetaData;
9 | import com.bigchaindb.model.MetaDatas;
10 | import com.bigchaindb.util.JsonUtils;
11 | import com.google.gson.JsonDeserializationContext;
12 | import com.google.gson.JsonDeserializer;
13 | import com.google.gson.JsonElement;
14 | import com.google.gson.JsonParseException;
15 |
16 | import java.lang.reflect.Type;
17 |
18 | /**
19 | * The Class AssetsDeserializer.
20 | */
21 | public class MetaDataDeserializer implements JsonDeserializer {
22 |
23 | /* (non-Javadoc)
24 | * @see com.google.gson.JsonDeserializer#deserialize(com.google.gson.JsonElement, java.lang.reflect.Type, com.google.gson.JsonDeserializationContext)
25 | */
26 | @Override
27 | public MetaDatas deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
28 | throws JsonParseException {
29 |
30 | MetaDatas metaDatas = new MetaDatas();
31 | for( JsonElement jElement: json.getAsJsonArray() ) {
32 | metaDatas.addMetaData(JsonUtils.fromJson(jElement.getAsJsonObject().toString(), MetaData.class));
33 | }
34 | return metaDatas;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/bigchaindb/json/strategy/MetaDataSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright BigchainDB GmbH and BigchainDB contributors
3 | * SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
4 | * Code is Apache-2.0 and docs are CC-BY-4.0
5 | */
6 | package com.bigchaindb.json.strategy;
7 |
8 | import com.bigchaindb.model.MetaData;
9 | import com.bigchaindb.util.JsonUtils;
10 | import com.google.gson.*;
11 | import com.google.gson.reflect.TypeToken;
12 |
13 | import java.lang.reflect.Type;
14 | import java.util.Map;
15 |
16 | public class MetaDataSerializer implements JsonSerializer
17 | {
18 | /**
19 | *
20 | * @param src object to serialize
21 | * @param typeOfSrc type of src
22 | * @param context the json context
23 | * @return the json object
24 | */
25 | public JsonElement serialize( MetaData src, Type typeOfSrc, JsonSerializationContext context )
26 | {
27 | Gson gson = JsonUtils.getGson();
28 | JsonElement metadata = gson.toJsonTree( src.getMetadata(), new TypeToken