本文整理汇总了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;
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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()));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}