-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transaction can serialize and deserialize according to Segwit (BIP144…
…). This adds TransactionWitnesses to the wallet protobuf, too. Based on code by: NicolasDorier <nicolas.dorier@gmail.com> Oscar Guindzberg <oscar.guindzberg@gmail.com> sstone <sstone@users.noreply.github.com>
- Loading branch information
Andreas Schildbach
committed
Apr 6, 2018
1 parent
7c270c2
commit b9c983e
Showing
13 changed files
with
1,117 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
core/src/main/java/org/bitcoinj/core/TransactionWitness.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* 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; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class TransactionWitness { | ||
public static final TransactionWitness EMPTY = new TransactionWitness(0); | ||
|
||
private final byte[][] pushes; | ||
|
||
public TransactionWitness(int pushCount) { | ||
pushes = new byte[pushCount][]; | ||
} | ||
|
||
public byte[] getPush(int i) { | ||
return pushes[i]; | ||
} | ||
|
||
public int getPushCount() { | ||
return pushes.length; | ||
} | ||
|
||
public void setPush(int i, byte[] value) { | ||
pushes[i] = value; | ||
} | ||
|
||
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { | ||
stream.write(new VarInt(pushes.length).encode()); | ||
for (int i = 0; i < pushes.length; i++) { | ||
byte[] push = pushes[i]; | ||
stream.write(new VarInt(push.length).encode()); | ||
stream.write(push); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
List<String> stringPushes = new ArrayList<>(); | ||
for (int j = 0; j < this.getPushCount(); j++) { | ||
byte[] push = this.getPush(j); | ||
if (push != null) { | ||
stringPushes.add(Utils.HEX.encode(push)); | ||
} else { | ||
stringPushes.add("NULL"); | ||
} | ||
} | ||
return Utils.SPACE_JOINER.join(stringPushes); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
TransactionWitness other = (TransactionWitness) o; | ||
return Arrays.deepEquals(pushes, other.pushes); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.deepHashCode(pushes); | ||
} | ||
} |
Oops, something went wrong.