当前位置: 首页>>代码示例>>Java>>正文


Java Coin.ZERO属性代码示例

本文整理汇总了Java中org.bitcoinj.core.Coin.ZERO属性的典型用法代码示例。如果您正苦于以下问题:Java Coin.ZERO属性的具体用法?Java Coin.ZERO怎么用?Java Coin.ZERO使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.bitcoinj.core.Coin的用法示例。


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

示例1: getBalance

/**
 * Returns the balance of this wallet as calculated by the provided balanceType.
 */
public Coin getBalance(BalanceType balanceType) {
    lock.lock();
    try {
        if (balanceType == BalanceType.AVAILABLE || balanceType == BalanceType.AVAILABLE_SPENDABLE) {
            List<TransactionOutput> candidates = calculateAllSpendCandidates(true, balanceType == BalanceType.AVAILABLE_SPENDABLE);
            CoinSelection selection = coinSelector.select(NetworkParameters.MAX_MONEY, candidates);
            return selection.valueGathered;
        } else if (balanceType == BalanceType.ESTIMATED || balanceType == BalanceType.ESTIMATED_SPENDABLE) {
            List<TransactionOutput> all = calculateAllSpendCandidates(false, balanceType == BalanceType.ESTIMATED_SPENDABLE);
            Coin value = Coin.ZERO;
            for (TransactionOutput out : all) value = value.add(out.getValue());
            return value;
        } else {
            throw new AssertionError("Unknown balance type");  // Unreachable.
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:22,代码来源:Wallet.java

示例2: getTotalReceived

/**
 * Returns the amount of bitcoin ever received via output. <b>This is not the balance!</b> If an output spends from a
 * transaction whose inputs are also to our wallet, the input amounts are deducted from the outputs contribution, with a minimum of zero
 * contribution. The idea behind this is we avoid double counting money sent to us.
 * @return the total amount of satoshis received, regardless of whether it was spent or not.
 */
public Coin getTotalReceived() {
    Coin total = Coin.ZERO;

    // Include outputs to us if they were not just change outputs, ie the inputs to us summed to less
    // than the outputs to us.
    for (Transaction tx: transactions.values()) {
        Coin txTotal = Coin.ZERO;
        for (TransactionOutput output : tx.getOutputs()) {
            if (output.isMine(this)) {
                txTotal = txTotal.add(output.getValue());
            }
        }
        for (TransactionInput in : tx.getInputs()) {
            TransactionOutput prevOut = in.getConnectedOutput();
            if (prevOut != null && prevOut.isMine(this)) {
                txTotal = txTotal.subtract(prevOut.getValue());
            }
        }
        if (txTotal.isPositive()) {
            total = total.add(txTotal);
        }
    }
    return total;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:30,代码来源:Wallet.java

示例3: getTotalSent

/**
 * Returns the amount of bitcoin ever sent via output. If an output is sent to our own wallet, because of change or
 * rotating keys or whatever, we do not count it. If the wallet was
 * involved in a shared transaction, i.e. there is some input to the transaction that we don't have the key for, then
 * we multiply the sum of the output values by the proportion of satoshi coming in to our inputs. Essentially we treat
 * inputs as pooling into the transaction, becoming fungible and being equally distributed to all outputs.
 * @return the total amount of satoshis sent by us
 */
public Coin getTotalSent() {
    Coin total = Coin.ZERO;

    for (Transaction tx: transactions.values()) {
        // Count spent outputs to only if they were not to us. This means we don't count change outputs.
        Coin txOutputTotal = Coin.ZERO;
        for (TransactionOutput out : tx.getOutputs()) {
            if (out.isMine(this) == false) {
                txOutputTotal = txOutputTotal.add(out.getValue());
            }
        }

        // Count the input values to us
        Coin txOwnedInputsTotal = Coin.ZERO;
        for (TransactionInput in : tx.getInputs()) {
            TransactionOutput prevOut = in.getConnectedOutput();
            if (prevOut != null && prevOut.isMine(this)) {
                txOwnedInputsTotal = txOwnedInputsTotal.add(prevOut.getValue());
            }
        }

        // If there is an input that isn't from us, i.e. this is a shared transaction
        Coin txInputsTotal = tx.getInputSum();
        if (txOwnedInputsTotal != txInputsTotal) {

            // multiply our output total by the appropriate proportion to account for the inputs that we don't own
            BigInteger txOutputTotalNum = new BigInteger(txOutputTotal.toString());
            txOutputTotalNum = txOutputTotalNum.multiply(new BigInteger(txOwnedInputsTotal.toString()));
            txOutputTotalNum = txOutputTotalNum.divide(new BigInteger(txInputsTotal.toString()));
            txOutputTotal = Coin.valueOf(txOutputTotalNum.longValue());
        }
        total = total.add(txOutputTotal);

    }
    return total;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:44,代码来源:Wallet.java

示例4: getAmount

public Coin getAmount() {
    Coin amount = Coin.ZERO;

    if (hasOutputs())
        for (final Output output : outputs)
            if (output.hasAmount())
                amount = amount.add(output.amount);

    if (amount.signum() != 0)
        return amount;
    else
        return null;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:13,代码来源:PaymentIntent.java

示例5: onStartCommand

@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
    if (intent != null) {
        log.info("service start command: " + intent + (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)
                ? " (alarm count: " + intent.getIntExtra(Intent.EXTRA_ALARM_COUNT, 0) + ")" : ""));

        final String action = intent.getAction();

        if (BlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) {
            notificationCount = 0;
            notificationAccumulatedAmount = Coin.ZERO;
            notificationAddresses.clear();

            nm.cancel(Constants.NOTIFICATION_ID_COINS_RECEIVED);
        } else if (BlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) {
            log.info("will remove blockchain on service shutdown");

            resetBlockchainOnShutdown = true;
            stopSelf();
        } else if (BlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) {
            final Sha256Hash hash = Sha256Hash
                    .wrap(intent.getByteArrayExtra(BlockchainService.ACTION_BROADCAST_TRANSACTION_HASH));
            final Transaction tx = application.getWallet().getTransaction(hash);

            if (peerGroup != null) {
                log.info("broadcasting transaction " + tx.getHashAsString());
                peerGroup.broadcastTransaction(tx);
            } else {
                log.info("peergroup not available, not broadcasting transaction " + tx.getHashAsString());
            }
        }
    } else {
        log.warn("service restart, although it was started as non-sticky");
    }

    return START_NOT_STICKY;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:37,代码来源:BlockchainServiceImpl.java

示例6: buildRevokeContract

/**
 * Revoke a contract sending back to provider the coin
 */
public static Transaction buildRevokeContract(final String providerAddress, final String userAddress, final TransactionOutput prevOut, NetworkParameters networkParameters) throws Exception {
	
	if (providerAddress == null) {
		
		throw new Exception("Provider address is null");
		
	}
	
	if (userAddress == null) {
		
		throw new Exception("User address is null");
		
	}
	
	Coin coinValue = prevOut.getValue().subtract(FEE);
	
	Coin totalCoinOut = Coin.ZERO;
	
	Coin coinDivided = Coin.valueOf(coinValue.getValue() / 2);
	
       final Transaction transaction = new Transaction(networkParameters);
       
       // provider output
       TransactionOutput outputToProvider = new TransactionOutput(networkParameters, transaction, coinDivided, Address.fromBase58(networkParameters, providerAddress));
       transaction.addOutput(outputToProvider);
       
       // user output
       TransactionOutput outputToUser = new TransactionOutput(networkParameters, transaction, coinDivided, Address.fromBase58(networkParameters, userAddress));
       transaction.addOutput(outputToUser);
       
       // add value
       totalCoinOut = totalCoinOut.add(coinValue);
       
       try {
		
		// Connect all input
       	transaction.addInput(prevOut).setScriptSig(ScriptBuilder.createInputScript(TransactionSignature.dummy()));
           	
       	return transaction;

       } catch (Exception ex) {

          throw new Exception("Exception while building revoke contract", ex);

       }

}
 
开发者ID:uniquid,项目名称:uniquid-utils,代码行数:50,代码来源:ContractUtils.java


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