Ejemplo n.º 1
0
  public CraftcoinAPI() {
    walletFile = new File("plugins/Craftcoinish/wallet.wallet");
    try {
      localWallet = Wallet.loadFromFile(walletFile);
      // Satoshis.log.info(localWallet.toString());
    } catch (IOException e) {
      localWallet = new Wallet(Craftcoinish.network);
    }
    try {
      localBlock =
          new SPVBlockStore(Craftcoinish.network, new File("plugins/Craftcoinish/h2.blockchain"));
      localChain = new BlockChain(Craftcoinish.network, localWallet, localBlock);
    } catch (BlockStoreException ex) {
      ex.printStackTrace();
    }
    localWallet.addEventListener(new CoinListener());
    localPeerGroup = new PeerGroup(Craftcoinish.network, localChain);
    localPeerGroup.setUserAgent("CraftcoinBukkit", "0.2");
    localPeerGroup.addWallet(localWallet);
    try {
      localPeerGroup.addAddress(
          new PeerAddress(InetAddress.getByName("smp1.spendlitecoins.com"), 12124));
      localPeerGroup.addAddress(new PeerAddress(InetAddress.getByName("207.68.215.202"), 12124));
    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
    }
    localPeerGroup.start();
    localPeerGroup.downloadBlockChain();
    try {
      StoredBlock b =
          localBlock.get(
              new Sha256Hash("64a9141746cbbe06c7e1a4b7f2abb968ccdeba66cd67c1add1091b29db00578e"));

      for (Transaction tx : localWallet.getTransactions(false, true)) {}

      System.out.println("Good TX's");
      for (Transaction tx : localWallet.getTransactionsByTime()) {}

    } catch (BlockStoreException e) {
      e.printStackTrace();
    }
  }