Java Code Examples for org.bitcoinj.core.Coin#signum()

The following examples show how to use org.bitcoinj.core.Coin#signum() . 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: BitcoinURI.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Simple Bitcoin URI builder using known good fields.
 *
 * @param params  The network parameters that determine which network the URI
 *                is for.
 * @param address The Bitcoin address
 * @param amount  The amount
 * @param label   A label
 * @param message A message
 * @return A String containing the Bitcoin URI
 */
public static String convertToBitcoinURI(NetworkParameters params,
                                         String address, @Nullable Coin amount,
                                         @Nullable String label, @Nullable String message) {
    checkNotNull(params);
    checkNotNull(address);
    if (amount != null && amount.signum() < 0) {
        throw new IllegalArgumentException("Coin must be positive");
    }

    StringBuilder builder = new StringBuilder();
    String scheme = params.getUriScheme();
    builder.append(scheme).append(":").append(address);

    boolean questionMarkHasBeenOutput = false;

    if (amount != null) {
        builder.append(QUESTION_MARK_SEPARATOR).append(FIELD_AMOUNT).append("=");
        builder.append(amount.toPlainString());
        questionMarkHasBeenOutput = true;
    }

    if (label != null && !"".equals(label)) {
        if (questionMarkHasBeenOutput) {
            builder.append(AMPERSAND_SEPARATOR);
        } else {
            builder.append(QUESTION_MARK_SEPARATOR);
            questionMarkHasBeenOutput = true;
        }
        builder.append(FIELD_LABEL).append("=").append(encodeURLString(label));
    }

    if (message != null && !"".equals(message)) {
        if (questionMarkHasBeenOutput) {
            builder.append(AMPERSAND_SEPARATOR);
        } else {
            builder.append(QUESTION_MARK_SEPARATOR);
        }
        builder.append(FIELD_MESSAGE).append("=").append(encodeURLString(message));
    }

    return builder.toString();
}
 
Example 2
Source File: BitcoinURI.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Simple Bitcoin URI builder using known good fields.
 *
 * @param params The network parameters that determine which network the URI
 * is for.
 * @param address The Bitcoin address
 * @param amount The amount
 * @param label A label
 * @param message A message
 * @return A String containing the Bitcoin URI
 */
public static String convertToBitcoinURI(NetworkParameters params,
                                         String address, @Nullable Coin amount,
                                         @Nullable String label, @Nullable String message) {
    checkNotNull(params);
    checkNotNull(address);
    if (amount != null && amount.signum() < 0) {
        throw new IllegalArgumentException("Coin must be positive");
    }
    
    StringBuilder builder = new StringBuilder();
    String scheme = params.getUriScheme();
    builder.append(scheme).append(":").append(address);
    
    boolean questionMarkHasBeenOutput = false;
    
    if (amount != null) {
        builder.append(QUESTION_MARK_SEPARATOR).append(FIELD_AMOUNT).append("=");
        builder.append(amount.toPlainString());
        questionMarkHasBeenOutput = true;
    }
    
    if (label != null && !"".equals(label)) {
        if (questionMarkHasBeenOutput) {
            builder.append(AMPERSAND_SEPARATOR);
        } else {
            builder.append(QUESTION_MARK_SEPARATOR);                
            questionMarkHasBeenOutput = true;
        }
        builder.append(FIELD_LABEL).append("=").append(encodeURLString(label));
    }
    
    if (message != null && !"".equals(message)) {
        if (questionMarkHasBeenOutput) {
            builder.append(AMPERSAND_SEPARATOR);
        } else {
            builder.append(QUESTION_MARK_SEPARATOR);
        }
        builder.append(FIELD_MESSAGE).append("=").append(encodeURLString(message));
    }
    
    return builder.toString();
}
 
Example 3
Source File: BitcoinURI.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Simple Bitcoin URI builder using known good fields.
 *
 * @param params The network parameters that determine which network the URI
 * is for.
 * @param address The Bitcoin address
 * @param amount The amount
 * @param label A label
 * @param message A message
 * @return A String containing the Bitcoin URI
 */
public static String convertToBitcoinURI(NetworkParameters params,
                                         String address, @Nullable Coin amount,
                                         @Nullable String label, @Nullable String message) {
    checkNotNull(params);
    checkNotNull(address);
    if (amount != null && amount.signum() < 0) {
        throw new IllegalArgumentException("Coin must be positive");
    }
    
    StringBuilder builder = new StringBuilder();
    String scheme = params.getUriScheme();
    builder.append(scheme).append(":").append(address);
    
    boolean questionMarkHasBeenOutput = false;
    
    if (amount != null) {
        builder.append(QUESTION_MARK_SEPARATOR).append(FIELD_AMOUNT).append("=");
        builder.append(amount.toPlainString());
        questionMarkHasBeenOutput = true;
    }
    
    if (label != null && !"".equals(label)) {
        if (questionMarkHasBeenOutput) {
            builder.append(AMPERSAND_SEPARATOR);
        } else {
            builder.append(QUESTION_MARK_SEPARATOR);                
            questionMarkHasBeenOutput = true;
        }
        builder.append(FIELD_LABEL).append("=").append(encodeURLString(label));
    }
    
    if (message != null && !"".equals(message)) {
        if (questionMarkHasBeenOutput) {
            builder.append(AMPERSAND_SEPARATOR);
        } else {
            builder.append(QUESTION_MARK_SEPARATOR);
        }
        builder.append(FIELD_MESSAGE).append("=").append(encodeURLString(message));
    }
    
    return builder.toString();
}