forked from FISCO-BCOS/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tars client impl (FISCO-BCOS#821)
* Add TarsClient * Update bulid.gradle, add tars-sdk * Update fisco-bcos-tars-sdk package name * Using google code style * Merge origin * Revert changes of xml * ExtraData use string type * Update tars client * Add tars config and impl * Update loadLibrary * Use google java format * Update library path find * Update tars client --------- Co-authored-by: More <More@MSI> Co-authored-by: More <[email protected]>
- Loading branch information
Showing
2 changed files
with
139 additions
and
13 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
73 changes: 73 additions & 0 deletions
73
src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/TarsTransactionProcessor.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,73 @@ | ||
package org.fisco.bcos.sdk.v3.transaction.manager; | ||
|
||
import org.fisco.bcos.sdk.tars.KeyPairInterface; | ||
import org.fisco.bcos.sdk.tars.SWIGTYPE_p_bcos__bytesConstRef; | ||
import org.fisco.bcos.sdk.tars.SWIGTYPE_p_std__shared_ptrT_KeyInterface_t; | ||
import org.fisco.bcos.sdk.tars.SWIGTYPE_p_std__unique_ptrT_bcos__crypto__KeyPairInterface_t; | ||
import org.fisco.bcos.sdk.tars.SWIGTYPE_p_std__vectorT_unsigned_char_t; | ||
import org.fisco.bcos.sdk.tars.Transaction; | ||
import org.fisco.bcos.sdk.tars.bcos; | ||
import org.fisco.bcos.sdk.v3.client.Client; | ||
import org.fisco.bcos.sdk.v3.client.TarsClient; | ||
import org.fisco.bcos.sdk.v3.crypto.keypair.CryptoKeyPair; | ||
import org.fisco.bcos.sdk.v3.model.callback.TransactionCallback; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class TarsTransactionProcessor extends TransactionProcessor { | ||
private TarsClient tarsClient; | ||
private static final Logger logger = LoggerFactory.getLogger(TarsTransactionProcessor.class); | ||
|
||
public TarsTransactionProcessor( | ||
Client client, CryptoKeyPair cryptoKeyPair, String groupId, String chainId) { | ||
super(client, cryptoKeyPair, groupId, chainId); | ||
tarsClient = (TarsClient) client; | ||
} | ||
|
||
@Override | ||
public String sendTransactionAsync( | ||
String to, | ||
byte[] data, | ||
CryptoKeyPair cryptoKeyPair, | ||
int txAttribute, | ||
TransactionCallback callback) { | ||
String extraData = client.getExtraData(); | ||
|
||
String hexPrivateKey = cryptoKeyPair.getHexPrivateKey(); | ||
SWIGTYPE_p_bcos__bytesConstRef hexPrivateKeyRef = bcos.toBytesConstRef(hexPrivateKey); | ||
SWIGTYPE_p_std__vectorT_unsigned_char_t privateKey = bcos.fromHex(hexPrivateKeyRef); | ||
SWIGTYPE_p_bcos__bytesConstRef privateKeyRef = bcos.toBytesConstRef(privateKey); | ||
SWIGTYPE_p_std__shared_ptrT_KeyInterface_t key = | ||
tarsClient | ||
.getTransactionFactory() | ||
.cryptoSuite() | ||
.keyFactory() | ||
.createKey(privateKeyRef); | ||
SWIGTYPE_p_std__unique_ptrT_bcos__crypto__KeyPairInterface_t sharedKeyPair = | ||
tarsClient.getTransactionFactory().cryptoSuite().signatureImpl().createKeyPair(key); | ||
KeyPairInterface keyPair = bcos.pointerToReference(sharedKeyPair); | ||
|
||
SWIGTYPE_p_std__vectorT_unsigned_char_t input = bcos.toBytes(data); | ||
|
||
Transaction transaction = | ||
tarsClient | ||
.getTransactionFactory() | ||
.createTransaction( | ||
0, | ||
to, | ||
input, | ||
tarsClient.getTarsRPCClient().generateNonce(), | ||
500, | ||
client.getChainId(), | ||
client.getGroup(), | ||
0, | ||
keyPair, | ||
""); | ||
transaction.setExtraData(extraData); | ||
transaction.setAttribute(txAttribute); | ||
|
||
tarsClient.sendTransactionAsync(transaction, callback); | ||
|
||
return bcos.toHex(transaction.hash()); | ||
} | ||
} |