-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from mikeluxue/0.5.0
0.5.0
- Loading branch information
Showing
13 changed files
with
4,766 additions
and
7,345 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ ext { | |
} | ||
|
||
allprojects { | ||
version '0.4.1' | ||
version '0.5.0' | ||
group = 'org.tron.trident' | ||
|
||
repositories { | ||
|
10,086 changes: 3,334 additions & 6,752 deletions
10,086
trident-java/core/src/main/grpc/org/tron/trident/api/WalletGrpc.java
Large diffs are not rendered by default.
Oops, something went wrong.
452 changes: 174 additions & 278 deletions
452
trident-java/core/src/main/java/org/tron/trident/api/GrpcAPI.java
Large diffs are not rendered by default.
Oops, something went wrong.
192 changes: 95 additions & 97 deletions
192
trident-java/core/src/main/java/org/tron/trident/core/ApiWrapper.java
Large diffs are not rendered by default.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
trident-java/core/src/main/java/org/tron/trident/core/transaction/BlockId.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,58 @@ | ||
package org.tron.trident.core.transaction; | ||
|
||
import org.tron.trident.core.utils.Sha256Hash; | ||
|
||
import java.util.Arrays; | ||
|
||
public class BlockId extends Sha256Hash { | ||
|
||
private long num; | ||
|
||
/** | ||
* Use {@link #wrap(byte[])} instead. | ||
*/ | ||
public BlockId(Sha256Hash hash, long num) { | ||
super(num, hash); | ||
this.num = num; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || (getClass() != o.getClass() && !(o instanceof Sha256Hash))) { | ||
return false; | ||
} | ||
return Arrays.equals(getBytes(), ((Sha256Hash) o).getBytes()); | ||
} | ||
|
||
public String getString() { | ||
return "Num:" + num + ",ID:" + super.toString(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return super.toString(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return super.hashCode(); | ||
} | ||
|
||
@Override | ||
public int compareTo(Sha256Hash other) { | ||
if (other.getClass().equals(BlockId.class)) { | ||
long otherNum = ((BlockId) other).getNum(); | ||
return Long.compare(num, otherNum); | ||
} | ||
return super.compareTo(other); | ||
} | ||
|
||
public long getNum() { | ||
return num; | ||
} | ||
} | ||
|
||
|
100 changes: 100 additions & 0 deletions
100
trident-java/core/src/main/java/org/tron/trident/core/transaction/TransactionCapsule.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,100 @@ | ||
package org.tron.trident.core.transaction; | ||
|
||
import com.google.protobuf.Any; | ||
import com.google.protobuf.ByteString; | ||
import org.tron.trident.core.utils.ByteArray; | ||
import org.tron.trident.proto.Chain; | ||
|
||
public class TransactionCapsule { | ||
|
||
public TransactionCapsule(com.google.protobuf.Message message, Chain.Transaction.Contract.ContractType contractType) { | ||
Chain.Transaction.raw.Builder transactionBuilder = Chain.Transaction.raw.newBuilder().addContract( | ||
Chain.Transaction.Contract.newBuilder().setType(contractType).setParameter( | ||
(message instanceof Any ? (Any) message : Any.pack(message))).build()); | ||
transaction = Chain.Transaction.newBuilder().setRawData(transactionBuilder.build()).build(); | ||
} | ||
|
||
private Chain.Transaction transaction; | ||
|
||
private boolean isVerified = false; | ||
|
||
private long blockNum = -1; | ||
|
||
|
||
private long time; | ||
|
||
private long order; | ||
|
||
private boolean isTransactionCreate = false; | ||
|
||
public boolean isTransactionCreate() { | ||
return isTransactionCreate; | ||
} | ||
|
||
public void setTransactionCreate(boolean transactionCreate) { | ||
isTransactionCreate = transactionCreate; | ||
} | ||
|
||
|
||
public Chain.Transaction getTransaction() { | ||
return transaction; | ||
} | ||
|
||
public void setTransaction(Chain.Transaction transaction) { | ||
this.transaction = transaction; | ||
} | ||
|
||
public boolean isVerified() { | ||
return isVerified; | ||
} | ||
|
||
public void setVerified(boolean verified) { | ||
isVerified = verified; | ||
} | ||
|
||
public long getBlockNum() { | ||
return blockNum; | ||
} | ||
|
||
public void setBlockNum(long blockNum) { | ||
this.blockNum = blockNum; | ||
} | ||
|
||
public long getTime() { | ||
return time; | ||
} | ||
|
||
public void setTime(long time) { | ||
this.time = time; | ||
} | ||
|
||
public long getOrder() { | ||
return order; | ||
} | ||
|
||
public void setOrder(long order) { | ||
this.order = order; | ||
} | ||
|
||
public void setReference(long blockNum, byte[] blockHash) { | ||
byte[] refBlockNum = ByteArray.fromLong(blockNum); | ||
Chain.Transaction.raw rawData = this.transaction.getRawData().toBuilder() | ||
.setRefBlockHash(ByteString.copyFrom(ByteArray.subArray(blockHash, 8, 16))) | ||
.setRefBlockBytes(ByteString.copyFrom(ByteArray.subArray(refBlockNum, 6, 8))) | ||
.build(); | ||
this.transaction = this.transaction.toBuilder().setRawData(rawData).build(); | ||
} | ||
|
||
public void setExpiration(long expiration) { | ||
Chain.Transaction.raw rawData = this.transaction.getRawData().toBuilder().setExpiration(expiration) | ||
.build(); | ||
this.transaction = this.transaction.toBuilder().setRawData(rawData).build(); | ||
} | ||
|
||
public void setTimestamp() { | ||
Chain.Transaction.raw rawData = this.transaction.getRawData().toBuilder() | ||
.setTimestamp(System.currentTimeMillis()) | ||
.build(); | ||
this.transaction = this.transaction.toBuilder().setRawData(rawData).build(); | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
trident-java/core/src/main/java/org/tron/trident/core/utils/ByteArray.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,128 @@ | ||
package org.tron.trident.core.utils; | ||
|
||
import com.google.common.primitives.Ints; | ||
import com.google.common.primitives.Longs; | ||
import org.bouncycastle.util.encoders.Hex; | ||
|
||
import java.math.BigInteger; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/* | ||
* Copyright (c) [2016] [ <ether.camp> ] | ||
* This file is part of the ethereumJ library. | ||
* | ||
* The ethereumJ library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The ethereumJ library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
public class ByteArray { | ||
|
||
public static String toHexString(byte[] data) { | ||
return data == null ? "" : Hex.toHexString(data); | ||
} | ||
public static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; | ||
/** | ||
* get bytes data from hex string data. | ||
*/ | ||
public static byte[] fromHexString(String data) { | ||
if (data == null) { | ||
return EMPTY_BYTE_ARRAY; | ||
} | ||
if (data.startsWith("0x")) { | ||
data = data.substring(2); | ||
} | ||
if (data.length() % 2 != 0) { | ||
data = "0" + data; | ||
} | ||
return Hex.decode(data); | ||
} | ||
|
||
public static byte[] fromLong(long val) { | ||
return Longs.toByteArray(val); | ||
} | ||
|
||
public static byte[] fromInt(int val) { | ||
return Ints.toByteArray(val); | ||
} | ||
|
||
|
||
/** | ||
* Stringify byte[] x | ||
* null for null | ||
* null for empty [] | ||
*/ | ||
public static String toJsonHex(byte[] x) { | ||
return x == null || x.length == 0 ? "0x" : "0x" + Hex.toHexString(x); | ||
} | ||
|
||
public static String toJsonHex(Long x) { | ||
return x == null ? null : "0x" + Long.toHexString(x); | ||
} | ||
|
||
|
||
public static BigInteger hexToBigInteger(String input) { | ||
if (input.startsWith("0x")) { | ||
return new BigInteger(input.substring(2), 16); | ||
} else { | ||
return new BigInteger(input, 10); | ||
} | ||
} | ||
|
||
|
||
|
||
public static int jsonHexToInt(String x) throws Exception { | ||
if (!x.startsWith("0x")) { | ||
throw new Exception("Incorrect hex syntax"); | ||
} | ||
x = x.substring(2); | ||
return Integer.parseInt(x, 16); | ||
} | ||
|
||
/** | ||
* Generate a subarray of a given byte array. | ||
* | ||
* @param input the input byte array | ||
* @param start the start index | ||
* @param end the end index | ||
* @return a subarray of <tt>input</tt>, ranging from <tt>start</tt> (inclusively) to <tt>end</tt> | ||
* (exclusively) | ||
*/ | ||
public static byte[] subArray(byte[] input, int start, int end) { | ||
byte[] result = new byte[end - start]; | ||
System.arraycopy(input, start, result, 0, end - start); | ||
return result; | ||
} | ||
|
||
public static boolean isEmpty(byte[] input) { | ||
return input == null || input.length == 0; | ||
} | ||
|
||
public static boolean matrixContains(List<byte[]> source, byte[] obj) { | ||
for (byte[] sobj : source) { | ||
if (Arrays.equals(sobj, obj)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static String fromHex(String x) { | ||
if (x.startsWith("0x")) { | ||
x = x.substring(2); | ||
} | ||
if (x.length() % 2 != 0) { | ||
x = "0" + x; | ||
} | ||
return x; | ||
} | ||
} |
Oops, something went wrong.