本文整理汇总了Java中org.web3j.protocol.http.HttpService类的典型用法代码示例。如果您正苦于以下问题:Java HttpService类的具体用法?Java HttpService怎么用?Java HttpService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpService类属于org.web3j.protocol.http包,在下文中一共展示了HttpService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEchoContract
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
public static Echo_sol_Echo getEchoContract()
throws JsonParseException, JsonMappingException, IOException, CipherException {
Web3j web3j = Web3j.build(new HttpService());
logger.debug("[ETH-INFO] Connected to TestRPC");
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
WalletFile walletFile = objectMapper
.readValue(ContractHelper.class.getResourceAsStream("/accountKeystore.json"), WalletFile.class);
Credentials credentials = Credentials.create(Wallet.decrypt(password, walletFile));
logger.debug("[ETH-INFO] Credentials: " + credentials.getAddress());
logger.debug("[ETH-INFO] Loading contract: " + contractAddress);
ese = Echo_sol_Echo.load(contractAddress, web3j, credentials, GAS_PRICE, GAS_LIMIT);
startObservable();
return ese;
}
示例2: EthereumWeb3jProvider
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
@Inject
public EthereumWeb3jProvider(EthereumConnectorConfig config) {
if (config.getEthereumJsonRpc() == null
&& config.getEthereumIpc() == null
&& config.getInfuraRpc() == null) {
this.web3j = Web3j.build(new HttpService(EthereumConnectorConfig.DEFAULT_JSON_RPC));
} else if (config.getEthereumJsonRpc() != null
&& config.getEthereumIpc() == null
&& config.getInfuraRpc() == null) {
this.web3j = Web3j.build(new HttpService(config.getEthereumJsonRpc()));
} else if (config.getEthereumJsonRpc() == null
&& config.getEthereumIpc() != null
&& config.getInfuraRpc() == null) {
this.web3j = Web3j.build(new UnixIpcService(config.getEthereumIpc()));
} else if (config.getEthereumJsonRpc() == null
&& config.getEthereumIpc() == null
&& config.getInfuraRpc() != null) {
this.web3j = Web3j.build(new InfuraHttpService(config.getInfuraRpc()));
} else {
throw new IllegalArgumentException("More than 1 Ethereum service providers found");
}
}
示例3: createTransaction
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
@Override
public Single<String> createTransaction(Wallet from, String toAddress, BigInteger subunitAmount, BigInteger gasPrice, BigInteger gasLimit, byte[] data, String password) {
final Web3j web3j = Web3jFactory.build(new HttpService(networkRepository.getDefaultNetwork().rpcServerUrl));
return Single.fromCallable(() -> {
EthGetTransactionCount ethGetTransactionCount = web3j
.ethGetTransactionCount(from.address, DefaultBlockParameterName.LATEST)
.send();
return ethGetTransactionCount.getTransactionCount();
})
.flatMap(nonce -> accountKeystoreService.signTransaction(from, password, toAddress, subunitAmount, gasPrice, gasLimit, nonce.longValue(), data, networkRepository.getDefaultNetwork().chainId))
.flatMap(signedMessage -> Single.fromCallable( () -> {
EthSendTransaction raw = web3j
.ethSendRawTransaction(Numeric.toHexString(signedMessage))
.send();
if (raw.hasError()) {
throw new ServiceException(raw.getError().getMessage());
}
return raw.getTransactionHash();
})).subscribeOn(Schedulers.io());
}
示例4: runPrivateGreeterTest
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
private void runPrivateGreeterTest(
Node sourceNode, Node destNode, String requestId) throws Exception {
Quorum quorum = Quorum.build(new HttpService(sourceNode.getUrl()));
ClientTransactionManager transactionManager =
new ClientTransactionManager(
quorum,
sourceNode.getAddress(), destNode.getPublicKeys());
String greeting = "Hello Quorum world! [" + requestId + "]";
Greeter contract = Greeter.deploy(
quorum, transactionManager,
GAS_PRICE, GAS_LIMIT,
greeting).send();
assertThat(contract.greet().send(), is(greeting));
}
示例5: testFibonacciNotify
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
@Test
public void testFibonacciNotify() throws Exception {
Fibonacci fibonacci = Fibonacci.load(
"0x3c05b2564139fb55820b18b72e94b2178eaace7d", Web3j.build(new HttpService()),
ALICE, GAS_PRICE, GAS_LIMIT);
TransactionReceipt transactionReceipt = fibonacci.fibonacciNotify(
BigInteger.valueOf(15)).send();
Fibonacci.NotifyEventResponse result = fibonacci.getNotifyEvents(transactionReceipt).get(0);
assertThat(result.input,
equalTo(new Uint256(BigInteger.valueOf(15))));
assertThat(result.result,
equalTo(new Uint256(BigInteger.valueOf(610))));
}
示例6: setUpClass
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException, CipherException {
credentials = WalletUtils.loadCredentials("password", KEY_FILE1);
testData1 = TestData.staticGenerate(credentials.getAddress());
parity = Parity.build(new HttpService("http://localhost:8545"));
// parity.personalUnlockAccount(credentials.getAddress(), "password", new BigInteger("100000"));
Cmc cmc = Cmc.load(CMC_ADDR, parity, credentials, GAS_PRICE, GAS_LIMIT);
cmcWrapper = new CmcWrapper(cmc);
// cmcWrapper.bootstrap();
String dnsManagerAddress = cmcWrapper.getAddress(APP_NAME);
SolDnsApp solDnsApp = SolDnsApp.load(dnsManagerAddress, parity, credentials, GAS_PRICE, GAS_LIMIT);
solDnsAppWrapper = new SolDnsAppWrapper(solDnsApp);
}
示例7: getModumToken
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
@Bean
public ModumToken getModumToken() throws IOException, CipherException {
Web3j web3j = Web3j.build(new HttpService());
try {
Credentials credentials = WalletUtils.loadCredentials(password, account);
return ModumToken.load(contract, web3j, credentials, ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT);
} catch (FileNotFoundException e) {
return null;
}
}
示例8: before
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
@Before
public void before() throws IOException, InterruptedException, ExecutionException {
web3j = Web3j.build(new HttpService());
EthAccounts accounts = web3j.ethAccounts().send();
Assert.assertNotEquals(0, accounts.getAccounts().size());
// use the first account as the main account for the tests
mainAccountAddress = accounts.getAccounts().get(0);
// deploy the contract
txManager = new ClientTransactionManager(web3j, mainAccountAddress);
bankAccountContract = BankAccount.deploy(web3j, txManager, GAS_PRICE, GAS_LIMIT, BigInteger.valueOf(0))
.get();
}
开发者ID:SenthuranSivananthan,项目名称:devops-blockchain-jenkins,代码行数:16,代码来源:BankAccountSmartContractTests.java
示例9: fetchGasSettings
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
private void fetchGasSettings() {
final Web3j web3j = Web3jFactory.build(new HttpService(networkRepository.getDefaultNetwork().rpcServerUrl));
try {
EthGasPrice price = web3j
.ethGasPrice()
.send();
cachedGasPrice = price.getGasPrice();
} catch (Exception ex) {
// silently
}
}
示例10: balanceInWei
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
@Override
public Single<BigInteger> balanceInWei(Wallet wallet) {
return Single.fromCallable(() -> Web3jFactory
.build(new HttpService(networkRepository.getDefaultNetwork().rpcServerUrl, httpClient, false))
.ethGetBalance(wallet.address, DefaultBlockParameterName.LATEST)
.send()
.getBalance())
.subscribeOn(Schedulers.io());
}
示例11: connect
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
public static Web3j connect() {
String clientUrl = String.format("http://%s:%s", IP_ADDRESS, PORT);
System.out.println("Trying to connect to Ethereum net on " + clientUrl + " ...");
web3j = Web3j.build(new HttpService(clientUrl));
System.out.println("Connected to " + getClientVersion());
return web3j;
}
示例12: getWeb3j
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
public Web3j getWeb3j() {
if (web3j == null) {
LOG.info("Trying to connect to Ethereum net ...");
String clientIp = CONFIG.getPropertyValue(EthereumClientIpProperty.class);
String clientPort = CONFIG.getPropertyValue(EthereumClientPortProperty.class);
String clientUrl = String.format("http://%s:%s", clientIp, clientPort);
web3j = Web3j.build(new HttpService(clientUrl));
LOG.info("Successfully connected");
}
return web3j;
}
示例13: init
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
private void init() {
if (USING_IPC) {
if (DEBUG) { // IPC Logging
System.setProperty("org.apache.commons.logging.simplelog.log.org.web3j.protocol.ipc", "DEBUG");
}
web3j = Web3j.build(new UnixIpcService(IPC_SOCKET_PATH));
} else {
if (DEBUG) { // HTTP Logging
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "DEBUG");
System.setProperty("org.apache.commons.logging.simplelog.log.org.web3j.protocol.ipc", "DEBUG");
}
web3j = Web3j.build(new HttpService(URL_JSON_RPC));
}
subscription = web3j.blockObservable(false).subscribe(block -> {
blockObservable(block);
}, Throwable::printStackTrace, () -> System.out.println("block done"));
web3j.transactionObservable().subscribe(tx -> {
transactionObservable(tx);
}, Throwable::printStackTrace, () -> System.out.println("tx done"));
web3j.pendingTransactionObservable().subscribe(tx -> {
pendingTransactionObservable(tx);
}, Throwable::printStackTrace, () -> System.out.println("ptx done"));
}
示例14: testEns
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
@Test
public void testEns() throws Exception {
Web3j web3j = Web3j.build(new HttpService());
EnsResolver ensResolver = new EnsResolver(web3j);
assertThat(ensResolver.resolve("web3j.test"),
is("0x19e03255f667bdfd50a32722df860b1eeaf4d635"));
}
示例15: testFibonacci
import org.web3j.protocol.http.HttpService; //导入依赖的package包/类
@Test
public void testFibonacci() throws Exception {
Fibonacci fibonacci = Fibonacci.load(
"0x3c05b2564139fb55820b18b72e94b2178eaace7d", Web3j.build(new HttpService()),
ALICE, GAS_PRICE, GAS_LIMIT);
BigInteger result = fibonacci.fibonacci(BigInteger.valueOf(10)).send();
assertThat(result, equalTo(BigInteger.valueOf(55)));
}