Skip to content

Commit a683c30

Browse files
authored
Merge pull request tronprotocol#1072 from tronprotocol/ev_release
Ev release
2 parents 9556ad1 + 49ac4b7 commit a683c30

File tree

6 files changed

+146
-21
lines changed

6 files changed

+146
-21
lines changed

src/main/java/org/tron/core/Wallet.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import org.tron.protos.Protocol.Account;
7070
import org.tron.protos.Protocol.Block;
7171
import org.tron.protos.Protocol.Transaction;
72+
import org.tron.protos.Protocol.TransactionSign;
7273

7374

7475
@Slf4j
@@ -293,6 +294,23 @@ public GrpcAPI.Return broadcastTransaction(Transaction signaturedTransaction) {
293294
}
294295
}
295296

297+
public TransactionCapsule getTransactionSign(TransactionSign transactionSign) {
298+
byte[] privateKey = transactionSign.getPrivateKey().toByteArray();
299+
TransactionCapsule trx = new TransactionCapsule(transactionSign.getTransaction());
300+
trx.sign(privateKey);
301+
return trx;
302+
}
303+
304+
public byte[] pass2Key(byte[] passPhrase){
305+
return Sha256Hash.hash(passPhrase);
306+
}
307+
308+
public byte[] createAdresss(byte[] passPhrase) {
309+
byte[] privateKey = pass2Key(passPhrase);
310+
ECKey ecKey = ECKey.fromPrivate(privateKey);
311+
return ecKey.getAddress();
312+
}
313+
296314
public Block getNowBlock() {
297315
List<BlockCapsule> blockList = dbManager.getBlockStore().getBlockByLatestNum(1);
298316
if (CollectionUtils.isEmpty(blockList)) {

src/main/java/org/tron/core/capsule/TransactionCapsule.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,10 @@ public boolean checkBalance(byte[] address, byte[] to, long amount, long balance
221221
return true;
222222
}
223223

224-
@Deprecated
225224
public void sign(byte[] privateKey) {
226225
ECKey ecKey = ECKey.fromPrivate(privateKey);
227226
ECDSASignature signature = ecKey.sign(getRawHash().getBytes());
228-
ByteString sig = ByteString.copyFrom(signature.toBase64().getBytes());
227+
ByteString sig = ByteString.copyFrom(signature.toByteArray());
229228
this.transaction = this.transaction.toBuilder().addSignature(sig).build();
230229
}
231230

src/main/java/org/tron/core/services/RpcApiService.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@
2626
import org.tron.api.GrpcAPI.BlockList;
2727
import org.tron.api.GrpcAPI.BlockReference;
2828
import org.tron.api.GrpcAPI.BytesMessage;
29+
import org.tron.api.GrpcAPI.EasyTransferMessage;
30+
import org.tron.api.GrpcAPI.EasyTransferResponse;
2931
import org.tron.api.GrpcAPI.EmptyMessage;
3032
import org.tron.api.GrpcAPI.Node;
3133
import org.tron.api.GrpcAPI.NodeList;
3234
import org.tron.api.GrpcAPI.NumberMessage;
3335
import org.tron.api.GrpcAPI.PaginatedMessage;
36+
import org.tron.api.GrpcAPI.Return.response_code;
3437
import org.tron.api.GrpcAPI.TransactionList;
3538
import org.tron.api.GrpcAPI.WitnessList;
3639
import org.tron.api.WalletExtensionGrpc;
3740
import org.tron.api.WalletGrpc.WalletImplBase;
3841
import org.tron.api.WalletSolidityGrpc.WalletSolidityImplBase;
3942
import org.tron.common.application.Service;
43+
import org.tron.common.crypto.ECKey;
4044
import org.tron.common.overlay.discover.node.NodeHandler;
4145
import org.tron.common.overlay.discover.node.NodeManager;
4246
import org.tron.common.utils.ByteArray;
@@ -70,6 +74,7 @@
7074
import org.tron.protos.Protocol.DynamicProperties;
7175
import org.tron.protos.Protocol.Transaction;
7276
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
77+
import org.tron.protos.Protocol.TransactionSign;
7378

7479
@Component
7580
@Slf4j
@@ -372,6 +377,58 @@ private TransactionCapsule createTransactionCapsule(com.google.protobuf.Message
372377
return trx;
373378
}
374379

380+
@Override
381+
public void getTransactionSign(TransactionSign req,
382+
StreamObserver<Transaction> responseObserver) {
383+
TransactionCapsule retur = wallet.getTransactionSign(req);
384+
responseObserver.onNext(retur.getInstance());
385+
responseObserver.onCompleted();
386+
}
387+
388+
@Override
389+
public void createAdresss(BytesMessage req,
390+
StreamObserver<BytesMessage> responseObserver) {
391+
byte[] address = wallet.createAdresss(req.getValue().toByteArray());
392+
BytesMessage.Builder builder = BytesMessage.newBuilder();
393+
builder.setValue(ByteString.copyFrom(address));
394+
responseObserver.onNext(builder.build());
395+
responseObserver.onCompleted();
396+
}
397+
398+
@Override
399+
public void easyTransfer(EasyTransferMessage req,
400+
StreamObserver<EasyTransferResponse> responseObserver) {
401+
byte[] privateKey = wallet.pass2Key(req.getPassPhrase().toByteArray());
402+
ECKey ecKey = ECKey.fromPrivate(privateKey);
403+
byte[] owner = ecKey.getAddress();
404+
TransferContract.Builder builder = TransferContract.newBuilder();
405+
builder.setOwnerAddress(ByteString.copyFrom(owner));
406+
builder.setToAddress(req.getToAddress());
407+
builder.setAmount(req.getAmount());
408+
409+
TransactionCapsule transactionCapsule = null;
410+
GrpcAPI.Return.Builder returnBuilder = GrpcAPI.Return.newBuilder();
411+
EasyTransferResponse.Builder responseBuild = EasyTransferResponse.newBuilder();
412+
try {
413+
transactionCapsule = createTransactionCapsule(builder.build(),
414+
ContractType.TransferContract);
415+
} catch (ContractValidateException e) {
416+
returnBuilder.setResult(false).setCode(response_code.CONTRACT_VALIDATE_ERROR)
417+
.setMessage(ByteString.copyFromUtf8(e.getMessage()));
418+
responseBuild.setResult(returnBuilder.build());
419+
responseObserver.onNext(responseBuild.build());
420+
responseObserver.onCompleted();
421+
return;
422+
}
423+
424+
transactionCapsule.sign(privateKey);
425+
GrpcAPI.Return retur = wallet.broadcastTransaction(transactionCapsule.getInstance());
426+
responseBuild.setTransaction(transactionCapsule.getInstance());
427+
responseBuild.setResult(retur);
428+
responseObserver.onNext(responseBuild.build());
429+
responseObserver.onCompleted();
430+
}
431+
375432
@Override
376433
public void broadcastTransaction(Transaction req,
377434
StreamObserver<GrpcAPI.Return> responseObserver) {

src/main/protos/api/api.proto

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,36 @@ service Wallet {
310310
}
311311
};
312312
}
313+
//Warning: do not invoke this interface provided by others.
314+
rpc GetTransactionSign (TransactionSign) returns (Transaction) {
315+
option (google.api.http) = {
316+
post: "/wallet/gettransactionsign"
317+
body: "*"
318+
additional_bindings {
319+
get: "/wallet/gettransactionsign"
320+
}
321+
};
322+
};
323+
//Warning: do not invoke this interface provided by others.
324+
rpc CreateAdresss (BytesMessage) returns (BytesMessage) {
325+
option (google.api.http) = {
326+
post: "/wallet/createadresss"
327+
body: "*"
328+
additional_bindings {
329+
get: "/wallet/createadresss"
330+
}
331+
};
332+
};
333+
//Warning: do not invoke this interface provided by others.
334+
rpc EasyTransfer (EasyTransferMessage) returns (EasyTransferResponse) {
335+
option (google.api.http) = {
336+
post: "/wallet/easytransfer"
337+
body: "*"
338+
additional_bindings {
339+
get: "/wallet/easytransfer"
340+
}
341+
};
342+
};
313343
};
314344

315345

@@ -523,3 +553,14 @@ message PaginatedMessage {
523553
int64 offset = 1;
524554
int64 limit = 2;
525555
}
556+
557+
message EasyTransferMessage{
558+
bytes passPhrase = 1;
559+
bytes toAddress = 2;
560+
int64 amount = 3;
561+
}
562+
563+
message EasyTransferResponse{
564+
Transaction transaction = 1;
565+
Return result = 2;
566+
}

src/main/protos/core/Tron.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ message Transactions {
194194
repeated Transaction transactions = 1;
195195
}
196196

197+
message TransactionSign {
198+
Transaction transaction = 1;
199+
bytes privateKey = 2;
200+
}
201+
197202
message BlockHeader {
198203
message raw {
199204
int64 timestamp = 1;

src/main/resources/config-localtest.conf

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ node {
109109
# The maximum size of header list allowed to be received, default 8192
110110
# maxHeaderListSize =
111111
}
112+
}
112113

113114
seed.node = {
114115
# List of the seed nodes
@@ -120,8 +121,8 @@ seed.node = {
120121
# ]
121122
ip.list = [
122123
"127.0.0.1:7777",
123-
"127.0.0.1:8888",
124-
"127.0.0.1:9999",
124+
# "127.0.0.1:8888",
125+
# "127.0.0.1:9999",
125126
]
126127
}
127128

@@ -166,32 +167,36 @@ genesis.block = {
166167
voteCount = 105
167168
#priKey = f5583fd20e13073900a513f333ed13db8c9e83e7e3cf37e74adacef96c5afeaa 7777
168169
},
169-
{
170-
address: TEZBh76rouEQpB2zqYVopbRXGx7RfyWorT
171-
#address: 27TfVERREG3FeWMHEAQ95tWHG4sb3ANn3Qe
172-
url = "http://Venus.org",
173-
voteCount = 104
174-
#priKey = 9f5c5e48bf87cf92017313082e8cf0f58ccfce423097f0fcebf801695fc99bd4 8888
175-
},
176-
{
177-
address: TN27wbfCLEN1gP2PZAxHgU3QZrntsLyxdj
178-
#address: 27b8RUuyZnNPFNZGct2bZkNu9MnGWNAdH3Z
179-
url = "http://Earth.org",
180-
voteCount = 103
181-
#priKey = 6781f44d9a2083b14fad1702b8e9ba82749162b795e2fc3f136192fc63f80de2 9999
182-
},
170+
# {
171+
# address: TEZBh76rouEQpB2zqYVopbRXGx7RfyWorT
172+
# #address: 27TfVERREG3FeWMHEAQ95tWHG4sb3ANn3Qe
173+
# url = "http://Venus.org",
174+
# voteCount = 104
175+
# #priKey = 9f5c5e48bf87cf92017313082e8cf0f58ccfce423097f0fcebf801695fc99bd4 8888
176+
# },
177+
# {
178+
# address: TN27wbfCLEN1gP2PZAxHgU3QZrntsLyxdj
179+
# #address: 27b8RUuyZnNPFNZGct2bZkNu9MnGWNAdH3Z
180+
# url = "http://Earth.org",
181+
# voteCount = 103
182+
# #priKey = 6781f44d9a2083b14fad1702b8e9ba82749162b795e2fc3f136192fc63f80de2 9999
183+
# },
183184
]
184185

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

187188
parentHash = "0x0000000000000000000000000000000000000000000000000000000000000000"
188189
}
189190

190-
localwitnesskeystore = [
191-
"src/main/resources/localwitnesskeystore.json"
191+
localwitness = [
192+
f5583fd20e13073900a513f333ed13db8c9e83e7e3cf37e74adacef96c5afeaa
192193
]
193194

195+
#localwitnesskeystore = [
196+
# "src/main/resources/localwitnesskeystore.json"
197+
#]
198+
194199
block = {
195-
needSyncCheck = true # first node : false, other : true
200+
needSyncCheck = false # first node : false, other : true
196201
maintenanceTimeInterval = 21600000 // 1 day: 86400000(ms), 6 hours: 21600000(ms)
197202
}

0 commit comments

Comments
 (0)