コード例 #1
0
  public static Transaction createSignedTransaction(TradeSession ts, MbwManager mbwManager) {
    Preconditions.checkNotNull(ts.buyerAddress);

    // Create default wallet
    Wallet wallet = mbwManager.getRecordManager().getWallet(mbwManager.getWalletMode());

    // Get spendable outputs
    SpendableOutputs spendable =
        wallet.getLocalSpendableOutputs(mbwManager.getBlockChainAddressTracker());

    // Extract private key ring
    PrivateKeyRing keyRing = wallet.getPrivateKeyRing();

    // Create unsigned transaction
    UnsignedTransaction unsigned =
        createUnsignedTransaction(
            ts.satoshisFromSeller,
            ts.satoshisForBuyer,
            ts.buyerAddress,
            ts.feeAddress,
            mbwManager,
            spendable,
            keyRing,
            mbwManager.getNetwork());

    if (unsigned == null) {
      return null;
    }

    // Make signatures
    List<byte[]> signatures =
        StandardTransactionBuilder.generateSignatures(
            unsigned.getSignatureInfo(), keyRing, mbwManager.getRecordManager().getRandomSource());

    // Sign transaction
    Transaction tx = StandardTransactionBuilder.finalizeTransaction(unsigned, signatures);
    return tx;
  }
コード例 #2
0
  public static boolean canAffordTrade(TradeSession ts, MbwManager mbwManager) {
    // Create default wallet
    Wallet wallet = mbwManager.getRecordManager().getWallet(mbwManager.getWalletMode());

    // Get spendable outputs
    SpendableOutputs spendable =
        wallet.getLocalSpendableOutputs(mbwManager.getBlockChainAddressTracker());

    // Extract private key ring
    PrivateKeyRing keyRing = wallet.getPrivateKeyRing();

    Address nullAddress = Address.getNullAddress(mbwManager.getNetwork());

    return createUnsignedTransaction(
            ts.satoshisFromSeller,
            ts.satoshisForBuyer,
            nullAddress,
            nullAddress,
            mbwManager,
            spendable,
            keyRing,
            mbwManager.getNetwork())
        != null;
  }