org.web3j.tx.ChainId Java Examples

The following examples show how to use org.web3j.tx.ChainId. 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: Contracts.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
public static String resolveRegistryContract(String chainId) {
    switch (Byte.valueOf(chainId)) {
        case ChainId.MAINNET:
            return MAINNET;
        case ChainId.ROPSTEN:
            return ROPSTEN;
        case ChainId.RINKEBY:
            return RINKEBY;
        default:
            throw new EnsResolutionException(
                    "Unable to resolve ENS registry contract for network id: " + chainId);
    }
}
 
Example #2
Source File: EnsResolverTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testResolve() throws Exception {
    configureSyncing(false);
    configureLatestBlock(System.currentTimeMillis() / 1000);  // block timestamp is in seconds

    NetVersion netVersion = new NetVersion();
    netVersion.setResult(Byte.toString(ChainId.MAINNET));

    String resolverAddress =
            "0x0000000000000000000000004c641fb9bad9b60ef180c31f56051ce826d21a9a";
    String contractAddress =
            "0x00000000000000000000000019e03255f667bdfd50a32722df860b1eeaf4d635";

    EthCall resolverAddressResponse = new EthCall();
    resolverAddressResponse.setResult(resolverAddress);

    EthCall contractAddressResponse = new EthCall();
    contractAddressResponse.setResult(contractAddress);

    when(web3jService.send(any(Request.class), eq(NetVersion.class)))
            .thenReturn(netVersion);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(resolverAddressResponse);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(contractAddressResponse);

    assertThat(ensResolver.resolve("web3j.eth"),
            is("0x19e03255f667bdfd50a32722df860b1eeaf4d635"));
}
 
Example #3
Source File: EnsResolverTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testReverseResolve() throws Exception {
    configureSyncing(false);
    configureLatestBlock(System.currentTimeMillis() / 1000);  // block timestamp is in seconds

    NetVersion netVersion = new NetVersion();
    netVersion.setResult(Byte.toString(ChainId.MAINNET));

    String resolverAddress =
            "0x0000000000000000000000004c641fb9bad9b60ef180c31f56051ce826d21a9a";
    String contractName =
            "0x0000000000000000000000000000000000000000000000000000000000000020"
            + TypeEncoder.encode(new Utf8String("web3j.eth"));
    System.err.println(contractName);

    EthCall resolverAddressResponse = new EthCall();
    resolverAddressResponse.setResult(resolverAddress);

    EthCall contractNameResponse = new EthCall();
    contractNameResponse.setResult(contractName);

    when(web3jService.send(any(Request.class), eq(NetVersion.class)))
            .thenReturn(netVersion);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(resolverAddressResponse);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(contractNameResponse);

    assertThat(ensResolver.reverseResolve("0x19e03255f667bdfd50a32722df860b1eeaf4d635"),
            is("web3j.eth"));
}
 
Example #4
Source File: TransactionManager.java    From BitcoinWallet with MIT License 5 votes vote down vote up
public String signData(RawTransaction rawTransaction, WalletFile walletfile, String password)
        throws Exception {
    Credentials credentials = Credentials.create(Wallet.decrypt(password, walletfile));
    byte[] signMessage =
            TransactionEncoder.signMessage(rawTransaction, ChainId.ROPSTEN, credentials);
    return Numeric.toHexString(signMessage);

}
 
Example #5
Source File: GasSliderView.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
/**
 * Currently, the dynamic price vs time is main net only
 * @param chainId
 */
public void setChainId(int chainId)
{
    //TODO: Add tx fee in FIAT for network transactions. Requires token or ticker.
    if (chainId != ChainId.MAINNET)
    {
        isMainNet = false;
    }
}
 
Example #6
Source File: ContractsTest.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testResolveRegistryContract() {
    assertThat(resolveRegistryContract(ChainId.MAINNET + ""), is(MAINNET));
    assertThat(resolveRegistryContract(ChainId.ROPSTEN + ""), is(ROPSTEN));
    assertThat(resolveRegistryContract(ChainId.RINKEBY + ""), is(RINKEBY));
}
 
Example #7
Source File: ContractsTest.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
@Test(expected = EnsResolutionException.class)
public void testResolveRegistryContractInvalid() {
    resolveRegistryContract(ChainId.NONE + "");
}
 
Example #8
Source File: ContractsTest.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testResolveRegistryContract() {
    assertEquals(resolveRegistryContract(ChainId.MAINNET + ""), (MAINNET));
    assertEquals(resolveRegistryContract(ChainId.ROPSTEN + ""), (ROPSTEN));
    assertEquals(resolveRegistryContract(ChainId.RINKEBY + ""), (RINKEBY));
}
 
Example #9
Source File: ContractsTest.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testResolveRegistryContractInvalid() {
    assertThrows(
            EnsResolutionException.class, () -> resolveRegistryContract(ChainId.NONE + ""));
}