Bitcoinj
基於雲的應用程序的 BitCoinJ
我目前正在開發一個基於雲的項目,該項目將接受使用比特幣的付款。我打算使用 BitCoinJ 來處理付款。不幸的是,我能得到的唯一幫助來自 JavaWorld 展示,它似乎與目前程式碼不同步。您能否指點我一些更好/更新的幫助連結/材料。
bitcoinj 庫本身中有一些範例始終是最新的(因為它們是建構的一部分)。
Mike 編寫的命令行工具“WalletTool”對於錢包創建、發送、接收等基礎知識非常有用。
WalletAppKit kit=new WalletAppKit(MainNetParams.get(), new File("."), "mywalletfilename"); kit.setAutoSave(true); kit.startAsync(); kit.awaitRunning(); kit.wallet().addEventListener(new WalletListener());
而聽眾看起來像:
public class WalletListener extends AbstractWalletEventListener { public WalletListener() { } @Override public void onCoinsReceived(org.bitcoinj.core.Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) { System.out.println("-----> coins resceived: " + tx.getHashAsString()+" prevBalance = "+prevBalance.getValue()+" newBal="+newBalance.getValue()); System.out.println("received: " + tx.getValue(wallet)); } @Override public void onTransactionConfidenceChanged(org.bitcoinj.core.Wallet wallet, Transaction tx) { System.out.println("-----> confidence changed: " + tx.getHashAsString()); TransactionConfidence confidence = tx.getConfidence(); System.out.println("new block depth: " + confidence.getDepthInBlocks()); } @Override public void onCoinsSent(org.bitcoinj.core.Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) { System.out.println("coins sent"); } @Override public void onReorganize(org.bitcoinj.core.Wallet wallet) { } @Override public void onWalletChanged(org.bitcoinj.core.Wallet wallet) { } @Override public void onKeysAdded(List<ECKey> keys) { System.out.println("new key added"); } /*@Override public void onScriptsAdded(Wallet wallet, List<Script> scripts) { System.out.println("new script added"); }*/
}
應該足以接收 BTC ;) 不要忘記 TXConfidence 已更改,它告訴您 TX 確認計數已更改以及更改的內容… ;-)