org.fisco.bcos.web3j.protocol.core.DefaultBlockParameter Java Examples
The following examples show how to use
org.fisco.bcos.web3j.protocol.core.DefaultBlockParameter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Web3ApiService.java From WeBASE-Front with Apache License 2.0 | 6 votes |
/** * getBlockTransCntByNumber. * * @param blockNumber blockNumber */ public int getBlockTransCntByNumber(int groupId, BigInteger blockNumber) { int transCnt; try { if (blockNumberCheck(groupId, blockNumber)) { throw new FrontException("ConstantCode.NODE_REQUEST_FAILED"); } BcosBlock.Block block = getWeb3j(groupId) .getBlockByNumber(DefaultBlockParameter.valueOf(blockNumber), true) .send() .getBlock(); transCnt = block.getTransactions().size(); } catch (IOException e) { log.error("getBlockTransCntByNumber fail. blockNumber:{} ", blockNumber); throw new FrontException(ConstantCode.NODE_REQUEST_FAILED); } return transCnt; }
Example #2
Source File: Web3ApiService.java From WeBASE-Front with Apache License 2.0 | 6 votes |
/** * getTransByBlockNumberAndIndex. * * @param blockNumber blockNumber * @param transactionIndex index */ public Transaction getTransByBlockNumberAndIndex(int groupId, BigInteger blockNumber, BigInteger transactionIndex) { Transaction transaction = null; try { if (blockNumberCheck(groupId, blockNumber)) { throw new FrontException("ConstantCode.NODE_REQUEST_FAILED"); } Optional<Transaction> opt = getWeb3j(groupId) .getTransactionByBlockNumberAndIndex( DefaultBlockParameter.valueOf(blockNumber), transactionIndex) .send().getTransaction(); if (opt.isPresent()) { transaction = opt.get(); } } catch (IOException e) { log.error("getTransByBlockNumberAndIndex fail.", e); throw new FrontException(ConstantCode.NODE_REQUEST_FAILED); } return transaction; }
Example #3
Source File: MockBlockTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Test public void getBlockNumber() throws IOException { BcosBlock block = objectMapper.readValue(rawResponse, BcosBlock.class); block.setRawResponse(rawResponse); Web3j web3j = Web3j.build(web3jService); when(web3jService.send(any(Request.class), eq(BcosBlock.class))).thenReturn(block); BcosBlock mockBlocks = web3j.getBlockByNumber(DefaultBlockParameter.valueOf(new BigInteger("1")), true) .send(); BcosBlock.Block mockBlock = mockBlocks.getBlock(); assertEquals(mockBlock.getNonce(), new BigInteger("0")); assertTrue(mockBlock.getNumber().intValue() == 1); }
Example #4
Source File: Web3ApiService.java From WeBASE-Front with Apache License 2.0 | 6 votes |
/** * getBlockByNumber. * * @param blockNumber blockNumber */ public BcosBlock.Block getBlockByNumber(int groupId, BigInteger blockNumber) { if (blockNumberCheck(groupId, blockNumber)) { throw new FrontException(ConstantCode.BLOCK_NUMBER_ERROR); } BcosBlock.Block block; try { block = getWeb3j(groupId) .getBlockByNumber(DefaultBlockParameter.valueOf(blockNumber), true) .send() .getBlock(); } catch (IOException e) { log.info("get blocknumber failed" + e.getMessage()); log.error("getBlAockByNumber fail. blockNumber:{} , groupID: {}", blockNumber, groupId); throw new FrontException(ConstantCode.NODE_REQUEST_FAILED); } return block; }
Example #5
Source File: BcosFilter.java From web3sdk with Apache License 2.0 | 5 votes |
public BcosFilter( DefaultBlockParameter fromBlock, DefaultBlockParameter toBlock, List<String> address) { super(); this.fromBlock = fromBlock; this.toBlock = toBlock; this.address = address; }
Example #6
Source File: Web3jApITest.java From web3sdk with Apache License 2.0 | 5 votes |
@Test public void getTransactionByBlockNumberAndIndex() throws IOException { BcosTransaction bcosTransaction = web3j .getTransactionByBlockNumberAndIndex( DefaultBlockParameter.valueOf(blockNumber), new BigInteger("0")) .send(); Transaction transaction = bcosTransaction.getTransaction().get(); assertNotNull(transaction); }
Example #7
Source File: EthClient.java From WeBASE-Collect-Bee with Apache License 2.0 | 5 votes |
@Cacheable(cacheNames = { "block" }) @Retry public Block getBlock(BigInteger blockHeightNumber) throws IOException { Stopwatch stopwatch = Stopwatch.createStarted(); log.debug("get block number: {}", blockHeightNumber); Block block = web3j.getBlockByNumber(DefaultBlockParameter.valueOf(blockHeightNumber), false).send().getBlock(); Stopwatch st1 = stopwatch.stop(); log.info("get block:{} succeed, eth.getBlock useTime: {}", blockHeightNumber, st1.elapsed(TimeUnit.MILLISECONDS)); return block; }
Example #8
Source File: BasicTest.java From WeBASE-Front with Apache License 2.0 | 5 votes |
private void testDeployContract(Web3j web3j, Credentials credentials) throws Exception { Ok okDemo = Ok.deploy(web3j, credentials, gasPrice, gasLimit).send(); if (okDemo != null) { System.out.println( "####get nonce from Block: " + web3j .getBlockByNumber(DefaultBlockParameter.valueOf(new BigInteger("0")), true) .send() .getBlock() .getNonce()); System.out.println( "####get block number by index from Block: " + web3j .getBlockByNumber(DefaultBlockParameter.valueOf(new BigInteger("1")), true) .send() .getBlock() .getNumber()); System.out.println("####contract address is: " + okDemo.getContractAddress()); // TransactionReceipt receipt = okDemo.trans(new // BigInteger("4")).sendAsync().get(60000, TimeUnit.MILLISECONDS); TransactionReceipt receipt = okDemo.trans(new BigInteger("4")).send(); List<Ok.TransEventEventResponse> events = okDemo.getTransEventEvents(receipt); events.stream().forEach(System.out::println); System.out.println("###callback trans success"); System.out.println( "####get block number from TransactionReceipt: " + receipt.getBlockNumber()); System.out.println( "####get transaction index from TransactionReceipt: " + receipt.getTransactionIndex()); System.out.println("####get gas used from TransactionReceipt: " + receipt.getGasUsed()); // System.out.println("####get cumulative gas used from TransactionReceipt: " + // receipt.getCumulativeGasUsed()); BigInteger toBalance = okDemo.get().send(); System.out.println("============to balance:" + toBalance.intValue()); } }
Example #9
Source File: BasicTest.java From WeBASE-Front with Apache License 2.0 | 5 votes |
@Ignore @Test public void getTransactionByBlockNumberAndIndexTest() throws IOException { Transaction transaction = web3j .getTransactionByBlockNumberAndIndex( DefaultBlockParameter.valueOf(new BigInteger("1")), new BigInteger("0")) .send() .getTransaction() .get(); assertTrue(transaction.getBlockNumber().intValue() == 1); }
Example #10
Source File: BasicTest.java From WeBASE-Front with Apache License 2.0 | 5 votes |
@Test public void getBlockNumber() throws Exception { BcosBlock bcosBlock = web3j.getBlockByNumber(DefaultBlockParameter.valueOf("latest"),true).send(); System.out.println(bcosBlock.getBlock()); Block block = bcosBlock.getBlock(); System.out.println(bcosBlock.getBlock().getNonce()); System.out.println(web3j.getBlockByNumber(DefaultBlockParameter.valueOf("latest"),true).send()); assertNotNull(web3j.getConsensusStatus().sendForReturnString()); }
Example #11
Source File: Web3ApiService.java From WeBASE-Front with Apache License 2.0 | 5 votes |
/** * getCode. * * @param address address * @param blockNumber blockNumber */ public String getCode(int groupId, String address, BigInteger blockNumber) { String code; try { if (blockNumberCheck(groupId, blockNumber)) { throw new FrontException(ConstantCode.BLOCK_NUMBER_ERROR); } code = getWeb3j(groupId) .getCode(address, DefaultBlockParameter.valueOf(blockNumber)).send().getCode(); } catch (IOException e) { log.error("getCode fail.", e); throw new FrontException(ConstantCode.NODE_REQUEST_FAILED); } return code; }
Example #12
Source File: Evidence.java From evidenceSample with Apache License 2.0 | 4 votes |
public Flowable<ErrorRepeatSignaturesEventEventResponse> errorRepeatSignaturesEventEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(ERRORREPEATSIGNATURESEVENT_EVENT)); return errorRepeatSignaturesEventEventFlowable(filter); }
Example #13
Source File: TableTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<UpdateResultEventResponse> updateResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(UPDATERESULT_EVENT)); return updateResultEventFlowable(filter); }
Example #14
Source File: TableTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<RemoveResultEventResponse> removeResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(REMOVERESULT_EVENT)); return removeResultEventFlowable(filter); }
Example #15
Source File: Ok.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<TransEventEventResponse> transEventEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(TRANSEVENT_EVENT)); return transEventEventFlowable(filter); }
Example #16
Source File: OkD.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<InsertResultEventResponse> insertResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(INSERTRESULT_EVENT)); return insertResultEventFlowable(filter); }
Example #17
Source File: TableTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<CreateResultEventResponse> createResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(CREATERESULT_EVENT)); return createResultEventFlowable(filter); }
Example #18
Source File: TableTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<SelectResultEventResponse> selectResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(SELECTRESULT_EVENT)); return selectResultEventFlowable(filter); }
Example #19
Source File: TableTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<InsertResultEventResponse> insertResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(INSERTRESULT_EVENT)); return insertResultEventFlowable(filter); }
Example #20
Source File: TableTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<UpdateResultEventResponse> updateResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(UPDATERESULT_EVENT)); return updateResultEventFlowable(filter); }
Example #21
Source File: TableTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<RemoveResultEventResponse> removeResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(REMOVERESULT_EVENT)); return removeResultEventFlowable(filter); }
Example #22
Source File: TableTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<InsertResultEventResponse> insertResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(INSERTRESULT_EVENT)); return insertResultEventFlowable(filter); }
Example #23
Source File: NewSolTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<OwnershipTransferredEventResponse> ownershipTransferredEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(OWNERSHIPTRANSFERRED_EVENT)); return ownershipTransferredEventFlowable(filter); }
Example #24
Source File: NewSolTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<TransferEventResponse> transferEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(TRANSFER_EVENT)); return transferEventFlowable(filter); }
Example #25
Source File: NewSolTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<ApprovalEventResponse> approvalEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(APPROVAL_EVENT)); return approvalEventFlowable(filter); }
Example #26
Source File: TableTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<CreateResultEventResponse> createResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(CREATERESULT_EVENT)); return createResultEventFlowable(filter); }
Example #27
Source File: TableTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<InsertResultEventResponse> insertResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(INSERTRESULT_EVENT)); return insertResultEventFlowable(filter); }
Example #28
Source File: TableTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<UpdateResultEventResponse> updateResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(UPDATERESULT_EVENT)); return updateResultEventFlowable(filter); }
Example #29
Source File: TableTest.java From web3sdk with Apache License 2.0 | 4 votes |
public Flowable<RemoveResultEventResponse> removeResultEventFlowable( DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(REMOVERESULT_EVENT)); return removeResultEventFlowable(filter); }
Example #30
Source File: EvidenceSignersData.java From evidenceSample with Apache License 2.0 | 4 votes |
public Flowable<NewEvidenceEventEventResponse> newEvidenceEventEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { BcosFilter filter = new BcosFilter(startBlock, endBlock, getContractAddress()); filter.addSingleTopic(EventEncoder.encode(NEWEVIDENCEEVENT_EVENT)); return newEvidenceEventEventFlowable(filter); }