use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class GMOkTransaction method main.
public static void main(String[] args) throws Exception {
EncryptType encryptType = new EncryptType(1);
String groupId = "1";
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Service service = context.getBean(Service.class);
service.run();
System.out.println("===================================================================");
ChannelEthereumService channelEthereumService = new ChannelEthereumService();
channelEthereumService.setChannelService(service);
channelEthereumService.setTimeout(10000);
Web3j web3 = Web3j.build(channelEthereumService, Integer.parseInt(groupId));
BigInteger gasPrice = new BigInteger("300000000");
BigInteger gasLimit = new BigInteger("3000000000");
Credentials credentials1 = GenCredential.create("a392604efc2fad9c0b3da43b5f698a2e3f270f170d859912be0d54742275c5f6");
ContractGasProvider contractGasProvider = new StaticGasProvider(gasPrice, gasLimit);
final Ok okDemo = Ok.deploy(web3, credentials1, contractGasProvider).send();
for (int i = 0; i < 1; i++) {
System.out.println("####contract address is: " + okDemo.getContractAddress());
TransactionReceipt receipt = okDemo.trans(new BigInteger("4")).send();
System.out.println(" balance = " + okDemo.get().send().intValue());
}
System.exit(0);
}
use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class MixContractClient method main.
public static void main(String[] args) throws Exception {
// init the Service
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Service service = context.getBean(Service.class);
service.setGroupId(Integer.parseInt(args[0]));
// run the daemon service
service.run();
// init the client keys
keyPair = Keys.createEcKeyPair();
credentials = Credentials.create(keyPair);
logger.info("-----> start test !");
logger.info("init AOMP ChannelEthereumService");
ChannelEthereumService channelEthereumService = new ChannelEthereumService();
channelEthereumService.setChannelService(service);
try {
web3j = Web3j.build(channelEthereumService, Integer.parseInt(args[0]));
} catch (Exception e) {
System.out.println("\nPlease provide groupID in the first paramters");
System.exit(0);
}
if (args.length > 1) {
if ("deploy".equals(args[1])) {
deploymixContract();
} else {
String[] params = new String[args.length - 1];
for (int i = 0; i < params.length; i++) params[i] = args[i + 1];
testMixContract(params);
}
} else {
System.out.println("\nPlease choose follow commands:\n deploy, create, insert, select, update or remove");
}
System.exit(0);
}
use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class TestTxDecode method sentTx.
public static TransactionReceipt sentTx() throws Exception {
// init the Service
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Service service = context.getBean(Service.class);
service.run();
ECKeyPair keyPair = Keys.createEcKeyPair();
Credentials credentials = Credentials.create(keyPair);
ChannelEthereumService channelEthereumService = new ChannelEthereumService();
channelEthereumService.setChannelService(service);
service.setGroupId(1);
Web3j web3j = Web3j.build(channelEthereumService, service.getGroupId());
RemoteCall<TableTest> deploy = TableTest.deploy(web3j, credentials, new StaticGasProvider(new BigInteger("30000000"), new BigInteger("30000000")));
TableTest tableTest = deploy.send();
tableTest.create().send();
String name = "fruit";
int item_id = 1;
String item_name = "apple";
RemoteCall<TransactionReceipt> insert = tableTest.insert(name, BigInteger.valueOf(item_id), item_name);
TransactionReceipt txReceipt = insert.send();
return txReceipt;
}
use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class PerformanceDTTest method initialize.
public void initialize(String groupId) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Service service = context.getBean(Service.class);
service.setGroupId(Integer.parseInt(groupId));
service.run();
ChannelEthereumService channelEthereumService = new ChannelEthereumService();
channelEthereumService.setChannelService(service);
Web3AsyncThreadPoolSize.web3AsyncCorePoolSize = 3000;
Web3AsyncThreadPoolSize.web3AsyncPoolSize = 2000;
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(500);
Web3j web3 = Web3j.build(channelEthereumService, 15 * 100, scheduledExecutorService, Integer.parseInt(groupId));
Credentials credentials = GenCredential.create();
dagTransfer = DagTransfer.load(dagTransferAddr, web3, credentials, new StaticGasProvider(new BigInteger("30000000"), new BigInteger("30000000")));
transactionManager = Contract.getTheTransactionManager(web3, credentials);
}
use of org.fisco.bcos.channel.client.Service in project web3sdk by FISCO-BCOS.
the class PerformanceRPC method main.
public static void main(String[] args) throws Exception {
try {
if (args.length < 3) {
Usage();
}
int groupId = Integer.valueOf(args[0]);
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Service service = context.getBean(Service.class);
service.setGroupId(groupId);
service.run();
System.out.println("Start test...");
System.out.println("===================================================================");
ChannelEthereumService channelEthereumService = new ChannelEthereumService();
channelEthereumService.setChannelService(service);
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(500);
Web3j web3j = Web3j.build(channelEthereumService, 15 * 100, scheduledExecutorService, groupId);
Integer count = Integer.parseInt(args[1]);
Integer qps = Integer.parseInt(args[2]);
ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
threadPool.setCorePoolSize(200);
threadPool.setMaxPoolSize(500);
threadPool.setQueueCapacity(count);
threadPool.initialize();
PerformanceRpcCollector collector = new PerformanceRpcCollector();
collector.setTotal(count);
RateLimiter limiter = RateLimiter.create(qps);
Integer area = count / 10;
final Integer total = count;
System.out.println("Start test,total:" + count);
for (Integer i = 0; i < count; ++i) {
threadPool.execute(new Runnable() {
@Override
public void run() {
limiter.acquire();
Response response = new Response();
try {
int random = new SecureRandom().nextInt(50000);
int methodNum = 10;
Long startTime = System.nanoTime();
switch(random % methodNum) {
// 1. call getPendingTxSize
case 0:
response = web3j.getPendingTxSize().send();
break;
// 2. call getBlockNumber
case 1:
response = web3j.getBlockNumber().send();
break;
// 3. call getSyncStatus
case 2:
response = web3j.getSyncStatus().send();
break;
// 5. call getSealerList
case 4:
response = web3j.getSealerList().send();
break;
// 6. call getTotalTransactionCount
case 5:
response = web3j.getTotalTransactionCount().send();
break;
// 7. call getObserverList
case 6:
response = web3j.getObserverList().send();
break;
// 8. call getBlockHashByNumber
case 7:
BigInteger blockNumber = web3j.getBlockNumber().send().getBlockNumber();
DefaultBlockParameter blockParam = DefaultBlockParameter.valueOf(blockNumber);
response = web3j.getBlockHashByNumber(blockParam).send();
break;
// 9. call getSystemConfigByKey
case 8:
response = web3j.getSystemConfigByKey("tx_count_limit").send();
break;
// 10. call getPbftView
case 9:
response = web3j.getPbftView().send();
break;
default:
// default call getPbftView
response = web3j.getPbftView().send();
}
Long cost = System.nanoTime() - startTime;
collector.onMessage(response, cost);
} catch (Exception e) {
logger.error("test rpc interface failed, error info: {}", e.getMessage());
Error error = new Error();
error.setCode(1);
response.setError(error);
collector.onMessage(response, 0L);
}
int current = sended.incrementAndGet();
if (current >= area && ((current % area) == 0)) {
System.out.println("Already sended: " + current + "/" + total + " RPC Requests");
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
Aggregations