Search in sources :

Example 16 with Utf8String

use of org.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.

the class SystemProxyTools method processSystemProxy.

static void processSystemProxy(SystemProxy systemProxy, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
    try {
        System.out.println("-----------------系统路由表----------------------");
        Uint256 routelength = systemProxy.getRouteSize().get();
        for (int i = 0; i < routelength.getValue().intValue(); i++) {
            Utf8String key = systemProxy.getRouteNameByIndex(new Uint256(i)).get();
            List<Type> route = systemProxy.getRoute(key).get();
            System.out.println(" " + i + ")" + key + "=>" + (route.get(0)) + "," + route.get(1).getValue() + "," + ((BigInteger) (route.get(2).getValue())).intValue());
            if (key.getValue().equals("TransactionFilterChain")) {
                TransactionFilterChain transactionFilterChain1 = TransactionFilterChain.load(route.get(0).toString(), web3j, credentials, gasPrice, gasLimit);
                Uint256 filterlength = transactionFilterChain1.getFiltersLength().get();
                for (int j = 0; j < filterlength.getValue().intValue(); j++) {
                    Address filter = transactionFilterChain1.getFilter(new Uint256(j)).get();
                    TransactionFilterBase transactionFilterBase = TransactionFilterBase.load(filter.toString(), web3j, credentials, gasPrice, gasLimit);
                    Utf8String name = transactionFilterBase._name().get();
                    Utf8String version = transactionFilterBase._version().get();
                    System.out.println("       " + name + "=>" + version + "," + filter);
                }
            }
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}
Also used : Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) Type(org.bcos.web3j.abi.datatypes.Type) Address(org.bcos.web3j.abi.datatypes.Address) TransactionFilterChain(org.bcos.contract.source.TransactionFilterChain) BigInteger(java.math.BigInteger) TransactionFilterBase(org.bcos.contract.source.TransactionFilterBase) Uint256(org.bcos.web3j.abi.datatypes.generated.Uint256)

Example 17 with Utf8String

use of org.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.

the class TypeDecoder method decodeUtf8String.

static Utf8String decodeUtf8String(String input, int offset) {
    DynamicBytes dynamicBytesResult = decodeDynamicBytes(input, offset);
    byte[] bytes = dynamicBytesResult.getValue();
    return new Utf8String(new String(bytes, StandardCharsets.UTF_8));
}
Also used : Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) DynamicBytes(org.bcos.web3j.abi.datatypes.DynamicBytes) Utf8String(org.bcos.web3j.abi.datatypes.Utf8String)

Example 18 with Utf8String

use of org.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.

the class LoadTestRunner method main.

public static void main(String[] args) throws Exception {
    logger.debug("初始化");
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.run();
    System.out.println("3s后开始测试...");
    Thread.sleep(1000);
    System.out.println("2s后开始测试...");
    Thread.sleep(1000);
    System.out.println("1s后开始测试...");
    Thread.sleep(1000);
    System.out.println("开始测试");
    System.out.println("===================================================================");
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);
    channelEthereumService.setTimeout(10000);
    Web3j web3 = Web3j.build(channelEthereumService);
    Thread.sleep(2000);
    // 先部署一个测试合约
    ECKeyPair keyPair = Keys.createEcKeyPair();
    Credentials credentials = Credentials.create(keyPair);
    RawTransactionManager rawTransactionManager = new RawTransactionManager(web3, credentials);
    java.math.BigInteger gasPrice = new BigInteger("30000000");
    java.math.BigInteger gasLimit = new BigInteger("30000000");
    java.math.BigInteger initialWeiValue = new BigInteger("0");
    LoadTest loadTest = LoadTest.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get();
    System.out.println("LoadTest getContractAddress " + loadTest.getContractAddress());
    // 发送交易
    for (Integer i = 0; i < 10; ++i) {
        Thread txThread = new Thread() {

            public void run() {
                try {
                    while (true) {
                        Thread.sleep(1000);
                        // TransactionReceipt receipt = loadTest.addCounter(new Utf8String(UUID.randomUUID().toString()), new Int256(1)).get();
                        loadTest.addCounter(new Utf8String(UUID.randomUUID().toString()), new Int256(1));
                    }
                } catch (Exception e) {
                    logger.error("系统错误", e);
                }
            }
        };
        txThread.start();
    }
    // 读取合约
    for (Integer i = 0; i < 10; ++i) {
        Thread callThread = new Thread() {

            public void run() {
                try {
                    while (true) {
                        Address origin = loadTest._origin().get();
                        Address sender = loadTest._sender().get();
                        logger.info("storage sender:{} origin:{}", sender.toString(), origin.toString());
                    }
                } catch (Exception e) {
                    logger.error("系统错误", e);
                }
            }
        };
        callThread.start();
    }
    // 200个线程,发链上链下消息
    for (Integer i = 0; i < 10; ++i) {
        Thread messageThread = new Thread() {

            public void run() {
                try {
                    while (true) {
                        ChannelRequest request = new ChannelRequest();
                        request.setToTopic("test");
                        request.setFromOrg("WB");
                        request.setToOrg("EB");
                        request.setMessageID(service.newSeq());
                        StringBuffer sb = new StringBuffer();
                        for (int i = 0; i < 500; ++i) {
                            sb.append("hello world!:");
                        }
                        request.setContent(sb.toString() + request.getMessageID());
                        request.setTimeout(2000);
                        // ChannelResponse response = service.sendChannelMessage2(request);
                        logger.info("发送链上链下消息:{}", request.getMessageID());
                        ChannelResponse response = service.sendChannelMessage(request);
                        logger.info("收到链上链下响应:{} {}", response.getMessageID(), response.getErrorCode());
                    }
                } catch (Exception e) {
                    logger.error("系统错误", e);
                }
            }
        };
        messageThread.start();
    }
    for (int i = 0; i < 10; ++i) {
        TransactionReceipt receipt = loadTest.addCounter(new Utf8String(UUID.randomUUID().toString()), new Int256(1)).get();
        Address origin = loadTest._origin().get();
        Address sender = loadTest._sender().get();
        List<Type> addresses = loadTest.constGetInf().get();
        logger.info("const sender:{} origin:{}", (((Address) addresses.get(0)).toString()), (((Address) addresses.get(1)).toString()));
        logger.info("storage sender:{} origin:{}", sender.toString(), origin.toString());
    }
}
Also used : ChannelRequest(org.bcos.channel.dto.ChannelRequest) Address(org.bcos.web3j.abi.datatypes.Address) ChannelEthereumService(org.bcos.web3j.protocol.channel.ChannelEthereumService) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BigInteger(java.math.BigInteger) ECKeyPair(org.bcos.web3j.crypto.ECKeyPair) TransactionReceipt(org.bcos.web3j.protocol.core.methods.response.TransactionReceipt) Service(org.bcos.channel.client.Service) ChannelEthereumService(org.bcos.web3j.protocol.channel.ChannelEthereumService) RawTransactionManager(org.bcos.web3j.tx.RawTransactionManager) ChannelResponse(org.bcos.channel.dto.ChannelResponse) BigInteger(java.math.BigInteger) Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) Int256(org.bcos.web3j.abi.datatypes.generated.Int256) Web3j(org.bcos.web3j.protocol.Web3j) Type(org.bcos.web3j.abi.datatypes.Type) BigInteger(java.math.BigInteger) Credentials(org.bcos.web3j.crypto.Credentials)

Example 19 with Utf8String

use of org.bcos.web3j.abi.datatypes.Utf8String in project web3sdk by FISCO-BCOS.

the class NodeAction method logMessageEventObservable.

public Observable<LogMessageEventResponse> logMessageEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
    final Event event = new Event("LogMessage", Arrays.<TypeReference<?>>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {
    }, new TypeReference<Uint256>() {
    }, new TypeReference<Utf8String>() {
    }));
    EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    return web3j.ethLogObservable(filter).map(new Func1<Log, LogMessageEventResponse>() {

        @Override
        public LogMessageEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            LogMessageEventResponse typedResponse = new LogMessageEventResponse();
            typedResponse.addr = (Address) eventValues.getNonIndexedValues().get(0);
            typedResponse.code = (Uint256) eventValues.getNonIndexedValues().get(1);
            typedResponse.msg = (Utf8String) eventValues.getNonIndexedValues().get(2);
            return typedResponse;
        }
    });
}
Also used : EventValues(org.bcos.web3j.abi.EventValues) EthFilter(org.bcos.web3j.protocol.core.methods.request.EthFilter) Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) Address(org.bcos.web3j.abi.datatypes.Address) Log(org.bcos.web3j.protocol.core.methods.response.Log) Event(org.bcos.web3j.abi.datatypes.Event) TypeReference(org.bcos.web3j.abi.TypeReference) Uint256(org.bcos.web3j.abi.datatypes.generated.Uint256)

Aggregations

Utf8String (org.bcos.web3j.abi.datatypes.Utf8String)19 Uint256 (org.bcos.web3j.abi.datatypes.generated.Uint256)15 EventValues (org.bcos.web3j.abi.EventValues)12 TypeReference (org.bcos.web3j.abi.TypeReference)12 Address (org.bcos.web3j.abi.datatypes.Address)12 Event (org.bcos.web3j.abi.datatypes.Event)12 EthFilter (org.bcos.web3j.protocol.core.methods.request.EthFilter)12 Log (org.bcos.web3j.protocol.core.methods.response.Log)12 Type (org.bcos.web3j.abi.datatypes.Type)6 BigInteger (java.math.BigInteger)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 InputStream (java.io.InputStream)2 Service (org.bcos.channel.client.Service)2 Uint8 (org.bcos.web3j.abi.datatypes.generated.Uint8)2 Credentials (org.bcos.web3j.crypto.Credentials)2 ECKeyPair (org.bcos.web3j.crypto.ECKeyPair)2 Web3j (org.bcos.web3j.protocol.Web3j)2 ChannelEthereumService (org.bcos.web3j.protocol.channel.ChannelEthereumService)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2