org.fisco.bcos.web3j.crypto.ExtendedRawTransaction Java Examples

The following examples show how to use org.fisco.bcos.web3j.crypto.ExtendedRawTransaction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FiscoBcosBroker4ProducerTest.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
/**
 * publish an externally signed event by fixed account.
 */
@Test
public void testPublishByFixedAccount() throws Exception {
    Map<String, String> ext = new HashMap<>();
    ext.put(WeEvent.WeEvent_SIGN, "true");
    WeEvent event = new WeEvent(this.topicName, "this is a signed message".getBytes(), ext);
    ContractContext contractContext = this.fiscoBcosDelegate.getContractContext(Long.parseLong(this.groupId));

    String rawData = buildWeEvent(event);
    ExtendedRawTransaction rawTransaction = getRawTransaction(this.groupId, rawData, contractContext);


    String signData = signData(rawTransaction, Web3SDKConnector.getCredentials(this.fiscoConfig));
    SendResult sendResult = this.iProducer.publish(new WeEvent(this.topicName, signData.getBytes(), ext), this.groupId).get(transactionTimeout, TimeUnit.MILLISECONDS);

    Assert.assertEquals(sendResult.getStatus(), SendResult.SendResultStatus.SUCCESS);
}
 
Example #2
Source File: FiscoBcosBroker4ProducerTest.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
/**
 * publish an externally signed event by external account.
 */
@Test
public void testPublishByExternalAccount() throws Exception {
    Credentials externallyCredentials = getExternalAccountCredentials();
    String operatorAddress = externallyCredentials.getAddress();

    // add operatorAddress for topic
    boolean result = this.iProducer.addOperator(this.groupId, this.topicName, operatorAddress);
    Assert.assertTrue(result);

    // publish event with the above generated externally account
    Map<String, String> ext = new HashMap<>();
    ext.put(WeEvent.WeEvent_SIGN, "true");
    WeEvent event = new WeEvent(this.topicName, "this is a signed message".getBytes(), ext);

    String rawData = buildWeEvent(event);
    ExtendedRawTransaction rawTransaction = getRawTransaction(this.groupId, rawData, this.contractContext);

    String signData = signData(rawTransaction, externallyCredentials);

    SendResult sendResult = this.iProducer.publish(new WeEvent(this.topicName, signData.getBytes(), ext), this.groupId).get(transactionTimeout, TimeUnit.MILLISECONDS);

    Assert.assertEquals(sendResult.getStatus(), SendResult.SendResultStatus.SUCCESS);
}
 
Example #3
Source File: FiscoBcosBroker4ProducerTest.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
/**
 * publish an externally signed event by external account.
 */
@Test
public void testPublishByExternalAccountNoPermission() throws Exception {
    Map<String, String> ext = new HashMap<>();
    ext.put(WeEvent.WeEvent_SIGN, "true");
    WeEvent event = new WeEvent(this.topicName, "this is a signed message".getBytes(), ext);

    String rawData = buildWeEvent(event);
    ExtendedRawTransaction rawTransaction = getRawTransaction(this.groupId, rawData, this.contractContext);

    Credentials credentials = getExternalAccountCredentials();

    String signData = signData(rawTransaction, credentials);
    SendResult sendResult = this.iProducer.publish(new WeEvent(this.topicName, signData.getBytes(), ext), this.groupId).get(transactionTimeout, TimeUnit.MILLISECONDS);

    Assert.assertEquals(sendResult.getStatus(), SendResult.SendResultStatus.NO_PERMISSION);
}
 
Example #4
Source File: FiscoBcosBroker4ProducerTest.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
private ExtendedRawTransaction getRawTransaction(String groupId, String data, ContractContext contractContext) {
    Random r = new SecureRandom();
    BigInteger randomid = new BigInteger(250, r);
    ExtendedRawTransaction rawTransaction =
            ExtendedRawTransaction.createTransaction(
                    randomid,
                    BigInteger.valueOf(contractContext.getGasPrice()),
                    BigInteger.valueOf(contractContext.getGasLimit()),
                    BigInteger.valueOf(contractContext.getBlockLimit()),
                    contractContext.getTopicAddress(),
                    BigInteger.ZERO,
                    data,
                    new BigInteger(contractContext.getChainId()),
                    new BigInteger(groupId),
                    null);
    return rawTransaction;
}
 
Example #5
Source File: TransactionManager.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public ExtendedRawTransaction createTransaction(
        BigInteger gasPrice,
        BigInteger gasLimit,
        String to,
        String data,
        BigInteger value,
        String extraData)
        throws IOException {
    return null;
}
 
Example #6
Source File: ManagedTransaction.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
protected String createSeq(
        String to, String data, BigInteger value, BigInteger gasPrice, BigInteger gasLimit)
        throws IOException {
    ExtendedRawTransaction rawTransaction =
            transactionManager.createTransaction(gasPrice, gasLimit, to, data, value, null);
    return transactionManager.sign(rawTransaction);
}
 
Example #7
Source File: FiscoBcosBroker4ProducerTest.java    From WeEvent with Apache License 2.0 4 votes vote down vote up
private String signData(ExtendedRawTransaction rawTransaction, Credentials credentials) {
    byte[] signedMessage = ExtendedTransactionEncoder.signMessage(rawTransaction, credentials);
    return Numeric.toHexString(signedMessage);
}
 
Example #8
Source File: TransactionManager.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
public String sign(ExtendedRawTransaction transaction) {
    return null;
}