Search in sources :

Example 1 with Uint256

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

the class Ethereum 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();
    Thread.sleep(3000);
    System.out.println("开始测试...");
    System.out.println("===================================================================");
    logger.info("初始化AOMP的ChannelEthereumService");
    ChannelEthereumService channelEthereumService = new ChannelEthereumService();
    channelEthereumService.setChannelService(service);
    // 使用AMOP消息信道初始化web3j
    Web3j web3 = Web3j.build(channelEthereumService);
    logger.info("调用web3的getBlockNumber接口");
    EthBlockNumber ethBlockNumber = web3.ethBlockNumber().sendAsync().get();
    logger.info("获取ethBlockNumber:{}", ethBlockNumber);
    // 初始化交易签名私钥
    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");
    // 部署合约
    Ok ok = Ok.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get();
    System.out.println("Ok getContractAddress " + ok.getContractAddress());
    // 调用合约接口
    java.math.BigInteger Num = new BigInteger("999");
    Uint256 num = new Uint256(Num);
    TransactionReceipt receipt = ok.trans(num).get();
    System.out.println("receipt transactionHash" + receipt.getTransactionHash());
    // 查询合约数据
    num = ok.get().get();
    System.out.println("ok.get() " + num.getValue());
}
Also used : EthBlockNumber(org.bcos.web3j.protocol.core.methods.response.EthBlockNumber) 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) ChannelEthereumService(org.bcos.web3j.protocol.channel.ChannelEthereumService) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Web3j(org.bcos.web3j.protocol.Web3j) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BigInteger(java.math.BigInteger) BigInteger(java.math.BigInteger) Uint256(org.bcos.web3j.abi.datatypes.generated.Uint256) Credentials(org.bcos.web3j.crypto.Credentials)

Example 2 with Uint256

use of org.bcos.web3j.abi.datatypes.generated.Uint256 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 3 with Uint256

use of org.bcos.web3j.abi.datatypes.generated.Uint256 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 4 with Uint256

use of org.bcos.web3j.abi.datatypes.generated.Uint256 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 5 with Uint256

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

the class CAActionTools method processCAAction.

static void processCAAction(ApplicationContext ctx, CAAction caActions, String[] args) {
    try {
        switch(args[1]) {
            case "update":
            case "updateStatus":
                if (args.length < 3) {
                    System.out.println("Please input: ca.json");
                    break;
                }
                System.out.println("ca.json=" + args[2]);
                Resource template = ctx.getResource(args[2]);
                InputStream ksInputStream = template.getInputStream();
                ObjectMapper mapper = new ObjectMapper();
                mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
                CaInfo caInfo = mapper.readValue(ksInputStream, CaInfo.class);
                if (args[1].equals("update")) {
                    caActions.update(new Utf8String(caInfo.getHash()), new Utf8String(caInfo.getPubkey()), new Utf8String(caInfo.getOrgname()), new Uint256(caInfo.getNotbefore()), new Uint256(caInfo.getNotafter()), new Uint8(caInfo.getStatus()), new Utf8String(caInfo.getWhitelist()), new Utf8String(caInfo.getBlacklist())).get();
                } else {
                    caActions.updateStatus(new Utf8String(caInfo.getHash()), new Uint8(caInfo.getStatus())).get();
                }
            case "all":
                Uint256 len = caActions.getHashsLength().get();
                System.out.println("HashsLength= " + len);
                for (int i = 0; i < len.getValue().intValue(); i++) {
                    System.out.println("----------CA " + i + "---------");
                    Utf8String hash = caActions.getHash(new Uint256(i)).get();
                    System.out.println("hash=" + hash);
                    List<Type> ca = caActions.get(hash).get();
                    System.out.println("pubkey=" + ca.get(1));
                    System.out.println("orgname=" + ca.get(2));
                    System.out.println("notbefore=" + ca.get(3));
                    System.out.println("notafter=" + ca.get(4));
                    System.out.println("status=" + ca.get(5));
                    System.out.println("blocknumber=" + ca.get(6));
                    List<Type> iplist = caActions.getIp(hash).get();
                    System.out.println("whitelist=" + iplist.get(0));
                    System.out.println("blacklist=" + iplist.get(1));
                }
                break;
            default:
                break;
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}
Also used : Utf8String(org.bcos.web3j.abi.datatypes.Utf8String) Uint8(org.bcos.web3j.abi.datatypes.generated.Uint8) Type(org.bcos.web3j.abi.datatypes.Type) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) Uint256(org.bcos.web3j.abi.datatypes.generated.Uint256) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Uint256 (org.bcos.web3j.abi.datatypes.generated.Uint256)16 Utf8String (org.bcos.web3j.abi.datatypes.Utf8String)15 EventValues (org.bcos.web3j.abi.EventValues)11 TypeReference (org.bcos.web3j.abi.TypeReference)11 Address (org.bcos.web3j.abi.datatypes.Address)11 Event (org.bcos.web3j.abi.datatypes.Event)11 EthFilter (org.bcos.web3j.protocol.core.methods.request.EthFilter)11 Log (org.bcos.web3j.protocol.core.methods.response.Log)11 BigInteger (java.math.BigInteger)4 Type (org.bcos.web3j.abi.datatypes.Type)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