• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java WalletCoinsReceivedEventListener类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener的典型用法代码示例。如果您正苦于以下问题:Java WalletCoinsReceivedEventListener类的具体用法?Java WalletCoinsReceivedEventListener怎么用?Java WalletCoinsReceivedEventListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WalletCoinsReceivedEventListener类属于org.bitcoinj.wallet.listeners包,在下文中一共展示了WalletCoinsReceivedEventListener类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: queueOnCoinsReceived

import org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener; //导入依赖的package包/类
protected void queueOnCoinsReceived(final Transaction tx, final Coin balance, final Coin newBalance) {
    checkState(lock.isHeldByCurrentThread());
    for (final ListenerRegistration<WalletCoinsReceivedEventListener> registration : coinsReceivedListeners) {
        registration.executor.execute(new Runnable() {
            @Override
            public void run() {
                registration.listener.onCoinsReceived(Wallet.this, tx, balance, newBalance);
            }
        });
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:12,代码来源:Wallet.java


示例2: main

import org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    File file = new File(args[0]);
    Wallet wallet = Wallet.loadFromFile(file);
    System.out.println(wallet.toString());

    // Set up the components and link them together.
    final NetworkParameters params = TestNet3Params.get();
    BlockStore blockStore = new MemoryBlockStore(params);
    BlockChain chain = new BlockChain(params, wallet, blockStore);

    final PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.startAsync();

    wallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
        @Override
        public synchronized void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) {
            System.out.println("\nReceived tx " + tx.getHashAsString());
            System.out.println(tx.toString());
        }
    });

    // Now download and process the block chain.
    peerGroup.downloadBlockChain();
    peerGroup.stopAsync();
    wallet.saveToFile(file);
    System.out.println("\nDone!\n");
    System.out.println(wallet.toString());
}
 
开发者ID:HashEngineering,项目名称:dashj,代码行数:29,代码来源:RefreshWallet.java


示例3: addCoinsReceivedEventListener

import org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener; //导入依赖的package包/类
/**
 * Adds an event listener object called when coins are received.
 * The listener is executed by the given executor.
 */
public void addCoinsReceivedEventListener(Executor executor, WalletCoinsReceivedEventListener listener) {
    // This is thread safe, so we don't need to take the lock.
    coinsReceivedListeners.add(new ListenerRegistration<>(listener, executor));
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:9,代码来源:Wallet.java


示例4: addCoinsReceivedEventListener

import org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener; //导入依赖的package包/类
/**
 * Adds an event listener object called when coins are received.
 * The listener is executed by the given executor.
 */
public void addCoinsReceivedEventListener(Executor executor, WalletCoinsReceivedEventListener listener) {
    // This is thread safe, so we don't need to take the lock.
    coinsReceivedListeners.add(new ListenerRegistration<WalletCoinsReceivedEventListener>(listener, executor));
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:9,代码来源:Wallet.java


示例5: testAppearedAtChainHeightDepthAndWorkDone

import org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener; //导入依赖的package包/类
@Test
public void testAppearedAtChainHeightDepthAndWorkDone() throws Exception {
    // Test the TransactionConfidence appearedAtChainHeight, depth and workDone field are stored.

    BlockChain chain = new BlockChain(PARAMS, myWallet, new MemoryBlockStore(PARAMS));

    final ArrayList<Transaction> txns = new ArrayList<Transaction>(2);
    myWallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
        @Override
        public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            txns.add(tx);
        }
    });

    // Start by building two blocks on top of the genesis block.
    Block b1 = PARAMS.getGenesisBlock().createNextBlock(myAddress);
    BigInteger work1 = b1.getWork();
    assertTrue(work1.signum() > 0);

    Block b2 = b1.createNextBlock(myAddress);
    BigInteger work2 = b2.getWork();
    assertTrue(work2.signum() > 0);

    assertTrue(chain.add(b1));
    assertTrue(chain.add(b2));

    // We now have the following chain:
    //     genesis -> b1 -> b2

    // Check the transaction confidence levels are correct before wallet roundtrip.
    Threading.waitForUserCode();
    assertEquals(2, txns.size());

    TransactionConfidence confidence0 = txns.get(0).getConfidence();
    TransactionConfidence confidence1 = txns.get(1).getConfidence();

    assertEquals(1, confidence0.getAppearedAtChainHeight());
    assertEquals(2, confidence1.getAppearedAtChainHeight());

    assertEquals(2, confidence0.getDepthInBlocks());
    assertEquals(1, confidence1.getDepthInBlocks());

    // Roundtrip the wallet and check it has stored the depth and workDone.
    Wallet rebornWallet = roundTrip(myWallet);

    Set<Transaction> rebornTxns = rebornWallet.getTransactions(false);
    assertEquals(2, rebornTxns.size());

    // The transactions are not guaranteed to be in the same order so sort them to be in chain height order if required.
    Iterator<Transaction> it = rebornTxns.iterator();
    Transaction txA = it.next();
    Transaction txB = it.next();

    Transaction rebornTx0, rebornTx1;
     if (txA.getConfidence().getAppearedAtChainHeight() == 1) {
        rebornTx0 = txA;
        rebornTx1 = txB;
    } else {
        rebornTx0 = txB;
        rebornTx1 = txA;
    }

    TransactionConfidence rebornConfidence0 = rebornTx0.getConfidence();
    TransactionConfidence rebornConfidence1 = rebornTx1.getConfidence();

    assertEquals(1, rebornConfidence0.getAppearedAtChainHeight());
    assertEquals(2, rebornConfidence1.getAppearedAtChainHeight());

    assertEquals(2, rebornConfidence0.getDepthInBlocks());
    assertEquals(1, rebornConfidence1.getDepthInBlocks());
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:72,代码来源:WalletProtobufSerializerTest.java


示例6: main

import org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    // This line makes the log output more compact and easily read, especially when using the JDK log adapter.
    BriefLogFormatter.init();
    if (args.length < 1) {
        System.err.println("Usage: address-to-send-back-to [regtest|testnet]");
        return;
    }

    // Figure out which network we should connect to. Each one gets its own set of files.
    NetworkParameters params;
    String filePrefix;
    if (args.length > 1 && args[1].equals("testnet")) {
        params = TestNet3Params.get();
        filePrefix = "forwarding-service-testnet";
    } else if (args.length > 1 && args[1].equals("regtest")) {
        params = RegTestParams.get();
        filePrefix = "forwarding-service-regtest";
    } else {
        params = MainNetParams.get();
        filePrefix = "forwarding-service";
    }
    // Parse the address given as the first parameter.
    forwardingAddress = Address.fromBase58(params, args[0]);

    // Start up a basic app using a class that automates some boilerplate.
    kit = new WalletAppKit(params, new File("."), filePrefix);

    if (params == RegTestParams.get()) {
        // Regression test mode is designed for testing and development only, so there's no public network for it.
        // If you pick this mode, you're expected to be running a local "bitcoind -regtest" instance.
        kit.connectToLocalHost();
    }

    // Download the block chain and wait until it's done.
    kit.startAsync();
    kit.awaitRunning();

    // We want to know when we receive money.
    kit.wallet().addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
        @Override
        public void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) {
            // Runs in the dedicated "user thread" (see bitcoinj docs for more info on this).
            //
            // The transaction "tx" can either be pending, or included into a block (we didn't see the broadcast).
            Coin value = tx.getValueSentToMe(w);
            System.out.println("Received tx for " + value.toFriendlyString() + ": " + tx);
            System.out.println("Transaction will be forwarded after it confirms.");
            // Wait until it's made it into the block chain (may run immediately if it's already there).
            //
            // For this dummy app of course, we could just forward the unconfirmed transaction. If it were
            // to be double spent, no harm done. Wallet.allowSpendingUnconfirmedTransactions() would have to
            // be called in onSetupCompleted() above. But we don't do that here to demonstrate the more common
            // case of waiting for a block.
            Futures.addCallback(tx.getConfidence().getDepthFuture(1), new FutureCallback<TransactionConfidence>() {
                @Override
                public void onSuccess(TransactionConfidence result) {
                    forwardCoins(tx);
                }

                @Override
                public void onFailure(Throwable t) {
                    // This kind of future can't fail, just rethrow in case something weird happens.
                    throw new RuntimeException(t);
                }
            });
        }
    });

    Address sendToAddress = kit.wallet().currentReceiveKey().toAddress(params);
    System.out.println("Send coins to: " + sendToAddress);
    System.out.println("Waiting for coins to arrive. Press Ctrl-C to quit.");

    try {
        Thread.sleep(Long.MAX_VALUE);
    } catch (InterruptedException ignored) {}
}
 
开发者ID:bitcoinj,项目名称:bitcoinj,代码行数:77,代码来源:ForwardingService.java


示例7: testAppearedAtChainHeightDepthAndWorkDone

import org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener; //导入依赖的package包/类
@Test
public void testAppearedAtChainHeightDepthAndWorkDone() throws Exception {
    // Test the TransactionConfidence appearedAtChainHeight, depth and workDone field are stored.

    BlockChain chain = new BlockChain(PARAMS, myWallet, new MemoryBlockStore(PARAMS));

    final ArrayList<Transaction> txns = new ArrayList<>(2);
    myWallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
        @Override
        public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            txns.add(tx);
        }
    });

    // Start by building two blocks on top of the genesis block.
    Block b1 = PARAMS.getGenesisBlock().createNextBlock(myAddress);
    BigInteger work1 = b1.getWork();
    assertTrue(work1.signum() > 0);

    Block b2 = b1.createNextBlock(myAddress);
    BigInteger work2 = b2.getWork();
    assertTrue(work2.signum() > 0);

    assertTrue(chain.add(b1));
    assertTrue(chain.add(b2));

    // We now have the following chain:
    //     genesis -> b1 -> b2

    // Check the transaction confidence levels are correct before wallet roundtrip.
    Threading.waitForUserCode();
    assertEquals(2, txns.size());

    TransactionConfidence confidence0 = txns.get(0).getConfidence();
    TransactionConfidence confidence1 = txns.get(1).getConfidence();

    assertEquals(1, confidence0.getAppearedAtChainHeight());
    assertEquals(2, confidence1.getAppearedAtChainHeight());

    assertEquals(2, confidence0.getDepthInBlocks());
    assertEquals(1, confidence1.getDepthInBlocks());

    // Roundtrip the wallet and check it has stored the depth and workDone.
    Wallet rebornWallet = roundTrip(myWallet);

    Set<Transaction> rebornTxns = rebornWallet.getTransactions(false);
    assertEquals(2, rebornTxns.size());

    // The transactions are not guaranteed to be in the same order so sort them to be in chain height order if required.
    Iterator<Transaction> it = rebornTxns.iterator();
    Transaction txA = it.next();
    Transaction txB = it.next();

    Transaction rebornTx0, rebornTx1;
     if (txA.getConfidence().getAppearedAtChainHeight() == 1) {
        rebornTx0 = txA;
        rebornTx1 = txB;
    } else {
        rebornTx0 = txB;
        rebornTx1 = txA;
    }

    TransactionConfidence rebornConfidence0 = rebornTx0.getConfidence();
    TransactionConfidence rebornConfidence1 = rebornTx1.getConfidence();

    assertEquals(1, rebornConfidence0.getAppearedAtChainHeight());
    assertEquals(2, rebornConfidence1.getAppearedAtChainHeight());

    assertEquals(2, rebornConfidence0.getDepthInBlocks());
    assertEquals(1, rebornConfidence1.getDepthInBlocks());
}
 
开发者ID:bitcoinj,项目名称:bitcoinj,代码行数:72,代码来源:WalletProtobufSerializerTest.java


示例8: removeCoinsReceivedEventListener

import org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener; //导入依赖的package包/类
/**
 * Removes the given event listener object. Returns true if the listener was removed, false if that listener
 * was never added.
 */
public boolean removeCoinsReceivedEventListener(WalletCoinsReceivedEventListener listener) {
    return ListenerRegistration.removeFromList(listener, coinsReceivedListeners);
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:8,代码来源:Wallet.java



注:本文中的org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IQueryListener类代码示例发布时间:2022-05-22
下一篇:
Java XCallback类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap