Commit 6fa1438f authored by bitcoinj-sv's avatar bitcoinj-sv

Merge remote-tracking branch 'bitcoinj-sv/master' into bsv-0.14.7

# Conflicts:
#	.travis.yml
#	core/pom.xml
#	core/src/main/java/org/bitcoinj/core/AbstractBlockChain.java
#	core/src/main/java/org/bitcoinj/core/Block.java
#	core/src/main/java/org/bitcoinj/core/NetworkParameters.java
#	core/src/main/java/org/bitcoinj/core/Transaction.java
#	core/src/main/java/org/bitcoinj/core/TransactionInput.java
#	core/src/main/java/org/bitcoinj/core/Utils.java
#	core/src/main/java/org/bitcoinj/core/VersionMessage.java
#	core/src/main/java/org/bitcoinj/crypto/TransactionSignature.java
#	core/src/main/java/org/bitcoinj/params/AbstractBitcoinNetParams.java
#	core/src/main/java/org/bitcoinj/params/MainNetParams.java
#	core/src/main/java/org/bitcoinj/pow/AbstractRuleCheckerFactory.java
#	core/src/main/java/org/bitcoinj/pow/factory/DAARuleCheckerFactory.java
#	core/src/main/java/org/bitcoinj/pow/factory/EDARuleCheckerFactory.java
#	core/src/main/java/org/bitcoinj/protocols/channels/IPaymentChannelClient.java
#	core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelClient.java
#	core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelClientConnection.java
#	core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelClientState.java
#	core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelServerState.java
#	core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelV1ClientState.java
#	core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelV1ServerState.java
#	core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelV2ClientState.java
#	core/src/main/java/org/bitcoinj/protocols/channels/PaymentChannelV2ServerState.java
#	core/src/main/java/org/bitcoinj/script/Script.java
#	core/src/main/java/org/bitcoinj/script/ScriptOpCodes.java
#	core/src/main/java/org/bitcoinj/signers/LocalTransactionSigner.java
#	core/src/main/java/org/bitcoinj/utils/MonetaryFormat.java
#	core/src/main/java/org/bitcoinj/wallet/DefaultRiskAnalysis.java
#	core/src/main/java/org/bitcoinj/wallet/SendRequest.java
#	core/src/main/java/org/bitcoinj/wallet/Wallet.java
#	core/src/test/java/org/bitcoinj/core/CoinTest.java
#	core/src/test/java/org/bitcoinj/protocols/channels/ChannelConnectionTest.java
#	core/src/test/java/org/bitcoinj/protocols/channels/PaymentChannelServerTest.java
#	core/src/test/java/org/bitcoinj/protocols/channels/PaymentChannelStateTest.java
#	core/src/test/java/org/bitcoinj/wallet/DefaultRiskAnalysisTest.java
#	core/src/test/java/org/bitcoinj/wallet/WalletTest.java
#	examples/pom.xml
#	pom.xml
#	tools/pom.xml
#	wallettemplate/pom.xml
parents 88f3caea d74bbeb8
# configuration for https://travis-ci.org/bitcoinj/bitcoinj
# configuration for https://travis-ci.org/bitcoincash-wallet/bitcoincashj
sudo: false
dist: precise
dist: trusty
language: java
addons:
hosts:
- host
hostname: host
jdk: oraclejdk8
install: true # remove default
addons:
postgresql: "9.3" # min supported version
cache:
directories:
- $HOME/.m2
services:
- mysql
install: true # disable default because no need to do the mvn install before mvn verify
before_script:
- psql -c "create user bitcoinj with password 'password';" -U postgres
- psql -c 'create database bitcoinj_test owner bitcoinj;' -U postgres
- mysql -e 'CREATE DATABASE bitcoinj_test;'
- mysql -e "grant all PRIVILEGES on bitcoinj_test.* to 'bitcoinj' identified by 'password';"
- mysql -e 'SET GLOBAL max_allowed_packet=20971520;'
script:
- mvn -q clean install -Pno-network
- jdk_switcher use openjdk6
- cd orchid
- mvn -q clean package
- cd ../core
- mvn -q clean package -Pno-network
- mvn verify -Ptravis -Dmaven.javadoc.skip=true
# to run one specific test - in this case only testFirst100kBlocksWithCustomSchema test in PostgresFullPrunedBlockChainIT class
# - mvn clean verify -Ptravis -Dmaven.javadoc.skip=true -Dit.test=PostgresFullPrunedBlockChainIT#testFirst100kBlocksWithCustomSchema -Dtest=nothing -DfailIfNoTests=false
# run only mysql integration tests
# - mvn clean verify -Ptravis -Dmaven.javadoc.skip=true -Dit.test=MySQLFullPrunedBlockChainIT -Dtest=nothing -DfailIfNoTests=false
after_success:
- cd ../core
- cd core
- mvn jacoco:report coveralls:report
notifications:
irc:
channels: "irc.freenode.net#bitcoinj"
skip_join: true
[![Build Status](https://travis-ci.org/bitcoinj/bitcoinj.png?branch=master)](https://travis-ci.org/bitcoinj/bitcoinj) [![Coverage Status](https://coveralls.io/repos/bitcoinj/bitcoinj/badge.png?branch=master)](https://coveralls.io/r/bitcoinj/bitcoinj?branch=master)
[![Build Status](https://travis-ci.org/bitcoinj-sv/bitcoinj-sv.png)](https://travis-ci.org/bitcoinj-sv/bitcoinj-sv) [![Coverage Status](https://coveralls.io/repos/github/bitcoinj-sv/bitcoinj-sv/badge.svg)](https://coveralls.io/github/bitcoinj-sv/bitcoinj-sv)
[![Visit our IRC channel](https://kiwiirc.com/buttons/irc.freenode.net/bitcoinj.png)](https://kiwiirc.com/client/irc.freenode.net/bitcoinj)
### NOTICE
This is a work in progress. It is not ready for release and I don't advise using it yet. It's future is also uncertain at this time.
### Welcome to bitcoinj
### Welcome to bitcoinj-sv
The bitcoinj library is a Java implementation of the Bitcoin protocol, which allows it to maintain a wallet and send/receive transactions without needing a local copy of Bitcoin Core. It comes with full documentation and some example apps showing how to use it.
The bitcoinj-sv library is a Java implementation of the Bitcoin SV protocol. This library is a fork of Mike Hearn's original bitcoinj library aimed at supporting Bitcoin SV.
It allows maintaining a wallet and sending/receiving transactions without needing a full blockchain node.
### Technologies
* Java 6 for the core modules, Java 8 for everything else
* Java 8
* [Maven 3+](http://maven.apache.org) - for building the project
* [Orchid](https://github.com/subgraph/Orchid) - for secure communications over [TOR](https://www.torproject.org)
* [Google Protocol Buffers](https://github.com/google/protobuf) - for use with serialization and hardware communications
### Getting started
To get started, it is best to have the latest JDK and Maven installed. The HEAD of the `master` branch contains the latest development code and various production releases are provided on feature branches.
To get started, it is best to have the latest JDK and Maven installed. The HEAD of the `master` branch contains the latest release and the `dev` branch contains development code.
#### Building from the command line
......@@ -23,12 +25,6 @@ To perform a full build use
```
mvn clean package
```
You can also run
```
mvn site:site
```
to generate a website with useful information like JavaDocs.
The outputs are under the `target` directory.
#### Building from an IDE
......@@ -39,20 +35,10 @@ Alternatively, just import the project using your IDE. [IntelliJ](http://www.jet
These are found in the `examples` module.
#### Forwarding service
This will download the block chain and eventually print a Bitcoin address that it has generated.
If you send coins to that address, it will forward them on to the address you specified.
```
cd examples
mvn exec:java -Dexec.mainClass=org.bitcoinj.examples.ForwardingService -Dexec.args="<insert a bitcoin address here>"
```
Note that this example app *does not use checkpointing*, so the initial chain sync will be pretty slow. You can make an app that starts up and does the initial sync much faster by including a checkpoints file; see the documentation for
more info on this technique.
### Contributing to bitcoinj-sv
### Where next?
Contributions to bitcoinj-sv are welcome and encouraged.
Now you are ready to [follow the tutorial](https://bitcoinj.github.io/getting-started).
* the development branch is `dev`
* Travis-CI is [here](https://travis-ci.org/bitcoinj-sv/bitcoinj-sv)
* Coveralls test coverage report is [here](https://coveralls.io/github/bitcoinj-sv/bitcoinj-sv)
This diff is collapsed.
......@@ -78,7 +78,7 @@ public class NativeSecp256k1 {
* libsecp256k1 Create an ECDSA signature.
*
* @param data Message hash, 32 bytes
* @param key Secret key, 32 bytes
* @param sec Secret key, 32 bytes
* @return sig byte array of signature
*/
public static byte[] sign(byte[] data, byte[] sec) throws AssertFailException {
......@@ -200,7 +200,7 @@ public class NativeSecp256k1 {
* libsecp256k1 PrivKey Tweak-Mul - Tweak privkey by multiplying to it
*
* @param tweak some bytes to tweak with
* @param seckey 32-byte seckey
* @param privkey 32-byte seckey
*/
public static byte[] privKeyTweakMul(byte[] privkey, byte[] tweak) throws AssertFailException {
Preconditions.checkArgument(privkey.length == 32);
......@@ -239,7 +239,7 @@ public class NativeSecp256k1 {
* libsecp256k1 PrivKey Tweak-Add - Tweak privkey by adding to it
*
* @param tweak some bytes to tweak with
* @param seckey 32-byte seckey
* @param privkey 32-byte seckey
*/
public static byte[] privKeyTweakAdd(byte[] privkey, byte[] tweak) throws AssertFailException {
Preconditions.checkArgument(privkey.length == 32);
......
......@@ -4993,6 +4993,25 @@ public final class Protos {
* </pre>
*/
com.google.protobuf.ByteString getTx();
/**
* <code>required uint64 amount = 3;</code>
*
* <pre>
* the amount of the input in the return transaction, in satoshis
* this is required to generate a signature on the return transaction
* </pre>
*/
boolean hasAmount();
/**
* <code>required uint64 amount = 3;</code>
*
* <pre>
* the amount of the input in the return transaction, in satoshis
* this is required to generate a signature on the return transaction
* </pre>
*/
long getAmount();
}
/**
* Protobuf type {@code paymentchannels.ProvideRefund}
......@@ -5060,6 +5079,11 @@ public final class Protos {
tx_ = input.readBytes();
break;
}
case 24: {
bitField0_ |= 0x00000004;
amount_ = input.readUInt64();
break;
}
}
}
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
......@@ -5162,9 +5186,35 @@ public final class Protos {
return tx_;
}
public static final int AMOUNT_FIELD_NUMBER = 3;
private long amount_;
/**
* <code>required uint64 amount = 3;</code>
*
* <pre>
* the amount of the input in the return transaction, in satoshis
* this is required to generate a signature on the return transaction
* </pre>
*/
public boolean hasAmount() {
return ((bitField0_ & 0x00000004) == 0x00000004);
}
/**
* <code>required uint64 amount = 3;</code>
*
* <pre>
* the amount of the input in the return transaction, in satoshis
* this is required to generate a signature on the return transaction
* </pre>
*/
public long getAmount() {
return amount_;
}
private void initFields() {
multisigKey_ = com.google.protobuf.ByteString.EMPTY;
tx_ = com.google.protobuf.ByteString.EMPTY;
amount_ = 0L;
}
private byte memoizedIsInitialized = -1;
public final boolean isInitialized() {
......@@ -5180,6 +5230,10 @@ public final class Protos {
memoizedIsInitialized = 0;
return false;
}
if (!hasAmount()) {
memoizedIsInitialized = 0;
return false;
}
memoizedIsInitialized = 1;
return true;
}
......@@ -5193,6 +5247,9 @@ public final class Protos {
if (((bitField0_ & 0x00000002) == 0x00000002)) {
output.writeBytes(2, tx_);
}
if (((bitField0_ & 0x00000004) == 0x00000004)) {
output.writeUInt64(3, amount_);
}
getUnknownFields().writeTo(output);
}
......@@ -5210,6 +5267,10 @@ public final class Protos {
size += com.google.protobuf.CodedOutputStream
.computeBytesSize(2, tx_);
}
if (((bitField0_ & 0x00000004) == 0x00000004)) {
size += com.google.protobuf.CodedOutputStream
.computeUInt64Size(3, amount_);
}
size += getUnknownFields().getSerializedSize();
memoizedSerializedSize = size;
return size;
......@@ -5335,6 +5396,8 @@ public final class Protos {
bitField0_ = (bitField0_ & ~0x00000001);
tx_ = com.google.protobuf.ByteString.EMPTY;
bitField0_ = (bitField0_ & ~0x00000002);
amount_ = 0L;
bitField0_ = (bitField0_ & ~0x00000004);
return this;
}
......@@ -5371,6 +5434,10 @@ public final class Protos {
to_bitField0_ |= 0x00000002;
}
result.tx_ = tx_;
if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
to_bitField0_ |= 0x00000004;
}
result.amount_ = amount_;
result.bitField0_ = to_bitField0_;
onBuilt();
return result;
......@@ -5393,6 +5460,9 @@ public final class Protos {
if (other.hasTx()) {
setTx(other.getTx());
}
if (other.hasAmount()) {
setAmount(other.getAmount());
}
this.mergeUnknownFields(other.getUnknownFields());
return this;
}
......@@ -5406,6 +5476,10 @@ public final class Protos {
return false;
}
if (!hasAmount()) {
return false;
}
return true;
}
......@@ -5562,6 +5636,58 @@ public final class Protos {
return this;
}
private long amount_ ;
/**
* <code>required uint64 amount = 3;</code>
*
* <pre>
* the amount of the input in the return transaction, in satoshis
* this is required to generate a signature on the return transaction
* </pre>
*/
public boolean hasAmount() {
return ((bitField0_ & 0x00000004) == 0x00000004);
}
/**
* <code>required uint64 amount = 3;</code>
*
* <pre>
* the amount of the input in the return transaction, in satoshis
* this is required to generate a signature on the return transaction
* </pre>
*/
public long getAmount() {
return amount_;
}
/**
* <code>required uint64 amount = 3;</code>
*
* <pre>
* the amount of the input in the return transaction, in satoshis
* this is required to generate a signature on the return transaction
* </pre>
*/
public Builder setAmount(long value) {
bitField0_ |= 0x00000004;
amount_ = value;
onChanged();
return this;
}
/**
* <code>required uint64 amount = 3;</code>
*
* <pre>
* the amount of the input in the return transaction, in satoshis
* this is required to generate a signature on the return transaction
* </pre>
*/
public Builder clearAmount() {
bitField0_ = (bitField0_ & ~0x00000004);
amount_ = 0L;
onChanged();
return this;
}
// @@protoc_insertion_point(builder_scope:paymentchannels.ProvideRefund)
}
......@@ -9622,24 +9748,24 @@ public final class Protos {
"\n\005major\030\001 \002(\005\022\020\n\005minor\030\002 \001(\005:\0010\"r\n\010Initi" +
"ate\022\024\n\014multisig_key\030\001 \002(\014\022!\n\031min_accepte" +
"d_channel_size\030\002 \002(\004\022\030\n\020expire_time_secs" +
"\030\003 \002(\004\022\023\n\013min_payment\030\004 \002(\004\"1\n\rProvideRe" +
"fund\022\024\n\014multisig_key\030\001 \002(\014\022\n\n\002tx\030\002 \002(\014\"!",
"\n\014ReturnRefund\022\021\n\tsignature\030\001 \002(\014\"j\n\017Pro" +
"videContract\022\n\n\002tx\030\001 \002(\014\0227\n\017initial_paym" +
"ent\030\002 \002(\0132\036.paymentchannels.UpdatePaymen" +
"t\022\022\n\nclient_key\030\003 \001(\014\"M\n\rUpdatePayment\022\033" +
"\n\023client_change_value\030\001 \002(\004\022\021\n\tsignature" +
"\030\002 \002(\014\022\014\n\004info\030\003 \001(\014\"\032\n\nPaymentAck\022\014\n\004in" +
"fo\030\001 \001(\014\"\030\n\nSettlement\022\n\n\002tx\030\003 \002(\014\"\251\002\n\005E" +
"rror\0225\n\004code\030\001 \001(\0162 .paymentchannels.Err" +
"or.ErrorCode:\005OTHER\022\023\n\013explanation\030\002 \001(\t" +
"\022\026\n\016expected_value\030\003 \001(\004\"\273\001\n\tErrorCode\022\013",
"\n\007TIMEOUT\020\001\022\020\n\014SYNTAX_ERROR\020\002\022\031\n\025NO_ACCE" +
"PTABLE_VERSION\020\003\022\023\n\017BAD_TRANSACTION\020\004\022\034\n" +
"\030TIME_WINDOW_UNACCEPTABLE\020\005\022\033\n\027CHANNEL_V" +
"ALUE_TOO_LARGE\020\006\022\031\n\025MIN_PAYMENT_TOO_LARG" +
"E\020\007\022\t\n\005OTHER\020\010B$\n\032org.bitcoin.paymentcha" +
"nnelB\006Protos"
"\030\003 \002(\004\022\023\n\013min_payment\030\004 \002(\004\"A\n\rProvideRe" +
"fund\022\024\n\014multisig_key\030\001 \002(\014\022\n\n\002tx\030\002 \002(\014\022\016",
"\n\006amount\030\003 \002(\004\"!\n\014ReturnRefund\022\021\n\tsignat" +
"ure\030\001 \002(\014\"j\n\017ProvideContract\022\n\n\002tx\030\001 \002(\014" +
"\0227\n\017initial_payment\030\002 \002(\0132\036.paymentchann" +
"els.UpdatePayment\022\022\n\nclient_key\030\003 \001(\014\"M\n" +
"\rUpdatePayment\022\033\n\023client_change_value\030\001 " +
"\002(\004\022\021\n\tsignature\030\002 \002(\014\022\014\n\004info\030\003 \001(\014\"\032\n\n" +
"PaymentAck\022\014\n\004info\030\001 \001(\014\"\030\n\nSettlement\022\n" +
"\n\002tx\030\003 \002(\014\"\251\002\n\005Error\0225\n\004code\030\001 \001(\0162 .pay" +
"mentchannels.Error.ErrorCode:\005OTHER\022\023\n\013e" +
"xplanation\030\002 \001(\t\022\026\n\016expected_value\030\003 \001(\004",
"\"\273\001\n\tErrorCode\022\013\n\007TIMEOUT\020\001\022\020\n\014SYNTAX_ER" +
"ROR\020\002\022\031\n\025NO_ACCEPTABLE_VERSION\020\003\022\023\n\017BAD_" +
"TRANSACTION\020\004\022\034\n\030TIME_WINDOW_UNACCEPTABL" +
"E\020\005\022\033\n\027CHANNEL_VALUE_TOO_LARGE\020\006\022\031\n\025MIN_" +
"PAYMENT_TOO_LARGE\020\007\022\t\n\005OTHER\020\010B$\n\032org.bi" +
"tcoin.paymentchannelB\006Protos"
};
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
......@@ -9682,7 +9808,7 @@ public final class Protos {
internal_static_paymentchannels_ProvideRefund_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_paymentchannels_ProvideRefund_descriptor,
new java.lang.String[] { "MultisigKey", "Tx", });
new java.lang.String[] { "MultisigKey", "Tx", "Amount", });
internal_static_paymentchannels_ReturnRefund_descriptor =
getDescriptor().getMessageTypes().get(5);
internal_static_paymentchannels_ReturnRefund_fieldAccessorTable = new
......
/*
* Copyright 2012 Google Inc.
* Copyright 2014 Andreas Schildbach
* Copyright 2018 the bitcoinj-cash developers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -13,6 +14,9 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file has been modified by the bitcoinj-cash developers for the bitcoinj-cash project.
* The original file was from the bitcoinj project (https://github.com/bitcoinj/bitcoinj).
*/
package org.bitcoinj.core;
......@@ -104,10 +108,11 @@ public abstract class AbstractBlockChain {
private final Object chainHeadLock = new Object();
protected final NetworkParameters params;
protected final AbstractRuleCheckerFactory ruleCheckerFactory;
private final CopyOnWriteArrayList<ListenerRegistration<NewBestBlockListener>> newBestBlockListeners;
private final CopyOnWriteArrayList<ListenerRegistration<ReorganizeListener>> reorganizeListeners;
private final CopyOnWriteArrayList<ListenerRegistration<TransactionReceivedInBlockListener>> transactionReceivedListeners;
protected final AbstractRuleCheckerFactory ruleCheckerFactory;
// Holds a block header and, optionally, a list of tx hashes or block's transactions
class OrphanBlock {
final Block block;
......@@ -153,6 +158,7 @@ public abstract class AbstractBlockChain {
log.info("chain head is at height {}:\n{}", chainHead.getHeight(), chainHead.getHeader());
this.params = context.getParams();
this.ruleCheckerFactory = RuleCheckerFactory.create(this.params);
this.newBestBlockListeners = new CopyOnWriteArrayList<ListenerRegistration<NewBestBlockListener>>();
this.reorganizeListeners = new CopyOnWriteArrayList<ListenerRegistration<ReorganizeListener>>();
this.transactionReceivedListeners = new CopyOnWriteArrayList<ListenerRegistration<TransactionReceivedInBlockListener>>();
......
......@@ -2,6 +2,7 @@
* Copyright 2011 Google Inc.
* Copyright 2014 Giannis Dzegoutanis
* Copyright 2015 Andreas Schildbach
* Copyright 2018 the bitcoinj-cash developers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -14,18 +15,20 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file has been modified by the bitcoinj-cash developers for the bitcoinj-cash project.
* The original file was from the bitcoinj project (https://github.com/bitcoinj/bitcoinj).
*/
package org.bitcoinj.core;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.bitcoinj.params.Networks;
import org.bitcoinj.script.Script;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
......@@ -172,7 +175,7 @@ public class Address extends VersionedChecksummedBytes {
/**
* Check if a given address version is valid given the NetworkParameters.
*/
private static boolean isAcceptableVersion(NetworkParameters params, int version) {
public static boolean isAcceptableVersion(NetworkParameters params, int version) {
for (int v : params.getAcceptableAddressCodes()) {
if (version == v) {
return true;
......
/*
* Copyright 2018 bitcoinj-cash developers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bitcoinj.core;
/**
* This is a factory class that creates Address or CashAddress objects from strings.
* It will create an Address object from Base58 strings or a CashAddress object from
* cashaddr format strings.
*/
public class AddressFactory {
public static AddressFactory create() {