Java Code Examples for org.fisco.bcos.web3j.crypto.Credentials

The following examples show how to use org.fisco.bcos.web3j.crypto.Credentials. These examples are extracted from open source projects. 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 Project: web3sdk   Source File: Contract.java    License: Apache License 2.0 6 votes vote down vote up
public static <T extends Contract> RemoteCall<T> deployRemoteCall(
        Class<T> type,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit,
        String binary,
        String encodedConstructor,
        BigInteger value) {
    return new RemoteCall<>(
            () ->
                    deploy(
                            type,
                            web3j,
                            credentials,
                            gasPrice,
                            gasLimit,
                            binary,
                            encodedConstructor,
                            value));
}
 
Example 2
Source Project: web3sdk   Source File: Contract.java    License: Apache License 2.0 6 votes vote down vote up
public static <T extends Contract> RemoteCall<T> deployRemoteCall(
        Class<T> type,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit,
        String binary,
        String encodedConstructor) {
    return deployRemoteCall(
            type,
            web3j,
            credentials,
            gasPrice,
            gasLimit,
            binary,
            encodedConstructor,
            BigInteger.ZERO);
}
 
Example 3
Source Project: WeEvent   Source File: FiscoBcosBroker4ProducerTest.java    License: 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 Project: WeBASE-Front   Source File: ConsensusServiceTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConsensus() throws Exception {
    nodeId = "224e6ee23e8a02d371298b9aec828f77cc2711da3a981684896715a3711885a3177b3cf7906bf9d1b84e597fad1e0049511139332c04edfe3daddba5ed60cffa";

    context = new ClassPathXmlApplicationContext("applicationContext.xml");
    PEMManager pem = context.getBean(PEMManager.class);
    ECKeyPair pemKeyPair = pem.getECKeyPair();
    //链管理员私钥加载
    Credentials credentialsPEM = GenCredential.create(pemKeyPair.getPrivateKey().toString(16));

    ConsensusService consensusService = new ConsensusService(web3j, credentialsPEM);
    System.out.println(consensusService.addSealer(nodeId));
    assertNotNull(consensusService.addSealer(nodeId));
    System.out.println(consensusService.addObserver(nodeId));
    assertNotNull(consensusService.addObserver(nodeId));
    System.out.println(consensusService.removeNode(nodeId));
    assertNotNull(consensusService.removeNode(nodeId));
}
 
Example 5
Source Project: web3sdk   Source File: Contract.java    License: Apache License 2.0 6 votes vote down vote up
public static <T extends Contract> RemoteCall<T> deployRemoteCall(
        Class<T> type,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider,
        String binary,
        String encodedConstructor,
        BigInteger value) {
    return new RemoteCall<>(
            () ->
                    deploy(
                            type,
                            web3j,
                            credentials,
                            contractGasProvider,
                            binary,
                            encodedConstructor,
                            value));
}
 
Example 6
Source Project: web3sdk   Source File: TableTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
public static TableTest load(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    return new TableTest(contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 7
Source Project: web3sdk   Source File: NewSolTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
public static NewSolTest load(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    return new NewSolTest(contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 8
Source Project: web3sdk   Source File: TableTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
protected TableTest(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 9
Source Project: web3sdk   Source File: Ok.java    License: Apache License 2.0 5 votes vote down vote up
protected Ok(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 10
Source Project: web3sdk   Source File: OkD.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
protected OkD(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 11
Source Project: web3sdk   Source File: EvidenceVerify.java    License: Apache License 2.0 5 votes vote down vote up
protected EvidenceVerify(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    super(getBinary(), contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 12
Source Project: web3sdk   Source File: OkD.java    License: Apache License 2.0 5 votes vote down vote up
protected OkD(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 13
Source Project: web3sdk   Source File: ChainGovernance.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
protected ChainGovernance(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 14
Source Project: web3sdk   Source File: Permission.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
protected Permission(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    super(getBinary(), contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 15
Source Project: WeBASE-Front   Source File: Evidence.java    License: Apache License 2.0 5 votes vote down vote up
public static RemoteCall<Evidence> deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider, String evi, String info, String id, BigInteger v, byte[] r, byte[] s, String addr, String sender) {
    String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.fisco.bcos.web3j.abi.datatypes.Utf8String(evi), 
            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(info), 
            new org.fisco.bcos.web3j.abi.datatypes.Utf8String(id), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Uint8(v), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(r), 
            new org.fisco.bcos.web3j.abi.datatypes.generated.Bytes32(s), 
            new org.fisco.bcos.web3j.abi.datatypes.Address(addr), 
            new org.fisco.bcos.web3j.abi.datatypes.Address(sender)));
    return deployRemoteCall(Evidence.class, web3j, credentials, contractGasProvider, BINARY, encodedConstructor);
}
 
Example 16
Source Project: WeEvent   Source File: Web3SDKConnector.java    License: Apache License 2.0 5 votes vote down vote up
public static Credentials getCredentials(FiscoConfig fiscoConfig) {
    log.debug("begin init Credentials");

    // read OSSCA account
    String privateKey;
    if (fiscoConfig.getWeb3sdkEncryptType().equals("SM2_TYPE")) {
        log.info("SM2_TYPE");
        try {
            PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
            Resource resource = resolver.getResource("classpath:" + fiscoConfig.getPemKeyPath());

            PEMManager pemManager = new PEMManager();
            pemManager.load(resource.getInputStream());
            ECKeyPair pemKeyPair = pemManager.getECKeyPair();
            privateKey = pemKeyPair.getPrivateKey().toString(16);
        } catch (UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException | InvalidKeySpecException | NoSuchProviderException | CertificateException | IOException e) {
            log.error("Init OSSCA Credentials failed", e);
            return null;
        }
    } else {
        privateKey = fiscoConfig.getAccount();
    }

    Credentials credentials = GenCredential.create(privateKey);
    if (null == credentials) {
        log.error("init Credentials failed");
        return null;
    }

    log.info("init Credentials success");
    return credentials;
}
 
Example 17
Source Project: web3sdk   Source File: Contract.java    License: Apache License 2.0 5 votes vote down vote up
public static TransactionManager getTheTransactionManager(
        Web3j web3j, Credentials credentials) {
    JsonRpc2_0Web3j jsonRpc2_0Web3j = (JsonRpc2_0Web3j) web3j;
    String chainId = "1";
    int groupId = 1;
    String version = "";
    String supportedVersion = "";
    NodeVersion.Version nodeVersion = null;
    try {
        groupId = jsonRpc2_0Web3j.getGroupId();
        nodeVersion = web3j.getNodeVersion().send().getNodeVersion();
        version = nodeVersion.getVersion();
        supportedVersion = nodeVersion.getSupportedVersion();

        if (EnumNodeVersion.BCOS_2_0_0_RC1.getVersion().equals(version)
                || EnumNodeVersion.BCOS_2_0_0_RC1.getVersion().equals(supportedVersion)) {
            version = EnumNodeVersion.BCOS_2_0_0_RC1.getVersion();
            logger.debug("fisco-bcos version:{}", version);
        } else {
            chainId = nodeVersion.getChainID();
            logger.debug(
                    "fisco-bcos version:{}, supported version:{}", version, supportedVersion);
        }
    } catch (Exception e) {
        logger.error("Query fisco-bcos version failed", e);
    }

    TransactionManager transactionManager =
            EnumNodeVersion.BCOS_2_0_0_RC1.getVersion().equals(version)
                    ? new RawTransactionManager(web3j, credentials)
                    : new ExtendedRawTransactionManager(
                            web3j,
                            credentials,
                            BigInteger.valueOf(groupId),
                            new BigInteger(chainId));

    transactionManager.setNodeVersion(nodeVersion);

    return transactionManager;
}
 
Example 18
Source Project: web3sdk   Source File: ContractLifeCyclePrecompiled.java    License: Apache License 2.0 5 votes vote down vote up
protected ContractLifeCyclePrecompiled(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 19
Source Project: web3sdk   Source File: Ok.java    License: Apache License 2.0 5 votes vote down vote up
public static Ok load(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    return new Ok(contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 20
Source Project: web3sdk   Source File: NewSolTest.java    License: Apache License 2.0 5 votes vote down vote up
protected NewSolTest(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 21
Source Project: web3sdk   Source File: NewSolTest.java    License: Apache License 2.0 5 votes vote down vote up
public static NewSolTest load(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    return new NewSolTest(contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 22
Source Project: WeBASE-Front   Source File: CnsServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
    public void testRegCns() throws Exception {
        contractName = "Evidence1";
        version = "1.0";
        address = "0x8acf30e511c885163b8b9d85f34b806c216da6cc";
        abi = "{\"constant\":true,\"inputs\":[{\"name\":\"id\",\"type\":\"bytes32\"}],\"name\":\"get\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"id\",\"type\":\"bytes32\"},{\"name\":\"decription\",\"type\":\"string\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"evidence\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]";
        contractNameAndVersion = "Evidencee:1.0";

        context = new ClassPathXmlApplicationContext("applicationContext.xml");
        PEMManager pem = context.getBean(PEMManager.class);
        ECKeyPair pemKeyPair = pem.getECKeyPair();
        //链管理员私钥加载
        Credentials credentialsPEM = GenCredential.create(pemKeyPair.getPrivateKey().toString(16));

        CnsService cnsService = new CnsService(web3j, credentialsPEM);
//        System.out.println(cnsService.registerCns(contractName, version, address, abi));
//        assertNotNull(cnsService.registerCns(contractName, version, address, abi));

        // 默认获取最新版本
//        String res = cnsService.getAddressByContractNameAndVersion("contractNameAndVersion");
        List<CnsInfo> list = new ArrayList<>();
                list = cnsService.queryCnsByName(contractName);
        System.out.println(contractNameAndVersion);
//        System.out.println(cnsService.getAddressByContractNameAndVersion(contractName));
//        assertNotNull(cnsService.getAddressByContractNameAndVersion(contractName));
//        System.out.println(cnsService.queryCnsByName(contractName).size());
//        System.out.println(cnsService.queryCnsByName(contractName).get(0).getAddress());
//        System.out.println(cnsService.queryCnsByName(contractName).get(1).getAddress());
//        assertTrue(cnsService.queryCnsByName(contractName).size() != 0);

    }
 
Example 23
protected RingSigPrecompiled(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 24
Source Project: web3sdk   Source File: ContractLifeCyclePrecompiled.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
public static ContractLifeCyclePrecompiled load(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    return new ContractLifeCyclePrecompiled(
            contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 25
Source Project: web3sdk   Source File: Permission.java    License: Apache License 2.0 5 votes vote down vote up
public static Permission load(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    return new Permission(contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 26
public static TestGroupSig load(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        ContractGasProvider contractGasProvider) {
    return new TestGroupSig(contractAddress, web3j, credentials, contractGasProvider);
}
 
Example 27
Source Project: web3sdk   Source File: DagTransfer.java    License: Apache License 2.0 5 votes vote down vote up
@Deprecated
protected DagTransfer(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    super(getBinary(), contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 28
Source Project: web3sdk   Source File: ManagedTransactionTester.java    License: Apache License 2.0 5 votes vote down vote up
public TransactionManager getVerifiedTransactionManager(
        Credentials credentials, int attempts, int sleepDuration) {
    RawTransactionManager transactionManager =
            new RawTransactionManager(web3j, credentials, attempts, sleepDuration);
    transactionManager.setTxHashVerifier(txHashVerifier);
    return transactionManager;
}
 
Example 29
@Deprecated
public static TestRingSig load(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    return new TestRingSig(contractAddress, web3j, credentials, gasPrice, gasLimit);
}
 
Example 30
@Deprecated
protected TestGroupSig(
        String contractAddress,
        Web3j web3j,
        Credentials credentials,
        BigInteger gasPrice,
        BigInteger gasLimit) {
    super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
}