Search in sources :

Example 1 with Address

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

the class CAAction 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)

Example 2 with Address

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

the class ConfigAction 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)

Example 3 with Address

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

the class ContractAbiMgr method updateAbiEventObservable.

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

        @Override
        public UpdateAbiEventResponse call(Log log) {
            EventValues eventValues = extractEventParameters(event, log);
            UpdateAbiEventResponse typedResponse = new UpdateAbiEventResponse();
            typedResponse.cns_name = (Utf8String) eventValues.getNonIndexedValues().get(0);
            typedResponse.contractname = (Utf8String) eventValues.getNonIndexedValues().get(1);
            typedResponse.version = (Utf8String) eventValues.getNonIndexedValues().get(2);
            typedResponse.abi = (Utf8String) eventValues.getNonIndexedValues().get(3);
            typedResponse.addr = (Address) eventValues.getNonIndexedValues().get(4);
            typedResponse.blocknumber = (Uint256) eventValues.getNonIndexedValues().get(5);
            typedResponse.timestamp = (Uint256) eventValues.getNonIndexedValues().get(6);
            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)

Example 4 with Address

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

the class InitSystemContract method main.

public static void main(String[] args) throws Exception {
    // 初始化Service
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    Service service = context.getBean(Service.class);
    service.run();
    System.out.println("开始部署...");
    System.out.println("===================================================================");
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);
    // init web3j
    Web3j web3 = Web3j.build(channelEthereumService);
    // 初始化交易签名私钥
    ECKeyPair keyPair = Keys.createEcKeyPair();
    Credentials credentials = Credentials.create(keyPair);
    // 初始化交易参数
    java.math.BigInteger gasPrice = new BigInteger("30000000");
    java.math.BigInteger gasLimit = new BigInteger("30000000");
    java.math.BigInteger initialWeiValue = new BigInteger("0");
    ToolConf toolConf = context.getBean(ToolConf.class);
    SystemProxy systemProxy = SystemProxy.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get();
    System.out.println("systemProxy getContractAddress " + systemProxy.getContractAddress());
    writeAddress(toolConf.getOutPutpath() + "SystemProxy.address", systemProxy.getContractAddress());
    CAAction caAction = CAAction.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue, new Address(systemProxy.getContractAddress())).get();
    System.out.println("caAction getContractAddress " + caAction.getContractAddress());
    writeAddress(toolConf.getOutPutpath() + "CAAction.address", caAction.getContractAddress());
    NodeAction nodeAction = NodeAction.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get();
    System.out.println("nodeAction getContractAddress " + nodeAction.getContractAddress());
    writeAddress(toolConf.getOutPutpath() + "NodeAction.address", nodeAction.getContractAddress());
    ConfigAction configAction = ConfigAction.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get();
    System.out.println("configAction getContractAddress " + configAction.getContractAddress());
    writeAddress(toolConf.getOutPutpath() + "ConfigAction.address", configAction.getContractAddress());
    FileInfoManager fileInfoManager = FileInfoManager.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get();
    System.out.println("fileInfoManager getContractAddress " + fileInfoManager.getContractAddress());
    writeAddress(toolConf.getOutPutpath() + "fileInfoManager.address", fileInfoManager.getContractAddress());
    FileServerManager fileServerManager = FileServerManager.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get();
    System.out.println("fileServerManager getContractAddress " + fileServerManager.getContractAddress());
    writeAddress(toolConf.getOutPutpath() + "fileServerManager.address", fileServerManager.getContractAddress());
    ContractAbiMgr contractAbiMgr = ContractAbiMgr.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get();
    System.out.println("contractAbiMgr getContractAddress " + contractAbiMgr.getContractAddress());
    writeAddress(toolConf.getOutPutpath() + "ContractAbiMgr.address", contractAbiMgr.getContractAddress());
    AuthorityFilter authorityFilter = AuthorityFilter.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get();
    System.out.println("authorityFilter getContractAddress " + authorityFilter.getContractAddress());
    writeAddress(toolConf.getOutPutpath() + "AuthorityFilter.address", authorityFilter.getContractAddress());
    authorityFilter.setName(new Utf8String("AuthorityFilter"));
    authorityFilter.setVersion(new Utf8String("1.0"));
    Group group = Group.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get();
    System.out.println("group getContractAddress " + group.getContractAddress());
    writeAddress(toolConf.getOutPutpath() + "Group.address", group.getContractAddress());
    TransactionFilterChain transactionFilterChain = TransactionFilterChain.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get();
    System.out.println("transactionFilterChain getContractAddress " + transactionFilterChain.getContractAddress());
    writeAddress(toolConf.getOutPutpath() + "transactionFilterChain.address", transactionFilterChain.getContractAddress());
    contractAbiMgr.addAbi(new Utf8String("ContractAbiMgr"), new Utf8String("ContractAbiMgr"), new Utf8String(""), new Utf8String(ContractAbiMgr.ABI), new Address(contractAbiMgr.getContractAddress()));
    contractAbiMgr.addAbi(new Utf8String("SystemProxy"), new Utf8String("SystemProxy"), new Utf8String(""), new Utf8String(SystemProxy.ABI), new Address(contractAbiMgr.getContractAddress()));
    contractAbiMgr.addAbi(new Utf8String("TransactionFilterChain"), new Utf8String("TransactionFilterChain"), new Utf8String(""), new Utf8String(TransactionFilterChain.ABI), new Address(contractAbiMgr.getContractAddress()));
    contractAbiMgr.addAbi(new Utf8String("AuthorityFilter"), new Utf8String("AuthorityFilter"), new Utf8String(""), new Utf8String(AuthorityFilter.ABI), new Address(contractAbiMgr.getContractAddress()));
    contractAbiMgr.addAbi(new Utf8String("Group"), new Utf8String("Group"), new Utf8String(""), new Utf8String(Group.ABI), new Address(contractAbiMgr.getContractAddress()));
    contractAbiMgr.addAbi(new Utf8String("CAAction"), new Utf8String("CAAction"), new Utf8String(""), new Utf8String(CAAction.ABI), new Address(contractAbiMgr.getContractAddress()));
    contractAbiMgr.addAbi(new Utf8String("ConfigAction"), new Utf8String("ConfigAction"), new Utf8String(""), new Utf8String(ConfigAction.ABI), new Address(contractAbiMgr.getContractAddress()));
    contractAbiMgr.addAbi(new Utf8String("NodeAction"), new Utf8String("NodeAction"), new Utf8String(""), new Utf8String(NodeAction.ABI), new Address(contractAbiMgr.getContractAddress()));
    transactionFilterChain.addFilter(new Address(authorityFilter.getContractAddress()));
    systemProxy.setRoute(new Utf8String("TransactionFilterChain"), new Address(transactionFilterChain.getContractAddress()), new Bool(false)).get();
    systemProxy.setRoute(new Utf8String("ConfigAction"), new Address(configAction.getContractAddress()), new Bool(false)).get();
    systemProxy.setRoute(new Utf8String("NodeAction"), new Address(nodeAction.getContractAddress()), new Bool(false)).get();
    systemProxy.setRoute(new Utf8String("CAAction"), new Address(caAction.getContractAddress()), new Bool(false)).get();
    systemProxy.setRoute(new Utf8String("ContractAbiMgr"), new Address(contractAbiMgr.getContractAddress()), new Bool(false)).get();
    systemProxy.setRoute(new Utf8String("FileInfoManager"), new Address(fileInfoManager.getContractAddress()), new Bool(false)).get();
    systemProxy.setRoute(new Utf8String("FileServerManager"), new Address(fileServerManager.getContractAddress()), new Bool(false)).get();
    System.out.println("合约部署完成 系统代理合约:" + systemProxy.getContractAddress());
    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(), web3, 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(), web3, credentials, gasPrice, gasLimit);
                Utf8String name = transactionFilterBase._name().get();
                Utf8String version = transactionFilterBase._version().get();
                System.out.println("       " + name + "=>" + version + "," + filter);
            }
        }
    }
    System.exit(0);
}
Also used : 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) Bool(org.bcos.web3j.abi.datatypes.Bool) BigInteger(java.math.BigInteger) ECKeyPair(org.bcos.web3j.crypto.ECKeyPair) Service(org.bcos.channel.client.Service) ChannelEthereumService(org.bcos.web3j.protocol.channel.ChannelEthereumService) Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) Web3j(org.bcos.web3j.protocol.Web3j) Type(org.bcos.web3j.abi.datatypes.Type) BigInteger(java.math.BigInteger) Uint256(org.bcos.web3j.abi.datatypes.generated.Uint256) Credentials(org.bcos.web3j.crypto.Credentials)

Example 5 with Address

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

the class Base 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

Address (org.bcos.web3j.abi.datatypes.Address)12 Utf8String (org.bcos.web3j.abi.datatypes.Utf8String)12 Uint256 (org.bcos.web3j.abi.datatypes.generated.Uint256)11 EventValues (org.bcos.web3j.abi.EventValues)9 TypeReference (org.bcos.web3j.abi.TypeReference)9 Event (org.bcos.web3j.abi.datatypes.Event)9 EthFilter (org.bcos.web3j.protocol.core.methods.request.EthFilter)9 Log (org.bcos.web3j.protocol.core.methods.response.Log)9 BigInteger (java.math.BigInteger)3 Type (org.bcos.web3j.abi.datatypes.Type)3 Service (org.bcos.channel.client.Service)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 ChannelRequest (org.bcos.channel.dto.ChannelRequest)1 ChannelResponse (org.bcos.channel.dto.ChannelResponse)1 TransactionFilterBase (org.bcos.contract.source.TransactionFilterBase)1