use of org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService in project web3sdk by FISCO-BCOS.
the class GMErc20Transaction method main.
public static void main(String[] args) throws Exception {
EncryptType encryptType = new EncryptType(1);
System.out.println(encryptType.getEncryptType());
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("300000000");
Credentials credentials1 = GenCredential.create("a392604efc2fad9c0b3da43b5f698a2e3f270f170d859912be0d54742275c5f6");
ContractGasProvider contractGasProvider = new StaticGasProvider(gasPrice, gasLimit);
NewSolTest erc20 = NewSolTest.deploy(web3, credentials1, contractGasProvider).send();
for (int i = 0; i < 1; i++) {
System.out.println("####contract address is: " + erc20.getContractAddress());
erc20.transfer("0x0f49a17d17f82da2a7d92ecf19268274150eaf5e", new BigInteger("100")).send();
BigInteger oldBalance = erc20.balanceOf("0x0f49a17d17f82da2a7d92ecf19268274150eaf5e").send();
System.out.println("0x0f49a17d17f82da2a7d92ecf19268274150eaf5e balance" + oldBalance.intValue());
}
System.exit(0);
}
use of org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService in project web3sdk by FISCO-BCOS.
the class GMTableTestClient 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 = GenCredential.create(keyPair.getPrivateKey().toString(16));
logger.info("-----> start test !");
logger.info("init AOMP ChannelEthereumService");
ChannelEthereumService channelEthereumService = new ChannelEthereumService();
channelEthereumService.setChannelService(service);
channelEthereumService.setTimeout(5 * 1000);
try {
web3j = Web3j.build(channelEthereumService, Integer.parseInt(args[0]));
} catch (Exception e) {
System.out.println("\nPlease provide groupID in the first parameters");
System.exit(0);
}
if (args.length > 1) {
if ("deploy".equals(args[1])) {
deployTableTest();
} else {
String[] params = new String[args.length - 1];
for (int i = 0; i < params.length; i++) params[i] = args[i + 1];
testTableTest(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.web3j.protocol.channel.ChannelEthereumService in project web3sdk by FISCO-BCOS.
the class PerformanceOkDSync method main.
public static void main(String[] args) throws Exception {
try {
String groupId = args[3];
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
Service service = context.getBean(Service.class);
service.setGroupId(Integer.parseInt(groupId));
service.run();
System.out.println("Start test...");
System.out.println("===================================================================");
ChannelEthereumService channelEthereumService = new ChannelEthereumService();
channelEthereumService.setChannelService(service);
if (args.length > 4) {
Integer threadPoolSize = Integer.parseInt(args[4]);
Async async = new Async(Executors.newFixedThreadPool(threadPoolSize));
System.out.println(" === thread pool size = " + threadPoolSize);
}
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(500);
Web3j web3 = Web3j.build(channelEthereumService, 15 * 100, scheduledExecutorService, Integer.parseInt(groupId));
Credentials credentials = Credentials.create("b83261efa42895c38c6c2364ca878f43e77f3cddbc922bf57d0d48070f79feb6");
BigInteger gasPrice = new BigInteger("30000000");
BigInteger gasLimit = new BigInteger("30000000");
String command = args[0];
Integer count = 0;
Integer qps = 0;
switch(command) {
case "trans":
count = Integer.parseInt(args[1]);
qps = Integer.parseInt(args[2]);
break;
default:
System.out.println("Args: <trans> <Total> <QPS> <GroupID> <ThreadPoolSize>");
}
ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
threadPool.setCorePoolSize(200);
threadPool.setMaxPoolSize(500);
threadPool.setQueueCapacity(count);
threadPool.initialize();
System.out.println("Deploying contract...");
OkD ok = OkD.deploy(web3, credentials, gasPrice, gasLimit).send();
PerformanceCollector collector = new PerformanceCollector();
collector.setTotal(count);
RateLimiter limiter = RateLimiter.create(qps);
Integer area = count / 10;
final Integer total = count;
Random random = new Random(System.currentTimeMillis());
System.out.println("Start test,total:" + count);
for (Integer i = 0; i < count; ++i) {
threadPool.execute(new Runnable() {
@Override
public void run() {
limiter.acquire();
PerformanceOkCallback callback = new PerformanceOkCallback();
callback.setCollector(collector);
try {
TransactionReceipt receipt = ok.trans(String.valueOf(random.nextLong()), new BigInteger("1")).sendAsync().get();
callback.onResponse(receipt);
} catch (Exception e) {
TransactionReceipt receipt = new TransactionReceipt();
receipt.setStatus("-1");
callback.onResponse(receipt);
logger.error("Error sending:", e);
}
int current = sended.incrementAndGet();
if (current >= area && ((current % area) == 0)) {
System.out.println("Already sended: " + current + "/" + total + " transactions");
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
use of org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService in project web3sdk by FISCO-BCOS.
the class TableTestClient 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 = GenCredential.create(keyPair.getPrivateKey().toString(16));
logger.info("-----> start test !");
logger.info("init AOMP ChannelEthereumService");
ChannelEthereumService channelEthereumService = new ChannelEthereumService();
channelEthereumService.setChannelService(service);
channelEthereumService.setTimeout(5 * 1000);
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])) {
deployTableTest();
} else {
String[] params = new String[args.length - 1];
for (int i = 0; i < params.length; i++) params[i] = args[i + 1];
testTableTest(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.web3j.protocol.channel.ChannelEthereumService 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);
}
Aggregations