0

I have a Bitcoin wallet developed in Java/Spring MVC and supports account setup, connect with the blockchain and keep tracks of the updates such as the balance, transactions etc. The sample code provided,

public class WalletModel {

    // keep tracks of the updates in the wallet
    private void update(Wallet wallet) {

          this.balance = wallet.getBalance();

    this.address = wallet.currentReceiveAddress();

    transactions.addAll(wallet.getRecentTransactions(100, false));

    // find to most recent transaction
    this.transaction = Objects.isNull(transactions) ||
            transactions.isEmpty() ? "No transaction" : String.valueOf(transactions.get(0));
  }

public boolean setWallet(Wallet wallet) {

    try {

        wallet.addChangeEventListener(new WalletChangeEventListener() {
            @Override
            public void onWalletChanged(Wallet wallet) {
                update(wallet);
            }
        });
        update(wallet);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
     }
 }

The WalletManager code e.g,

public class WalletManager {

      public static WalletAppKit bitcoin;
      public static NetworkParameters networkParameters = 
 TestNet3Params.get();

public static WalletManager setupWallet(final String walletName) {

        logger.info("Setup Wallet");

        WalletManager walletManager = new WalletManager();
        walletManager.setupWalletKit(walletName);

        try {
            if (walletManager.bitcoin.isChainFileLocked()) {
                return walletManager;
            }
        } catch (IOException e) {
            e.printStackTrace();
            return walletManager;
        }

        walletManager.bitcoin.startAsync();
        return walletManager;
    }

private void setupWalletKit(final String walletId) {

        File directory = getWalletDirectory(walletId);

        // if the seed is not null, that means we are restoring from the backup
        bitcoin = new WalletAppKit(networkParameters, directory, WALLET_FILE_NAME) {

            @Override
            protected void onSetupCompleted() {

                // Don't make the user wait for confirmations
                // they're sending their own money anyway!!
                bitcoin.wallet().allowSpendingUnconfirmedTransactions();
                Wallet wallet = bitcoin.wallet();

                model.setWallet(wallet);
                setupCompletedListeners.forEach(listener -> listener.onSetupCompleted(wallet));
            }
        };

        // Now configure and start the appkit. This will take a second or two - we could show a temporary splash screen
        // or progress widget to keep the user engaged whilst we initialise, but we don't.
        if (networkParameters == RegTestParams.get()) {
            bitcoin.connectToLocalHost();   // You should run a regtest mode bitcoind locally.
        } else if (networkParameters == TestNet3Params.get()) {
            bitcoin.useTor();
        }

        bitcoin.setDownloadListener(model.getSyncProgressUpdater())
                .setBlockingStartup(false)
                .setUserAgent(APP_NAME, "1.0");
    }
}

How to write similar operations in the Ethereum with Java?

UPDATE

I use maven for the development and use EthereumJ dependency e.g;

       <dependency>
            <groupId>org.ethereum</groupId>
            <artifactId>ethereumj-core</artifactId>
            <version>1.5.0-RELEASE</version>
        </dependency>

This seems fine as there is no error in the POM file. When I tried to import in the source file, I get the RED errors,

enter image description here

I have tried with other version of the dependencies as well. What os the issue here?

| improve this question | | | | |
2

I think it be easier to use an api to monitor account details. For instance Amberdata.io has a way to get the details about an account that you are looking for. You can try it out here!

| improve this answer | | | | |
0

In order to acquire dependency by maven you should add this to your pom:

<repositories>
    <repository>
        <id>ethereum</id>
        <url>http://dl.bintray.com/ethereum/maven</url>
    </repository>
</repositories>

because artifacts were not published on the central http://maven.org/

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.