Java Code Examples for org.bitcoinj.core.Address#toString()

The following examples show how to use org.bitcoinj.core.Address#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BsqFormatter.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns the base-58 encoded String representation of this
 * object, including version and checksum bytes.
 */
public String getBsqAddressStringFromAddress(Address address) {
    final String addressString = address.toString();
    if (useBsqAddressFormat)
        return prefix + addressString;
    else
        return addressString;

}
 
Example 2
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public String getWalletFriendlyAddress() {
    if (walletFriendlyAddress != null && !walletFriendlyAddress.isEmpty()) {
        CashAddressFactory cashAddressFactory = CashAddressFactory.create();
        Address cashAddress = cashAddressFactory.getFromBase58(params, walletFriendlyAddress);
        return cashAddress.toString();
    } else {
        return null;
    }
}
 
Example 3
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public String getWalletAddressForDeposit() {
    if (walletFriendlyAddress != null && !walletFriendlyAddress.isEmpty()) {
        CashAddressFactory cashAddressFactory = CashAddressFactory.create();
        Address cashAddress = cashAddressFactory.getFromBase58(params, walletFriendlyAddress);
        return cashAddress.toString();
    } else {
        return null;
    }
}
 
Example 4
Source File: BsqFormatter.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns the base-58 encoded String representation of this
 * object, including version and checksum bytes.
 */
public String getBsqAddressStringFromAddress(Address address) {
    final String addressString = address.toString();
    if (useBsqAddressFormat)
        return prefix + addressString;
    else
        return addressString;

}
 
Example 5
Source File: TradeWalletService.java    From bisq-core with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * The taker creates a dummy transaction to get the input(s) and optional change output for the amount and the takersAddress for that trade.
 * That will be used to send to the maker for creating the deposit transaction.
 *
 * @param inputAmount   Amount of takers input
 * @param txFee         Mining fee
 * @param takersAddress Address of taker
 * @return A data container holding the inputs, the output value and address
 * @throws TransactionVerificationException
 * @throws WalletException
 */
public InputsAndChangeOutput takerCreatesDepositsTxInputs(Coin inputAmount, Coin txFee, Address takersAddress, Address takersChangeAddress) throws
        TransactionVerificationException, WalletException {
    log.debug("takerCreatesDepositsTxInputs called");
    log.debug("inputAmount " + inputAmount.toFriendlyString());
    log.debug("txFee " + txFee.toFriendlyString());
    log.debug("takersAddress " + takersAddress.toString());

    // We add the mining fee 2 times to the deposit tx:
    // 1. Will be spent when publishing the deposit tx (paid by buyer)
    // 2. Will be added to the MS amount, so when publishing the payout tx the fee is already there and the outputs are not changed by fee reduction
    // The fee for the payout will be paid by the seller.

    /*
     The tx we create has that structure:

     IN[0]  any input > inputAmount (including tx fee) (unsigned)
     IN[1...n] optional inputs supported, but normally there is just 1 input (unsigned)
     OUT[0] dummyOutputAmount (inputAmount - tx fee)
     OUT[1] Optional Change = inputAmount - dummyOutputAmount - tx fee

     We are only interested in the inputs and the optional change output.
     */


    // inputAmount includes the tx fee. So we subtract the fee to get the dummyOutputAmount.
    Coin dummyOutputAmount = inputAmount.subtract(txFee);

    Transaction dummyTX = new Transaction(params);
    // The output is just used to get the right inputs and change outputs, so we use an anonymous ECKey, as it will never be used for anything.
    // We don't care about fee calculation differences between the real tx and that dummy tx as we use a static tx fee.
    TransactionOutput dummyOutput = new TransactionOutput(params, dummyTX, dummyOutputAmount, new ECKey().toAddress(params));
    dummyTX.addOutput(dummyOutput);

    // Find the needed inputs to pay the output, optionally add 1 change output.
    // Normally only 1 input and no change output is used, but we support multiple inputs and 1 change output.
    // Our spending transaction output is from the create offer fee payment.
    addAvailableInputsAndChangeOutputs(dummyTX, takersAddress, takersChangeAddress, txFee);

    // The completeTx() call signs the input, but we don't want to pass over signed tx inputs so we remove the signature
    WalletService.removeSignatures(dummyTX);

    WalletService.verifyTransaction(dummyTX);

    //WalletService.printTx("dummyTX", dummyTX);

    List<RawTransactionInput> rawTransactionInputList = dummyTX.getInputs().stream()
            .map(e -> {
                checkNotNull(e.getConnectedOutput(), "e.getConnectedOutput() must not be null");
                checkNotNull(e.getConnectedOutput().getParentTransaction(), "e.getConnectedOutput().getParentTransaction() must not be null");
                checkNotNull(e.getValue(), "e.getValue() must not be null");
                return getRawInputFromTransactionInput(e);
            })
            .collect(Collectors.toList());

    // We don't support more then 1 change outputs, so there are max. 2 outputs
    checkArgument(dummyTX.getOutputs().size() < 3);
    // Only interested in optional change output, the dummy output at index 0 is ignored (that's why we use index 1)
    TransactionOutput changeOutput = dummyTX.getOutputs().size() == 2 ? dummyTX.getOutputs().get(1) : null;
    long changeOutputValue = 0L;
    String changeOutputAddress = null;
    if (changeOutput != null) {
        changeOutputValue = changeOutput.getValue().getValue();
        Address addressFromP2PKHScript = changeOutput.getAddressFromP2PKHScript(params);
        checkNotNull(addressFromP2PKHScript, "changeOutput.getAddressFromP2PKHScript(params) must not be null");
        changeOutputAddress = addressFromP2PKHScript.toString();
    }

    return new InputsAndChangeOutput(new ArrayList<>(rawTransactionInputList), changeOutputValue, changeOutputAddress);
}
 
Example 6
Source File: HWWallet.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
protected Object[] getChallengeArguments(final boolean isTrezor, final NetworkParameters params) {
    final byte[] id = getPubKey().toAddress(params).getHash160();
    final Address addr = new Address(params, id);
    return new Object[]{ "login.get_trezor_challenge", addr.toString(), !isTrezor };
}
 
Example 7
Source File: SWWallet.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
public Object[] getChallengeArguments(final NetworkParameters params) {
    final Address addr = new Address(params, mRootKey.getIdentifier());
    return new Object[]{ "login.get_challenge", addr.toString() };
}