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


Java Convert.safeAdd方法代码示例

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


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

示例1: applyUnconfirmed

import nxt.util.Convert; //导入方法依赖的package包/类
final boolean applyUnconfirmed(Transaction transaction, Account senderAccount) {
    long totalAmountNQT = Convert.safeAdd(transaction.getAmountNQT(), transaction.getFeeNQT());
    if (transaction.getReferencedTransactionFullHash() != null
            && transaction.getTimestamp() > Constants.REFERENCED_TRANSACTION_FULL_HASH_BLOCK_TIMESTAMP) {
        totalAmountNQT = Convert.safeAdd(totalAmountNQT, Constants.UNCONFIRMED_POOL_DEPOSIT_NQT);
    }
    if (senderAccount.getUnconfirmedBalanceNQT() < totalAmountNQT) {
        return false;
    }
    senderAccount.addToUnconfirmedBalanceNQT(-totalAmountNQT);
    if (!applyAttachmentUnconfirmed(transaction, senderAccount)) {
        senderAccount.addToUnconfirmedBalanceNQT(totalAmountNQT);
        return false;
    }
    return true;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:17,代码来源:TransactionType.java

示例2: applyAttachment

import nxt.util.Convert; //导入方法依赖的package包/类
@Override
final void applyAttachment(Transaction transaction, Account senderAccount, Account recipientAccount) {
	Attachment.AdvancedPaymentEscrowCreation attachment = (Attachment.AdvancedPaymentEscrowCreation) transaction.getAttachment();
	Long totalAmountNQT = Convert.safeAdd(attachment.getAmountNQT(), attachment.getTotalSigners() * Constants.ONE_NXT);
	senderAccount.addToBalanceNQT(-totalAmountNQT);
	Collection<Long> signers = attachment.getSigners();
	for(Long signer : signers) {
		Account.addOrGetAccount(signer).addToBalanceAndUnconfirmedBalanceNQT(Constants.ONE_NXT);
	}
	Escrow.addEscrowTransaction(senderAccount,
								recipientAccount,
								transaction.getId(),
								attachment.getAmountNQT(),
								attachment.getRequiredSigners(),
								attachment.getSigners(),
								transaction.getTimestamp() + attachment.getDeadline(),
								attachment.getDeadlineAction());
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:19,代码来源:TransactionType.java

示例3: processRequest

import nxt.util.Convert; //导入方法依赖的package包/类
@Override
JSONStreamAware processRequest(HttpServletRequest req) throws NxtException {

    Asset asset = ParameterParser.getAsset(req);
    long priceNQT = ParameterParser.getPriceNQT(req);
    long quantityQNT = ParameterParser.getQuantityQNT(req);
    long feeNQT = ParameterParser.getFeeNQT(req);
    Account account = ParameterParser.getSenderAccount(req);

    try {
        if (Convert.safeAdd(feeNQT, Convert.safeMultiply(priceNQT, quantityQNT)) > account.getUnconfirmedBalanceNQT()) {
            return NOT_ENOUGH_FUNDS;
        }
    } catch (ArithmeticException e) {
        return NOT_ENOUGH_FUNDS;
    }

    Attachment attachment = new Attachment.ColoredCoinsBidOrderPlacement(asset.getId(), quantityQNT, priceNQT);
    return createTransaction(req, account, attachment);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:21,代码来源:PlaceBidOrder.java

示例4: addToAssetBalanceQNT

import nxt.util.Convert; //导入方法依赖的package包/类
void addToAssetBalanceQNT(long assetId, long quantityQNT) {
    if (quantityQNT == 0) {
        return;
    }
    AccountAsset accountAsset;
    accountAsset = accountAssetTable.get(accountAssetDbKeyFactory.newKey(this.id, assetId));
    long assetBalance = accountAsset == null ? 0 : accountAsset.quantityQNT;
    assetBalance = Convert.safeAdd(assetBalance, quantityQNT);
    if (accountAsset == null) {
        accountAsset = new AccountAsset(this.id, assetId, assetBalance, 0);
    } else {
        accountAsset.quantityQNT = assetBalance;
    }
    accountAsset.save();
    listeners.notify(this, Event.ASSET_BALANCE);
    assetListeners.notify(accountAsset, Event.ASSET_BALANCE);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:18,代码来源:Account.java

示例5: addToUnconfirmedAssetBalanceQNT

import nxt.util.Convert; //导入方法依赖的package包/类
void addToUnconfirmedAssetBalanceQNT(long assetId, long quantityQNT) {
    if (quantityQNT == 0) {
        return;
    }
    AccountAsset accountAsset;
    accountAsset = accountAssetTable.get(accountAssetDbKeyFactory.newKey(this.id, assetId));
    long unconfirmedAssetBalance = accountAsset == null ? 0 : accountAsset.unconfirmedQuantityQNT;
    unconfirmedAssetBalance = Convert.safeAdd(unconfirmedAssetBalance, quantityQNT);
    if (accountAsset == null) {
        accountAsset = new AccountAsset(this.id, assetId, 0, unconfirmedAssetBalance);
    } else {
        accountAsset.unconfirmedQuantityQNT = unconfirmedAssetBalance;
    }
    accountAsset.save();
    listeners.notify(this, Event.UNCONFIRMED_ASSET_BALANCE);
    assetListeners.notify(accountAsset, Event.UNCONFIRMED_ASSET_BALANCE);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:18,代码来源:Account.java

示例6: addToAssetAndUnconfirmedAssetBalanceQNT

import nxt.util.Convert; //导入方法依赖的package包/类
void addToAssetAndUnconfirmedAssetBalanceQNT(long assetId, long quantityQNT) {
    if (quantityQNT == 0) {
        return;
    }
    AccountAsset accountAsset;
    accountAsset = accountAssetTable.get(accountAssetDbKeyFactory.newKey(this.id, assetId));
    long assetBalance = accountAsset == null ? 0 : accountAsset.quantityQNT;
    assetBalance = Convert.safeAdd(assetBalance, quantityQNT);
    long unconfirmedAssetBalance = accountAsset == null ? 0 : accountAsset.unconfirmedQuantityQNT;
    unconfirmedAssetBalance = Convert.safeAdd(unconfirmedAssetBalance, quantityQNT);
    if (accountAsset == null) {
        accountAsset = new AccountAsset(this.id, assetId, assetBalance, unconfirmedAssetBalance);
    } else {
        accountAsset.quantityQNT = assetBalance;
        accountAsset.unconfirmedQuantityQNT = unconfirmedAssetBalance;
    }
    accountAsset.save();
    listeners.notify(this, Event.ASSET_BALANCE);
    listeners.notify(this, Event.UNCONFIRMED_ASSET_BALANCE);
    assetListeners.notify(accountAsset, Event.ASSET_BALANCE);
    assetListeners.notify(accountAsset, Event.UNCONFIRMED_ASSET_BALANCE);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:23,代码来源:Account.java

示例7: applyAttachmentUnconfirmed

import nxt.util.Convert; //导入方法依赖的package包/类
@Override
final boolean applyAttachmentUnconfirmed(Transaction transaction, Account senderAccount) {
	Attachment.AdvancedPaymentEscrowCreation attachment = (Attachment.AdvancedPaymentEscrowCreation) transaction.getAttachment();
	Long totalAmountNQT = Convert.safeAdd(attachment.getAmountNQT(), attachment.getTotalSigners() * Constants.ONE_NXT);
	if(senderAccount.getUnconfirmedBalanceNQT() < totalAmountNQT.longValue()) {
		return false;
	}
	senderAccount.addToUnconfirmedBalanceNQT(-totalAmountNQT);
	return true;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:11,代码来源:TransactionType.java

示例8: minimumFeeNQT

import nxt.util.Convert; //导入方法依赖的package包/类
long minimumFeeNQT(int height, int appendagesSize) {
    if (height < BASELINE_FEE_HEIGHT) {
        return 0; // No need to validate fees before baseline block
    }
    Fee fee;
    if (height >= NEXT_FEE_HEIGHT) {
        fee = getNextFee();
    } else {
        fee = getBaselineFee();
    }
    return Convert.safeAdd(fee.getConstantFee(), Convert.safeMultiply(appendagesSize, fee.getAppendagesFee()));
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:13,代码来源:TransactionType.java

示例9: addToBalanceNQT

import nxt.util.Convert; //导入方法依赖的package包/类
void addToBalanceNQT(long amountNQT) {
    if (amountNQT == 0) {
        return;
    }
    this.balanceNQT = Convert.safeAdd(this.balanceNQT, amountNQT);
    checkBalance(this.id, this.balanceNQT, this.unconfirmedBalanceNQT);
    accountTable.insert(this);
    listeners.notify(this, Event.BALANCE);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:10,代码来源:Account.java

示例10: addToUnconfirmedBalanceNQT

import nxt.util.Convert; //导入方法依赖的package包/类
void addToUnconfirmedBalanceNQT(long amountNQT) {
    if (amountNQT == 0) {
        return;
    }
    this.unconfirmedBalanceNQT = Convert.safeAdd(this.unconfirmedBalanceNQT, amountNQT);
    checkBalance(this.id, this.balanceNQT, this.unconfirmedBalanceNQT);
    accountTable.insert(this);
    listeners.notify(this, Event.UNCONFIRMED_BALANCE);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:10,代码来源:Account.java

示例11: addToBalanceAndUnconfirmedBalanceNQT

import nxt.util.Convert; //导入方法依赖的package包/类
void addToBalanceAndUnconfirmedBalanceNQT(long amountNQT) {
    if (amountNQT == 0) {
        return;
    }
    this.balanceNQT = Convert.safeAdd(this.balanceNQT, amountNQT);
    this.unconfirmedBalanceNQT = Convert.safeAdd(this.unconfirmedBalanceNQT, amountNQT);
    checkBalance(this.id, this.balanceNQT, this.unconfirmedBalanceNQT);
    accountTable.insert(this);
    listeners.notify(this, Event.BALANCE);
    listeners.notify(this, Event.UNCONFIRMED_BALANCE);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:12,代码来源:Account.java

示例12: addToForgedBalanceNQT

import nxt.util.Convert; //导入方法依赖的package包/类
void addToForgedBalanceNQT(long amountNQT) {
    if (amountNQT == 0) {
        return;
    }
    this.forgedBalanceNQT = Convert.safeAdd(this.forgedBalanceNQT, amountNQT);
    accountTable.insert(this);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:8,代码来源:Account.java

示例13: applyUnconfirmed

import nxt.util.Convert; //导入方法依赖的package包/类
private boolean applyUnconfirmed() {
	Account sender = Account.getAccount(senderId);
	long totalAmountNQT = Convert.safeAdd(amountNQT, getFee());
	
	if(sender.getUnconfirmedBalanceNQT() < totalAmountNQT) {
		return false;
	}
	
	sender.addToUnconfirmedBalanceNQT(-totalAmountNQT);
	
	return true;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:13,代码来源:Subscription.java

示例14: apply

import nxt.util.Convert; //导入方法依赖的package包/类
private void apply(Block block) {
	Account sender = Account.getAccount(senderId);
	Account recipient = Account.getAccount(recipientId);
	
	long totalAmountNQT = Convert.safeAdd(amountNQT, getFee());
	
	sender.addToBalanceNQT(-totalAmountNQT);
	recipient.addToBalanceAndUnconfirmedBalanceNQT(amountNQT);
	
	Attachment.AbstractAttachment attachment = new Attachment.AdvancedPaymentSubscriptionPayment(id);
	TransactionImpl.BuilderImpl builder = new TransactionImpl.BuilderImpl((byte) 1,
																  sender.getPublicKey(), amountNQT,
																  getFee(),
																  timeNext, (short)1440, attachment);
	
	try {
		builder.senderId(senderId)
		   .recipientId(recipientId)
		   .blockId(block.getId())
		   .height(block.getHeight())
		   .blockTimestamp(block.getTimestamp())
		   .ecBlockHeight(0)
		   .ecBlockId(0L);
		TransactionImpl transaction = builder.build();
		if(!TransactionDb.hasTransaction(transaction.getId())) {
			paymentTransactions.add(transaction);
		}
	} catch (NotValidException e) {
		throw new RuntimeException("Failed to build subscription payment transaction");
	}
	
	timeNext += frequency;
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:34,代码来源:Subscription.java

示例15: undoAttachmentUnconfirmed

import nxt.util.Convert; //导入方法依赖的package包/类
@Override
final void undoAttachmentUnconfirmed(Transaction transaction, Account senderAccount) {
	Attachment.AdvancedPaymentEscrowCreation attachment = (Attachment.AdvancedPaymentEscrowCreation) transaction.getAttachment();
	Long totalAmountNQT = Convert.safeAdd(attachment.getAmountNQT(), attachment.getTotalSigners() * Constants.ONE_NXT);
	senderAccount.addToUnconfirmedBalanceNQT(totalAmountNQT);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:7,代码来源:TransactionType.java


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