Skip to content

Commit 64e3b01

Browse files
author
Andrew Lekar
committed
Initial commit
0 parents  commit 64e3b01

File tree

196 files changed

+18674
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+18674
-0
lines changed

.gitignore

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
2+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
3+
4+
# User-specific stuff
5+
.idea/**/workspace.xml
6+
.idea/**/tasks.xml
7+
.idea/**/usage.statistics.xml
8+
.idea/**/dictionaries
9+
.idea/**/shelf
10+
commit.bat
11+
12+
# Generated files
13+
.idea/**/contentModel.xml
14+
15+
# Sensitive or high-churn files
16+
.idea/**/dataSources/
17+
.idea/**/dataSources.ids
18+
.idea/**/dataSources.local.xml
19+
.idea/**/sqlDataSources.xml
20+
.idea/**/dynamic.xml
21+
.idea/**/uiDesigner.xml
22+
.idea/**/dbnavigator.xml
23+
24+
# Gradle
25+
.idea/**/gradle.xml
26+
.idea/**/libraries
27+
.gradle/
28+
build/
29+
30+
# Gradle and Maven with auto-import
31+
# When using Gradle or Maven with auto-import, you should exclude module files,
32+
# since they will be recreated, and may cause churn. Uncomment if using
33+
# auto-import.
34+
.idea/modules.xml
35+
.idea/*.iml
36+
.idea/modules
37+
*.iml
38+
39+
# CMake
40+
cmake-build-*/
41+
42+
# Mongo Explorer plugin
43+
.idea/**/mongoSettings.xml
44+
45+
# File-based project format
46+
*.iws
47+
48+
# IntelliJ
49+
out/
50+
51+
# mpeltonen/sbt-idea plugin
52+
.idea_modules/
53+
54+
# JIRA plugin
55+
atlassian-ide-plugin.xml
56+
57+
# Cursive Clojure plugin
58+
.idea/replstate.xml
59+
60+
# Crashlytics plugin (for Android Studio and IntelliJ)
61+
com_crashlytics_export_strings.xml
62+
crashlytics.properties
63+
crashlytics-build.properties
64+
fabric.properties
65+
66+
# Editor-based Rest Client
67+
.idea/httpRequests
68+
69+
# Android studio 3.1+ serialized cache file
70+
.idea/caches/build_file_checksums.ser
71+
72+
# Application specific
73+
*.spv
74+
*.jrnl
75+
*.sqlite
76+
77+
# Eclipse
78+
.settings
79+
.classpath
80+
.project

.travis.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: java
2+
jdk:
3+
- openjdk8
4+
sudo: false
5+
before_cache:
6+
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
7+
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
8+
cache:
9+
directories:
10+
- $HOME/.gradle/caches/
11+
- $HOME/.gradle/wrapper/
12+
before_install:
13+
- chmod +x gradlew
14+
install:
15+
- ./gradlew assemble
16+
script:
17+
- ./gradlew check
18+

LICENSE

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
MIT License
2+
3+
VeriBlock Blockchain Project
4+
5+
Copyright (c) 2017-2018 VeriBlock, Inc
6+
Copyright (c) 2018-2019 Xenios SEZC
7+
8+
All Rights Reserved.
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
SOFTWARE.

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# VeriBlock Integration Library
2+
## Overview
3+
Altchains adopting Bitcoin security through VeriBlock will use the VeriBlock Integration Point
4+
to record and maintain SPV-level knowledge of VeriBlock (and by extension, Bitcoin). VTB
5+
payloads contained in PoP transactions on the altchain are
6+
provided to the VeriBlock integration point, from which it constructs the SPV view. During
7+
fork resolution over a keystone boundary, the altchain will consult the integration point to
8+
determine the timeliness of publications of its keystone periods to the VeriBlock blockchain.
9+
10+
During normal operation, the integration point maintains a deterministic SPV-level view of
11+
VeriBlock based entirely on the VTB publications it has been provided. It maintains an
12+
association of these VTB payloads with their enclosing altchain block (by block number), so
13+
that altchain reorganizations can undo the state changes the unapplied blocks made to the
14+
integration point’s view of VeriBlock.
15+
16+
During fork resolution, the integration point is temporarily updated with VTB information
17+
contained within the challenging fork to ensure the integration point’s view includes
18+
information stored in both forks. After fork resolution, the altchain sends a command to the
19+
integration point to clear the temporarily-added VTB payloads, which returns the integration
20+
point’s view to one which only reflects VTB payloads in the main chain. In the event that the
21+
challenging fork is selected, the altchain still sends the clear command, and then un-applies
22+
VTB payloads in the previously-main chain back to the forking point, and applies the new
23+
VTB payloads from the new fork.
24+
25+
Appendix B of the document [Proof-of-Proof and VeriBlock Blockchain Protocol Consensus Algorithm and Economic Incentivization](https://mirror1.veriblock.org/Proof-of-Proof_and_VeriBlock_Blockchain_Protocol_Consensus_Algorithm_and_Economic_Incentivization_v1.0.pdf) contains details about the library's API and expected uses.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Gradle
2+
.idea/**/gradle.xml
3+
.idea/**/libraries
4+
.gradle/
5+
build/
6+
7+
# Application specific
8+
*.spv
9+
*.jrnl
10+
tmp/
11+
data/
12+
*.log
13+
webservice.properties
14+
generated/
15+
16+
# Eclipse
17+
.settings
18+
.classpath
19+
.project
20+
bin/
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
id "java"
3+
id "java-library"
4+
}
5+
6+
repositories {
7+
flatDir {
8+
dirs '../libs'
9+
}
10+
}
11+
12+
version = '0.1.2'
13+
14+
dependencies {
15+
testImplementation 'junit:junit:4.12'
16+
17+
compile group: 'io.grpc', name: 'grpc-protobuf', version: '1.23.0'
18+
compile group: 'io.grpc', name: 'grpc-stub', version: '1.23.0'
19+
implementation name: 'integration-grpc-java-1.0'
20+
compile project(':core')
21+
compile project(':reference-lib')
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// VeriBlock Blockchain Project
2+
// Copyright 2017-2018 VeriBlock, Inc
3+
// Copyright 2018-2019 Xenios SEZC
4+
// All rights reserved.
5+
// https://www.veriblock.org
6+
// Distributed under the MIT software license, see the accompanying
7+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
8+
9+
package org.veriblock.protoconverters;
10+
11+
import org.veriblock.sdk.Address;
12+
13+
import integration.api.grpc.VeriBlockMessages;
14+
15+
public final class AddressProtoConverter {
16+
17+
private AddressProtoConverter() {} //never
18+
19+
public static Address fromProto(VeriBlockMessages.Address protoData) {
20+
Address result = new Address(protoData.getAddress());
21+
return result;
22+
}
23+
24+
public static VeriBlockMessages.Address toProto(Address data) {
25+
VeriBlockMessages.Address.Builder result = VeriBlockMessages.Address.newBuilder();
26+
result = result.setAddress(data.toString());
27+
return result.build();
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// VeriBlock Blockchain Project
2+
// Copyright 2017-2018 VeriBlock, Inc
3+
// Copyright 2018-2019 Xenios SEZC
4+
// All rights reserved.
5+
// https://www.veriblock.org
6+
// Distributed under the MIT software license, see the accompanying
7+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
8+
9+
package org.veriblock.protoconverters;
10+
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
import org.veriblock.sdk.AltPublication;
15+
import org.veriblock.sdk.VeriBlockBlock;
16+
import org.veriblock.sdk.VeriBlockMerklePath;
17+
import org.veriblock.sdk.VeriBlockTransaction;
18+
19+
import integration.api.grpc.VeriBlockMessages;
20+
21+
public final class AltPublicationProtoConverter {
22+
23+
private AltPublicationProtoConverter() {} //never
24+
25+
public static AltPublication fromProto(VeriBlockMessages.AltPublication protoData) {
26+
VeriBlockTransaction transaction = VeriBlockTransactionProtoConverter.fromProto(protoData.getTransaction());
27+
VeriBlockMerklePath merklePath = VeriBlockMerklePathProtoConverter.fromProto(protoData.getMerklePath());
28+
VeriBlockBlock containingBlock = VeriBlockBlockProtoConverter.fromProto(protoData.getContainingBlock());
29+
List<VeriBlockBlock> context = VeriBlockBlockProtoConverter.fromProto(protoData.getContextList());
30+
AltPublication result = new AltPublication(transaction, merklePath, containingBlock, context);
31+
return result;
32+
}
33+
34+
public static List<AltPublication> fromProto(List<VeriBlockMessages.AltPublication> protoData) {
35+
List<AltPublication> result = new ArrayList<AltPublication>();
36+
for(VeriBlockMessages.AltPublication output : protoData) {
37+
result.add(fromProto(output));
38+
}
39+
return result;
40+
}
41+
42+
public static VeriBlockMessages.AltPublication toProto(AltPublication data) {
43+
VeriBlockMessages.VeriBlockTransaction transaction = VeriBlockTransactionProtoConverter.toProto(data.getTransaction());
44+
String merklePath = data.getMerklePath().toCompactString();
45+
VeriBlockMessages.VeriBlockBlock containingBlock = VeriBlockBlockProtoConverter.toProto(data.getContainingBlock());
46+
List<VeriBlockMessages.VeriBlockBlock> context = VeriBlockBlockProtoConverter.toProto(data.getContext());
47+
VeriBlockMessages.AltPublication.Builder result = VeriBlockMessages.AltPublication.newBuilder();
48+
result = result.setTransaction(transaction)
49+
.setMerklePath(merklePath)
50+
.setContainingBlock(containingBlock)
51+
.addAllContext(context);
52+
return result.build();
53+
}
54+
55+
public static List<VeriBlockMessages.AltPublication> toProto(List<AltPublication> data) {
56+
List<VeriBlockMessages.AltPublication> result = new ArrayList<>();
57+
for(AltPublication output : data) {
58+
result.add(toProto(output));
59+
}
60+
return result;
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// VeriBlock Blockchain Project
2+
// Copyright 2017-2018 VeriBlock, Inc
3+
// Copyright 2018-2019 Xenios SEZC
4+
// All rights reserved.
5+
// https://www.veriblock.org
6+
// Distributed under the MIT software license, see the accompanying
7+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
8+
9+
package org.veriblock.protoconverters;
10+
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
import org.veriblock.sdk.BitcoinBlock;
15+
import org.veriblock.sdk.Sha256Hash;
16+
17+
import com.google.protobuf.ByteString;
18+
19+
import integration.api.grpc.VeriBlockMessages;
20+
21+
public final class BitcoinBlockProtoConverter {
22+
23+
private BitcoinBlockProtoConverter() {} //never
24+
25+
public static BitcoinBlock fromProto(VeriBlockMessages.BitcoinBlock protoData) {
26+
int version = protoData.getVersion();
27+
Sha256Hash previousBlock = Sha256Hash.wrap(protoData.getPreviousBlock().toByteArray(), protoData.getPreviousBlock().size());
28+
Sha256Hash merkleRoot = Sha256Hash.wrap(protoData.getMerkleRoot().toByteArray(), protoData.getMerkleRoot().size());
29+
int timestamp = protoData.getTimestamp();
30+
int bits = protoData.getBits();
31+
int nonce = protoData.getNonce();
32+
33+
BitcoinBlock result = new BitcoinBlock(version, previousBlock, merkleRoot, timestamp, bits, nonce);
34+
return result;
35+
}
36+
37+
public static List<BitcoinBlock> fromProto(List<VeriBlockMessages.BitcoinBlock> protoData) {
38+
List<BitcoinBlock> result = new ArrayList<BitcoinBlock>();
39+
for(VeriBlockMessages.BitcoinBlock output : protoData) {
40+
result.add(fromProto(output));
41+
}
42+
return result;
43+
}
44+
45+
public static VeriBlockMessages.BitcoinBlock toProto(BitcoinBlock data) {
46+
int version = data.getVersion();
47+
byte[] previousBlock = data.getPreviousBlock().getBytes();
48+
byte[] merkleRoot = data.getMerkleRoot().getBytes();
49+
int timestamp = data.getTimestamp();
50+
int bits = data.getBits();
51+
int nonce = data.getNonce();
52+
53+
VeriBlockMessages.BitcoinBlock.Builder result = VeriBlockMessages.BitcoinBlock.newBuilder();
54+
result = result.setVersion(version)
55+
.setPreviousBlock(ByteString.copyFrom(previousBlock))
56+
.setMerkleRoot(ByteString.copyFrom(merkleRoot))
57+
.setTimestamp(timestamp)
58+
.setBits(bits)
59+
.setNonce(nonce);
60+
return result.build();
61+
}
62+
63+
public static List<VeriBlockMessages.BitcoinBlock> toProto(List<BitcoinBlock> data) {
64+
List<VeriBlockMessages.BitcoinBlock> result = new ArrayList<>();
65+
for(BitcoinBlock output : data) {
66+
result.add(toProto(output));
67+
}
68+
return result;
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// VeriBlock Blockchain Project
2+
// Copyright 2017-2018 VeriBlock, Inc
3+
// Copyright 2018-2019 Xenios SEZC
4+
// All rights reserved.
5+
// https://www.veriblock.org
6+
// Distributed under the MIT software license, see the accompanying
7+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
8+
9+
package org.veriblock.protoconverters;
10+
11+
import org.veriblock.sdk.BitcoinTransaction;
12+
13+
import com.google.protobuf.ByteString;
14+
15+
import integration.api.grpc.VeriBlockMessages;
16+
17+
public final class BitcoinTransactionProtoConverter {
18+
19+
private BitcoinTransactionProtoConverter() {} //never
20+
21+
public static BitcoinTransaction fromProto(VeriBlockMessages.BitcoinTransaction protoData) {
22+
BitcoinTransaction result = new BitcoinTransaction(protoData.getRaw().toByteArray());
23+
return result;
24+
}
25+
26+
public static VeriBlockMessages.BitcoinTransaction toProto(BitcoinTransaction data) {
27+
VeriBlockMessages.BitcoinTransaction.Builder result = VeriBlockMessages.BitcoinTransaction.newBuilder();
28+
result = result.setRaw(ByteString.copyFrom(data.getRawBytes()));
29+
return result.build();
30+
}
31+
}

0 commit comments

Comments
 (0)