Skip to content

Commit

Permalink
Merge pull request #78 from mikeluxue/0.5.0
Browse files Browse the repository at this point in the history
0.5.0
  • Loading branch information
eodiandie authored Apr 18, 2023
2 parents e0e2f69 + e3779e5 commit 8661820
Show file tree
Hide file tree
Showing 13 changed files with 4,766 additions and 7,345 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Functions include:

- Offline address generation

- Offline transaction construct

- Offline transaction signature

- java-tron full node API support
Expand Down
6 changes: 3 additions & 3 deletions trident-java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ dependencies {
<dependency>
<groupId>org.tron.trident</groupId>
<artifactId>abi</artifactId>
<version>0.3.0</version>
<version>0.5.0</version>
<scope>system</scope>
<systemPath>your path</systemPath>
</dependency>
<dependency>
<groupId>org.tron.trident</groupId>
<artifactId>utils</artifactId>
<version>0.3.0</version>
<version>0.5.0</version>
<scope>system</scope>
<systemPath>your path</systemPath>
</dependency>
<dependency>
<groupId>org.tron.trident</groupId>
<artifactId>core</artifactId>
<version>0.3.0</version>
<version>0.5.0</version>
<scope>system</scope>
<systemPath>your path</systemPath>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion trident-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ext {
}

allprojects {
version '0.4.1'
version '0.5.0'
group = 'org.tron.trident'

repositories {
Expand Down
10,086 changes: 3,334 additions & 6,752 deletions trident-java/core/src/main/grpc/org/tron/trident/api/WalletGrpc.java

Large diffs are not rendered by default.

452 changes: 174 additions & 278 deletions trident-java/core/src/main/java/org/tron/trident/api/GrpcAPI.java

Large diffs are not rendered by default.

192 changes: 95 additions & 97 deletions trident-java/core/src/main/java/org/tron/trident/core/ApiWrapper.java

Large diffs are not rendered by default.

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;
}
}


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();
}
}
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;
}
}
Loading

0 comments on commit 8661820

Please sign in to comment.