Skip to content

Commit

Permalink
Merge pull request #1072 from tronprotocol/ev_release
Browse files Browse the repository at this point in the history
Ev release
  • Loading branch information
pangpangfeng authored Jun 21, 2018
2 parents 9556ad1 + 49ac4b7 commit a683c30
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 21 deletions.
18 changes: 18 additions & 0 deletions src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.tron.protos.Protocol.Account;
import org.tron.protos.Protocol.Block;
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.TransactionSign;


@Slf4j
Expand Down Expand Up @@ -293,6 +294,23 @@ public GrpcAPI.Return broadcastTransaction(Transaction signaturedTransaction) {
}
}

public TransactionCapsule getTransactionSign(TransactionSign transactionSign) {
byte[] privateKey = transactionSign.getPrivateKey().toByteArray();
TransactionCapsule trx = new TransactionCapsule(transactionSign.getTransaction());
trx.sign(privateKey);
return trx;
}

public byte[] pass2Key(byte[] passPhrase){
return Sha256Hash.hash(passPhrase);
}

public byte[] createAdresss(byte[] passPhrase) {
byte[] privateKey = pass2Key(passPhrase);
ECKey ecKey = ECKey.fromPrivate(privateKey);
return ecKey.getAddress();
}

public Block getNowBlock() {
List<BlockCapsule> blockList = dbManager.getBlockStore().getBlockByLatestNum(1);
if (CollectionUtils.isEmpty(blockList)) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/tron/core/capsule/TransactionCapsule.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,10 @@ public boolean checkBalance(byte[] address, byte[] to, long amount, long balance
return true;
}

@Deprecated
public void sign(byte[] privateKey) {
ECKey ecKey = ECKey.fromPrivate(privateKey);
ECDSASignature signature = ecKey.sign(getRawHash().getBytes());
ByteString sig = ByteString.copyFrom(signature.toBase64().getBytes());
ByteString sig = ByteString.copyFrom(signature.toByteArray());
this.transaction = this.transaction.toBuilder().addSignature(sig).build();
}

Expand Down
57 changes: 57 additions & 0 deletions src/main/java/org/tron/core/services/RpcApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@
import org.tron.api.GrpcAPI.BlockList;
import org.tron.api.GrpcAPI.BlockReference;
import org.tron.api.GrpcAPI.BytesMessage;
import org.tron.api.GrpcAPI.EasyTransferMessage;
import org.tron.api.GrpcAPI.EasyTransferResponse;
import org.tron.api.GrpcAPI.EmptyMessage;
import org.tron.api.GrpcAPI.Node;
import org.tron.api.GrpcAPI.NodeList;
import org.tron.api.GrpcAPI.NumberMessage;
import org.tron.api.GrpcAPI.PaginatedMessage;
import org.tron.api.GrpcAPI.Return.response_code;
import org.tron.api.GrpcAPI.TransactionList;
import org.tron.api.GrpcAPI.WitnessList;
import org.tron.api.WalletExtensionGrpc;
import org.tron.api.WalletGrpc.WalletImplBase;
import org.tron.api.WalletSolidityGrpc.WalletSolidityImplBase;
import org.tron.common.application.Service;
import org.tron.common.crypto.ECKey;
import org.tron.common.overlay.discover.node.NodeHandler;
import org.tron.common.overlay.discover.node.NodeManager;
import org.tron.common.utils.ByteArray;
Expand Down Expand Up @@ -70,6 +74,7 @@
import org.tron.protos.Protocol.DynamicProperties;
import org.tron.protos.Protocol.Transaction;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
import org.tron.protos.Protocol.TransactionSign;

@Component
@Slf4j
Expand Down Expand Up @@ -372,6 +377,58 @@ private TransactionCapsule createTransactionCapsule(com.google.protobuf.Message
return trx;
}

@Override
public void getTransactionSign(TransactionSign req,
StreamObserver<Transaction> responseObserver) {
TransactionCapsule retur = wallet.getTransactionSign(req);
responseObserver.onNext(retur.getInstance());
responseObserver.onCompleted();
}

@Override
public void createAdresss(BytesMessage req,
StreamObserver<BytesMessage> responseObserver) {
byte[] address = wallet.createAdresss(req.getValue().toByteArray());
BytesMessage.Builder builder = BytesMessage.newBuilder();
builder.setValue(ByteString.copyFrom(address));
responseObserver.onNext(builder.build());
responseObserver.onCompleted();
}

@Override
public void easyTransfer(EasyTransferMessage req,
StreamObserver<EasyTransferResponse> responseObserver) {
byte[] privateKey = wallet.pass2Key(req.getPassPhrase().toByteArray());
ECKey ecKey = ECKey.fromPrivate(privateKey);
byte[] owner = ecKey.getAddress();
TransferContract.Builder builder = TransferContract.newBuilder();
builder.setOwnerAddress(ByteString.copyFrom(owner));
builder.setToAddress(req.getToAddress());
builder.setAmount(req.getAmount());

TransactionCapsule transactionCapsule = null;
GrpcAPI.Return.Builder returnBuilder = GrpcAPI.Return.newBuilder();
EasyTransferResponse.Builder responseBuild = EasyTransferResponse.newBuilder();
try {
transactionCapsule = createTransactionCapsule(builder.build(),
ContractType.TransferContract);
} catch (ContractValidateException e) {
returnBuilder.setResult(false).setCode(response_code.CONTRACT_VALIDATE_ERROR)
.setMessage(ByteString.copyFromUtf8(e.getMessage()));
responseBuild.setResult(returnBuilder.build());
responseObserver.onNext(responseBuild.build());
responseObserver.onCompleted();
return;
}

transactionCapsule.sign(privateKey);
GrpcAPI.Return retur = wallet.broadcastTransaction(transactionCapsule.getInstance());
responseBuild.setTransaction(transactionCapsule.getInstance());
responseBuild.setResult(retur);
responseObserver.onNext(responseBuild.build());
responseObserver.onCompleted();
}

@Override
public void broadcastTransaction(Transaction req,
StreamObserver<GrpcAPI.Return> responseObserver) {
Expand Down
41 changes: 41 additions & 0 deletions src/main/protos/api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,36 @@ service Wallet {
}
};
}
//Warning: do not invoke this interface provided by others.
rpc GetTransactionSign (TransactionSign) returns (Transaction) {
option (google.api.http) = {
post: "/wallet/gettransactionsign"
body: "*"
additional_bindings {
get: "/wallet/gettransactionsign"
}
};
};
//Warning: do not invoke this interface provided by others.
rpc CreateAdresss (BytesMessage) returns (BytesMessage) {
option (google.api.http) = {
post: "/wallet/createadresss"
body: "*"
additional_bindings {
get: "/wallet/createadresss"
}
};
};
//Warning: do not invoke this interface provided by others.
rpc EasyTransfer (EasyTransferMessage) returns (EasyTransferResponse) {
option (google.api.http) = {
post: "/wallet/easytransfer"
body: "*"
additional_bindings {
get: "/wallet/easytransfer"
}
};
};
};


Expand Down Expand Up @@ -523,3 +553,14 @@ message PaginatedMessage {
int64 offset = 1;
int64 limit = 2;
}

message EasyTransferMessage{
bytes passPhrase = 1;
bytes toAddress = 2;
int64 amount = 3;
}

message EasyTransferResponse{
Transaction transaction = 1;
Return result = 2;
}
5 changes: 5 additions & 0 deletions src/main/protos/core/Tron.proto
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ message Transactions {
repeated Transaction transactions = 1;
}

message TransactionSign {
Transaction transaction = 1;
bytes privateKey = 2;
}

message BlockHeader {
message raw {
int64 timestamp = 1;
Expand Down
43 changes: 24 additions & 19 deletions src/main/resources/config-localtest.conf
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ node {
# The maximum size of header list allowed to be received, default 8192
# maxHeaderListSize =
}
}

seed.node = {
# List of the seed nodes
Expand All @@ -120,8 +121,8 @@ seed.node = {
# ]
ip.list = [
"127.0.0.1:7777",
"127.0.0.1:8888",
"127.0.0.1:9999",
# "127.0.0.1:8888",
# "127.0.0.1:9999",
]
}

Expand Down Expand Up @@ -166,32 +167,36 @@ genesis.block = {
voteCount = 105
#priKey = f5583fd20e13073900a513f333ed13db8c9e83e7e3cf37e74adacef96c5afeaa 7777
},
{
address: TEZBh76rouEQpB2zqYVopbRXGx7RfyWorT
#address: 27TfVERREG3FeWMHEAQ95tWHG4sb3ANn3Qe
url = "http://Venus.org",
voteCount = 104
#priKey = 9f5c5e48bf87cf92017313082e8cf0f58ccfce423097f0fcebf801695fc99bd4 8888
},
{
address: TN27wbfCLEN1gP2PZAxHgU3QZrntsLyxdj
#address: 27b8RUuyZnNPFNZGct2bZkNu9MnGWNAdH3Z
url = "http://Earth.org",
voteCount = 103
#priKey = 6781f44d9a2083b14fad1702b8e9ba82749162b795e2fc3f136192fc63f80de2 9999
},
# {
# address: TEZBh76rouEQpB2zqYVopbRXGx7RfyWorT
# #address: 27TfVERREG3FeWMHEAQ95tWHG4sb3ANn3Qe
# url = "http://Venus.org",
# voteCount = 104
# #priKey = 9f5c5e48bf87cf92017313082e8cf0f58ccfce423097f0fcebf801695fc99bd4 8888
# },
# {
# address: TN27wbfCLEN1gP2PZAxHgU3QZrntsLyxdj
# #address: 27b8RUuyZnNPFNZGct2bZkNu9MnGWNAdH3Z
# url = "http://Earth.org",
# voteCount = 103
# #priKey = 6781f44d9a2083b14fad1702b8e9ba82749162b795e2fc3f136192fc63f80de2 9999
# },
]

timestamp = "0" #2017-8-26 12:00:00

parentHash = "0x0000000000000000000000000000000000000000000000000000000000000000"
}

localwitnesskeystore = [
"src/main/resources/localwitnesskeystore.json"
localwitness = [
f5583fd20e13073900a513f333ed13db8c9e83e7e3cf37e74adacef96c5afeaa
]

#localwitnesskeystore = [
# "src/main/resources/localwitnesskeystore.json"
#]

block = {
needSyncCheck = true # first node : false, other : true
needSyncCheck = false # first node : false, other : true
maintenanceTimeInterval = 21600000 // 1 day: 86400000(ms), 6 hours: 21600000(ms)
}

0 comments on commit a683c30

Please sign in to comment.