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


Java Transaction类代码示例

本文整理汇总了Java中org.nem.core.model.Transaction的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createTransaction

import org.nem.core.model.Transaction; //导入依赖的package包/类
/**
 * Creates the transaction.
 *
 * @param timeInstant
 *            the time instant
 * @param sender
 *            the sender
 * @param recipient
 *            the recipient
 * @param amount
 *            the amount
 * @param attachment
 *            the attachment
 * @return the transaction
 */
public static Transaction createTransaction(final TimeInstant timeInstant, final Account sender,
		final Account recipient, final long amount, final TransferTransactionAttachment attachment) {

	final TransferTransaction transaction = new TransferTransaction(timeInstant, // instant
			sender, recipient, // recipient
			Amount.fromMicroNem(amount), // amount in micro xem
			attachment); // attachment (message, mosaics)

	if (transaction.getFee() == null) {
		transaction.setFee(NemAppsLibGlobals.getGlobalTransactionFee().calculateMinimumFee(transaction));
	} else {
		transaction.setFee(Amount.fromNem(0));
	}

	transaction.setDeadline(timeInstant.addHours(23));
	return transaction;
}
 
开发者ID:NEMPH,项目名称:nem-apps-lib,代码行数:33,代码来源:BlockchainTransactionService.java

示例2: createMultisigTransaction

import org.nem.core.model.Transaction; //导入依赖的package包/类
/**
 * Creates the multisig transaction.
 *
 * @param timeInstant
 *            the time instant
 * @param sender
 *            the sender
 * @param recipient
 *            the recipient
 * @param amount
 *            the amount
 * @param transaction
 *            the transaction
 * @return the transaction
 */
public static Transaction createMultisigTransaction(final TimeInstant timeInstant, final Account sender,
		final Account recipient, final long amount, final Transaction transaction) {

	final MultisigTransaction multiSigTransaction = new MultisigTransaction(timeInstant, sender, transaction);
	multiSigTransaction.setDeadline(timeInstant.addHours(23));

	if (multiSigTransaction.getFee() == null) {
		TransactionFeeCalculator feeCalculator = NemAppsLibGlobals.getGlobalTransactionFee();
		multiSigTransaction.setFee(feeCalculator.calculateMinimumFee(multiSigTransaction));
	} else {
		multiSigTransaction.setFee(Amount.fromNem(0));
	}

	return multiSigTransaction;
}
 
开发者ID:NEMPH,项目名称:nem-apps-lib,代码行数:31,代码来源:BlockchainTransactionService.java

示例3: createMultisigSignatureTransaction

import org.nem.core.model.Transaction; //导入依赖的package包/类
/**
 * Creates the multisig signature transaction.
 *
 * @param timeInstant            the time instant
 * @param sender            the sender
 * @param multisig            the multisig
 * @param amount            the amount
 * @param hashTransaction the hash transaction
 * @return the transaction
 */
public static Transaction createMultisigSignatureTransaction(final TimeInstant timeInstant, final Account sender,
		final Account multisig, final long amount, final Hash hashTransaction) {

	final MultisigSignatureTransaction multiSigSignedTransaction = new MultisigSignatureTransaction(timeInstant,
			sender, multisig, hashTransaction);
	multiSigSignedTransaction.setDeadline(timeInstant.addHours(23));

	if (multiSigSignedTransaction.getFee() == null) {
		TransactionFeeCalculator feeCalculator = NemAppsLibGlobals.getGlobalTransactionFee();
		multiSigSignedTransaction.setFee(feeCalculator.calculateMinimumFee(multiSigSignedTransaction));
	} else {
		multiSigSignedTransaction.setFee(Amount.fromNem(0));
	}

	return multiSigSignedTransaction;
}
 
开发者ID:NEMPH,项目名称:nem-apps-lib,代码行数:27,代码来源:BlockchainTransactionService.java

示例4: calculateMinimumFee

import org.nem.core.model.Transaction; //导入依赖的package包/类
/**
 * Calculates the minimum fee for the specified transaction at the specified block height.
 *
 * @param transaction The transaction.
 * @return The minimum fee.
 */
@Override
public Amount calculateMinimumFee(final Transaction transaction) {
	switch (transaction.getType()) {
		case TransactionTypes.TRANSFER:
			return this.calculateMinimumFee((TransferTransaction)transaction);

		case TransactionTypes.MULTISIG_AGGREGATE_MODIFICATION:
			return calculateMinimumFee((MultisigAggregateModificationTransaction)transaction);

		case TransactionTypes.PROVISION_NAMESPACE:
		case TransactionTypes.MOSAIC_DEFINITION_CREATION:
		case TransactionTypes.MOSAIC_SUPPLY_CHANGE:
			return FEE_UNIT.multiply(10);
	}

	return FEE_UNIT.multiply(FEE_MULTIPLIER);
}
 
开发者ID:NEMPH,项目名称:nem-apps-lib,代码行数:24,代码来源:TransactionFeeCalculatorAfterForkForApp.java

示例5: validateCallsAllApplicableChildExtension

import org.nem.core.model.Transaction; //导入依赖的package包/类
@Test
public void validateCallsAllApplicableChildExtension() {
	// Arrange:
	final TransactionValidationExtension<Transaction> extension1 = createMockExtension(true);
	final TransactionValidationExtension<Transaction> extension2 = createMockExtension(false);
	final TransactionValidationExtension<Transaction> extension3 = createMockExtension(true);
	final AggregateTransactionValidationExtension<Transaction> aggregate =
			new AggregateTransactionValidationExtension<>(Arrays.asList(extension1, extension2, extension3));

	// Act:
	final Transaction transaction = RandomTransactionFactory.createTransfer();
	aggregate.validate(transaction);

	// Assert:
	Mockito.verify(extension1, Mockito.times(1)).validate(transaction);
	Mockito.verify(extension2, Mockito.never()).validate(Mockito.any());
	Mockito.verify(extension3, Mockito.times(1)).validate(transaction);
}
 
开发者ID:NemProject,项目名称:nem.core,代码行数:19,代码来源:AggregateTransactionValidationExtensionTest.java

示例6: serializeCallsApplicableChildExtension

import org.nem.core.model.Transaction; //导入依赖的package包/类
@Test
public void serializeCallsApplicableChildExtension() {
	// Arrange:
	final Serializer serializer = Mockito.mock(Serializer.class);
	final TransactionSerializationExtension<Object> extension = createMockExtension(true);
	final AggregateTransactionSerializationExtension<Object> aggregate =
			new AggregateTransactionSerializationExtension<>(Collections.singletonList(extension));

	// Act:
	final Transaction transaction = RandomTransactionFactory.createTransfer();
	aggregate.serialize(serializer, 7, transaction);

	// Assert:
	Mockito.verify(extension, Mockito.times(1)).isApplicable(7);
	Mockito.verify(extension, Mockito.times(1)).serialize(serializer, transaction);
}
 
开发者ID:NemProject,项目名称:nem.core,代码行数:17,代码来源:AggregateTransactionSerializationExtensionTest.java

示例7: serializeDoesNotCallNonApplicableChildExtension

import org.nem.core.model.Transaction; //导入依赖的package包/类
@Test
public void serializeDoesNotCallNonApplicableChildExtension() {
	// Arrange:
	final Serializer serializer = Mockito.mock(Serializer.class);
	final TransactionSerializationExtension<Object> extension = createMockExtension(false);
	final AggregateTransactionSerializationExtension<Object> aggregate =
			new AggregateTransactionSerializationExtension<>(Collections.singletonList(extension));

	// Act:
	final Transaction transaction = RandomTransactionFactory.createTransfer();
	aggregate.serialize(serializer, 7, transaction);

	// Assert:
	Mockito.verify(extension, Mockito.times(1)).isApplicable(7);
	Mockito.verify(extension, Mockito.never()).serialize(Mockito.any(), Mockito.any());
}
 
开发者ID:NemProject,项目名称:nem.core,代码行数:17,代码来源:AggregateTransactionSerializationExtensionTest.java

示例8: serializeCallsAllApplicableChildExtension

import org.nem.core.model.Transaction; //导入依赖的package包/类
@Test
public void serializeCallsAllApplicableChildExtension() {
	// Arrange:
	final Serializer serializer = Mockito.mock(Serializer.class);
	final TransactionSerializationExtension<Object> extension1 = createMockExtension(true);
	final TransactionSerializationExtension<Object> extension2 = createMockExtension(false);
	final TransactionSerializationExtension<Object> extension3 = createMockExtension(true);
	final AggregateTransactionSerializationExtension<Object> aggregate =
			new AggregateTransactionSerializationExtension<>(Arrays.asList(extension1, extension2, extension3));

	// Act:
	final Transaction transaction = RandomTransactionFactory.createTransfer();
	aggregate.serialize(serializer, 7, transaction);

	// Assert:
	Mockito.verify(extension1, Mockito.times(1)).serialize(serializer, transaction);
	Mockito.verify(extension2, Mockito.never()).serialize(Mockito.any(), Mockito.any());
	Mockito.verify(extension3, Mockito.times(1)).serialize(serializer, transaction);
}
 
开发者ID:NemProject,项目名称:nem.core,代码行数:20,代码来源:AggregateTransactionSerializationExtensionTest.java

示例9: deserializeCallsApplicableChildExtension

import org.nem.core.model.Transaction; //导入依赖的package包/类
@Test
public void deserializeCallsApplicableChildExtension() {
	// Arrange:
	final Deserializer deserializer = Mockito.mock(Deserializer.class);
	final TransactionSerializationExtension<Object> extension = createMockExtension(true);
	final AggregateTransactionSerializationExtension<Object> aggregate =
			new AggregateTransactionSerializationExtension<>(Collections.singletonList(extension));

	// Act:
	final Transaction transaction = RandomTransactionFactory.createTransfer();
	aggregate.deserialize(deserializer, 8, transaction);

	// Assert:
	Mockito.verify(extension, Mockito.times(1)).isApplicable(8);
	Mockito.verify(extension, Mockito.times(1)).deserialize(deserializer, transaction);
}
 
开发者ID:NemProject,项目名称:nem.core,代码行数:17,代码来源:AggregateTransactionSerializationExtensionTest.java

示例10: deserializeDoesNotCallNonApplicableChildExtension

import org.nem.core.model.Transaction; //导入依赖的package包/类
@Test
public void deserializeDoesNotCallNonApplicableChildExtension() {
	// Arrange:
	final Deserializer deserializer = Mockito.mock(Deserializer.class);
	final TransactionSerializationExtension<Object> extension = createMockExtension(false);
	final AggregateTransactionSerializationExtension<Object> aggregate =
			new AggregateTransactionSerializationExtension<>(Collections.singletonList(extension));

	// Act:
	final Transaction transaction = RandomTransactionFactory.createTransfer();
	aggregate.deserialize(deserializer, 8, transaction);

	// Assert:
	Mockito.verify(extension, Mockito.times(1)).isApplicable(8);
	Mockito.verify(extension, Mockito.never()).deserialize(Mockito.any(), Mockito.any());
}
 
开发者ID:NemProject,项目名称:nem.core,代码行数:17,代码来源:AggregateTransactionSerializationExtensionTest.java

示例11: deserializeCallsAllApplicableChildExtension

import org.nem.core.model.Transaction; //导入依赖的package包/类
@Test
public void deserializeCallsAllApplicableChildExtension() {
	// Arrange:
	final Deserializer deserializer = Mockito.mock(Deserializer.class);
	final TransactionSerializationExtension<Object> extension1 = createMockExtension(true);
	final TransactionSerializationExtension<Object> extension2 = createMockExtension(false);
	final TransactionSerializationExtension<Object> extension3 = createMockExtension(true);
	final AggregateTransactionSerializationExtension<Object> aggregate =
			new AggregateTransactionSerializationExtension<>(Arrays.asList(extension1, extension2, extension3));

	// Act:
	final Transaction transaction = RandomTransactionFactory.createTransfer();
	aggregate.deserialize(deserializer, 8, transaction);

	// Assert:
	Mockito.verify(extension1, Mockito.times(1)).deserialize(deserializer, transaction);
	Mockito.verify(extension2, Mockito.never()).deserialize(Mockito.any(), Mockito.any());
	Mockito.verify(extension3, Mockito.times(1)).deserialize(deserializer, transaction);
}
 
开发者ID:NemProject,项目名称:nem.core,代码行数:20,代码来源:AggregateTransactionSerializationExtensionTest.java

示例12: isFeeValid

import org.nem.core.model.Transaction; //导入依赖的package包/类
@Override
public boolean isFeeValid(Transaction transaction, BlockHeight blockHeight) {
	final Amount minimumFee = this.calculateMinimumFee(transaction);
	final Amount maxCacheFee = Amount.fromNem(1000); // 1000 xem is the maximum fee that helps push a transaction into the cache
	switch (transaction.getType()) {
		case TransactionTypes.MULTISIG_SIGNATURE:
			// minimumFee <= multisig signatures fee <= 1000
			// reason: during spam attack cosignatories must be able to get their signature into the cache.
			//         it is limited in order for the last cosignatory not to be able to drain the multisig account
			return 0 <= transaction.getFee().compareTo(minimumFee) && 0 >= transaction.getFee().compareTo(maxCacheFee);
	}

	return transaction.getFee().compareTo(minimumFee) >= 0;
}
 
开发者ID:NEMPH,项目名称:nem-apps-lib,代码行数:15,代码来源:TransactionFeeCalculatorAfterForkForApp.java

示例13: postTransactionAnnounce

import org.nem.core.model.Transaction; //导入依赖的package包/类
public TransactionResult postTransactionAnnounce(Account sender,
                                                Supplier<? extends Transaction> transactionFactory,
                                                Function<Deserializer, TransactionResult> resultHandler) {
    final Transaction transaction = transactionFactory.get();

    final byte[] data = BinarySerializer.serializeToBytes(transaction.asNonVerifiable());
    final RequestAnnounce request = new RequestAnnounce(data, transaction.getSignature().getBytes());

    final CompletableFuture<Deserializer> future = getConnector().postAsync(
            getMijinNodeEndpoint(),
            NisApiId.NIS_REST_TRANSACTION_ANNOUNCE,
            new HttpJsonPostRequest(request));

    MijinResult<TransactionResult> result = new MijinResult<>();

    future.thenAccept(d -> {
        result.setRaw(resultHandler.apply(d));
    }).exceptionally(e -> {
        log.warn(String.format("account %s transaction(type: %d) failed, reason: %s",
                sender.getAddress(),
                transaction.getType(),
                e.getMessage()), e);

        return null;
    }).join();

    return result.getRaw();
}
 
开发者ID:sjitech,项目名称:mijin-java-sample,代码行数:29,代码来源:MijinUtil.java

示例14: UnconfirmedTransactionMetaDataPairTest

import org.nem.core.model.Transaction; //导入依赖的package包/类
public UnconfirmedTransactionMetaDataPairTest() {
	super(
			account -> {
				final Transaction transfer = RandomTransactionFactory.createTransfer(account);
				transfer.sign();
				return transfer;
			},
			id -> new UnconfirmedTransactionMetaData(Hash.fromHexString(Integer.toHexString(id))),
			UnconfirmedTransactionMetaDataPair::new,
			UnconfirmedTransactionMetaDataPair::new,
			transaction -> transaction.getSigner().getAddress(),
			metaData -> Integer.parseInt(metaData.getInnerTransactionHash().toString(), 16));
}
 
开发者ID:NemProject,项目名称:nem.core,代码行数:14,代码来源:UnconfirmedTransactionMetaDataPairTest.java

示例15: TransactionMetaDataPairTest

import org.nem.core.model.Transaction; //导入依赖的package包/类
public TransactionMetaDataPairTest() {
	super(
			account -> {
				final Transaction transfer = RandomTransactionFactory.createTransfer(account);
				transfer.sign();
				return transfer;
			},
			id -> new TransactionMetaData(BlockHeight.ONE, (long)id, Hash.ZERO),
			TransactionMetaDataPair::new,
			TransactionMetaDataPair::new,
			transaction -> transaction.getSigner().getAddress(),
			metaData -> metaData.getId().intValue());
}
 
开发者ID:NemProject,项目名称:nem.core,代码行数:14,代码来源:TransactionMetaDataPairTest.java


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