本文整理汇总了Java中org.nem.core.model.TransferTransaction类的典型用法代码示例。如果您正苦于以下问题:Java TransferTransaction类的具体用法?Java TransferTransaction怎么用?Java TransferTransaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransferTransaction类属于org.nem.core.model包,在下文中一共展示了TransferTransaction类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTransaction
import org.nem.core.model.TransferTransaction; //导入依赖的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;
}
示例2: calculateMinimumFee
import org.nem.core.model.TransferTransaction; //导入依赖的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);
}
示例3: testMulitSigTransactionBuilderSimple
import org.nem.core.model.TransferTransaction; //导入依赖的package包/类
/**
* Test cb build and send transaction.
*/
@Test
public void testMulitSigTransactionBuilderSimple() {
// Build a transaction and send it.
try {
TransferTransaction trans = TransferTransactionBuilder
.sender(new Account(new KeyPair(PrivateKey
.fromHexString("d8b89745a3006e293d16b8a16294582734c6b20ca5feb6e7ca25fec9295b1145")))) // multisig
.recipient(new Account(new KeyPair(PublicKey
.fromHexString("a70bf981bdb62c5d4e44b25ca2629108a394c7aaf18eec50dc405b1e44d712d4"))))
.fee(Amount.ZERO).amount(Amount.fromMicroNem(0l)).buildTransaction();
MultisigTransaction multiSigTrans = MultisigTransactionBuilder.sender(this.senderPrivateAccount)
.otherTransaction(trans).buildMultisigTransaction();
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: testMulitSigTransactionBuilder
import org.nem.core.model.TransferTransaction; //导入依赖的package包/类
/**
* Test cb build and send file transaction.
*/
@Test
public void testMulitSigTransactionBuilder() {
SecureMessage message = null;
try {
message = SecureMessage.fromDecodedPayload(this.senderPrivateAccount, this.recipientPublicAccount,
sampleMsg.getBytes());
} catch (Exception e1) {
e1.printStackTrace();
}
// Build a transaction and send it.
try {
TransferTransaction trans = TransferTransactionBuilder
.sender(new Account(new KeyPair(PrivateKey
.fromHexString("d8b89745a3006e293d16b8a16294582734c6b20ca5feb6e7ca25fec9295b1145")))) // multisig
.recipient(this.recipientPublicAccount).fee(Amount.ZERO).amount(Amount.fromMicroNem(0l)).version(0)
.buildTransaction();
NemAnnounceResult multisigTrans = MultisigTransactionBuilder.sender(this.senderPrivateAccount)
.otherTransaction(trans).buildAndSendMultisigTransaction();
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: sendTransferTransaction
import org.nem.core.model.TransferTransaction; //导入依赖的package包/类
/**
* Send transfer transaction.
*
* @param transaction
* the transaction
* @return the nem announce result
*/
public static NemAnnounceResult sendTransferTransaction(TransferTransaction transaction) {
final byte[] data = BinarySerializer.serializeToBytes(transaction.asNonVerifiable());
final RequestAnnounce request = new RequestAnnounce(data, transaction.getSignature().getBytes());
final CompletableFuture<Deserializer> future = TransactionApi.announceTransaction(NemAppsLibGlobals.getNodeEndpoint(),
request);
try {
Deserializer transDes = future.get();
return new NemAnnounceResult(transDes);
} catch (Exception e) {
LOGGER.warning("Error Occured: " + e.getMessage());
}
return null;
}
示例6: testMulitSigTransactionBuilderSecureMessage
import org.nem.core.model.TransferTransaction; //导入依赖的package包/类
/**
* Test cb build and send string XML transaction.
*/
@Test
public void testMulitSigTransactionBuilderSecureMessage() {
// Build a transaction and send it.
try {
final SecureMessage message = SecureMessage.fromDecodedPayload(this.senderPrivateAccount,
this.recipientPublicAccount, this.sampleMsg.getBytes());
TransferTransaction trans = TransferTransactionBuilder
.sender(new Account(new KeyPair(PrivateKey
.fromHexString("d8b89745a3006e293d16b8a16294582734c6b20ca5feb6e7ca25fec9295b1145")))) // multisig
.recipient(new Account(new KeyPair(PublicKey
.fromHexString("a70bf981bdb62c5d4e44b25ca2629108a394c7aaf18eec50dc405b1e44d712d4"))))
.fee(Amount.ZERO).amount(Amount.fromMicroNem(0l))
.attachment(AttachmentFactory.createTransferTransactionAttachment(message)).buildTransaction();
MultisigTransactionBuilder.sender(this.senderPrivateAccount).otherTransaction(trans)
.buildAndSendMultisigTransaction();
// it!
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: testCbBuildAndSendFileTransaction
import org.nem.core.model.TransferTransaction; //导入依赖的package包/类
/**
* Test cb build and send file transaction.
*/
@Test
public void testCbBuildAndSendFileTransaction() {
SecureMessage message = null;
try {
message = SecureMessage.fromDecodedPayload(this.senderPrivateAccount, this.recipientPublicAccount,
sampleMsg.getBytes());
} catch (Exception e1) {
e1.printStackTrace();
}
// Build a transaction and send it.
try {
TransferTransaction trans = TransferTransactionBuilder
.sender(new Account(new KeyPair(PrivateKey
.fromHexString("d8b89745a3006e293d16b8a16294582734c6b20ca5feb6e7ca25fec9295b1145")))) // multisig
.recipient(this.recipientPublicAccount).fee(Amount.ZERO).amount(Amount.fromMicroNem(0l))
.buildTransaction();
MultisigTransactionBuilder.sender(this.senderPrivateAccount).otherTransaction(trans)
.buildAndSendMultisigTransaction();
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: send_v2
import org.nem.core.model.TransferTransaction; //导入依赖的package包/类
public String send_v2(String recipient, long amount, String messagePayload, MosaicId mosaicId, Quantity mosaicQuantity, String fee){
// collect parameters
TimeInstant timeInstant = new SystemTimeProvider().getCurrentTime();
KeyPair senderKeyPair = new KeyPair(PrivateKey.fromHexString(this.privateKey));
Account senderAccount = new Account(senderKeyPair);
Account recipientAccount = new Account(Address.fromEncoded(recipient));
// add message and mosaic
TransferTransactionAttachment attachment = new TransferTransactionAttachment();
if(!"".equals(messagePayload.trim())){
PlainMessage message = new PlainMessage(messagePayload.getBytes());
attachment.setMessage(message);
}
if(mosaicId!=null && mosaicQuantity!=null){
attachment.addMosaic(mosaicId, mosaicQuantity);
}
if(attachment.getMessage()==null && attachment.getMosaics().size()==0){
attachment = null;
}
// create transaction
TransferTransaction transaction = new TransferTransaction(2, timeInstant, senderAccount, recipientAccount, Amount.fromNem(amount), attachment);
// ignore fee or not
if(fee==null){
TransactionFeeCalculatorAfterForkForApp feeCalculator = new TransactionFeeCalculatorAfterForkForApp();
transaction.setFee(feeCalculator.calculateMinimumFee(transaction));
} else {
transaction.setFee(Amount.fromNem(0));
}
transaction.setDeadline(timeInstant.addHours(23));
transaction.sign();
JSONObject params = new JSONObject();
final byte[] data = BinarySerializer.serializeToBytes(transaction.asNonVerifiable());
params.put("data", ByteUtils.toHexString(data));
params.put("signature", transaction.getSignature().toString());
return HttpClientUtils.post(Constants.URL_TRANSACTION_ANNOUNCE, params.toString());
}
示例9: parseTransactionDataByType
import org.nem.core.model.TransferTransaction; //导入依赖的package包/类
protected void parseTransactionDataByType(UnconfirmedTransactionMetaDataPair pair, TransactionData data) {
if (pair.getEntity().getType() == TransactionTypes.TRANSFER) {
TransferTransaction transferTransaction = (TransferTransaction) pair.getEntity();
data.setAmount(transferTransaction.getAmount().getNumNem());
data.setRecipient(transferTransaction.getRecipient().getAddress().toString());
if (transferTransaction.getMessage() != null) {
if (transferTransaction.getMessage().getType() == MessageTypes.PLAIN) {
data.setMessage(new String(transferTransaction.getMessage().getDecodedPayload()));
}
}
if (transferTransaction.getMosaics() != null && transferTransaction.getMosaics().size() > 0) {
List<MosaicData> mosaicDataList = new ArrayList<>();
for (Mosaic mosaic : transferTransaction.getMosaics()) {
MosaicData mosaicData = new MosaicData();
mosaicData.setNamespace(mosaic.getMosaicId().getNamespaceId().toString());
mosaicData.setMosaic(mosaic.getMosaicId().getName());
mosaicData.setQuantity(mosaic.getQuantity().getRaw());
mosaicDataList.add(mosaicData);
}
}
} else if (pair.getEntity().getType() == TransactionTypes.PROVISION_NAMESPACE) {
} else if (pair.getEntity().getType() == TransactionTypes.MOSAIC_DEFINITION_CREATION) {
} else if (pair.getEntity().getType() == TransactionTypes.MULTISIG_AGGREGATE_MODIFICATION) {
} else if (pair.getEntity().getType() == TransactionTypes.MULTISIG_SIGNATURE) {
} else if (pair.getEntity().getType() == TransactionTypes.MULTISIG) {
} // TODO other transaction type
}
示例10: send_v2
import org.nem.core.model.TransferTransaction; //导入依赖的package包/类
public String send_v2(String recipient, long amount, String messagePayload, MosaicId mosaicId, Quantity mosaicQuantity, String fee){
// collect parameters
TimeInstant timeInstant = new SystemTimeProvider().getCurrentTime();
KeyPair senderKeyPair = new KeyPair(PrivateKey.fromHexString(this.privateKey));
Account senderAccount = new Account(senderKeyPair);
Account multisigAccount = new Account(Address.fromPublicKey(PublicKey.fromHexString(this.multisigPublicKey)));
Account recipientAccount = new Account(Address.fromEncoded(recipient));
TransferTransactionAttachment attachment = new TransferTransactionAttachment();
if(!"".equals(messagePayload.trim())){
PlainMessage message = new PlainMessage(messagePayload.getBytes());
attachment.setMessage(message);
}
if(mosaicId!=null && mosaicQuantity!=null){
attachment.addMosaic(mosaicId, mosaicQuantity);
}
if(attachment.getMessage()==null && attachment.getMosaics().size()==0){
attachment = null;
}
// create transaction
TransferTransaction transaction = new TransferTransaction(2, timeInstant, multisigAccount, recipientAccount, Amount.fromNem(amount), attachment);
TransactionFeeCalculatorAfterForkForApp feeCalculator = new TransactionFeeCalculatorAfterForkForApp();
// ignore fee or not
if(fee==null){
transaction.setFee(feeCalculator.calculateMinimumFee(transaction));
} else {
transaction.setFee(Amount.fromNem(0));
}
// create multisig transaction
MultisigTransaction multisigTransaction = new MultisigTransaction(timeInstant, senderAccount, transaction);
if(fee==null){
multisigTransaction.setFee(feeCalculator.calculateMinimumFee(multisigTransaction));
} else {
multisigTransaction.setFee(Amount.fromNem(0));
}
transaction.setDeadline(timeInstant.addHours(23));
multisigTransaction.setDeadline(timeInstant.addHours(23));
multisigTransaction.sign();
JSONObject params = new JSONObject();
final byte[] data = BinarySerializer.serializeToBytes(multisigTransaction.asNonVerifiable());
params.put("data", ByteUtils.toHexString(data));
params.put("signature", multisigTransaction.getSignature().toString());
return HttpClientUtils.post(Constants.URL_TRANSACTION_ANNOUNCE, params.toString());
}
示例11: parseTransactionSearchResult
import org.nem.core.model.TransferTransaction; //导入依赖的package包/类
private List<TransactionData> parseTransactionSearchResult(Deserializer deserializer) {
final List<TransactionMetaDataPair> resultList =
deserializer.readOptionalObjectArray("data", TransactionMetaDataPair::new);
List<TransactionData> transactionList = new ArrayList<TransactionData>();
if (resultList != null && resultList.size() > 0) {
resultList.stream()
.forEach(pair -> {
TransactionData data = new TransactionData();
data.setId(pair.getMetaData().getId());
data.setHash(pair.getMetaData().getHash().toString());
data.setHeight(pair.getMetaData().getHeight().getRaw());
data.setFee(pair.getEntity().getFee().getNumNem());
data.setSigner(pair.getEntity().getSigner().getAddress().toString());
data.setTimestamp(pair.getEntity().getTimeStamp().getRawTime());
data.setDeadline(pair.getEntity().getDeadline().getRawTime());
data.setType(pair.getEntity().getType());
data.setVersion(pair.getEntity().getVersion());
if (pair.getEntity().getType() == TransactionTypes.TRANSFER) {
TransferTransaction transferTransaction = (TransferTransaction) pair.getEntity();
data.setAmount(transferTransaction.getAmount().getNumNem());
data.setRecipient(transferTransaction.getRecipient().getAddress().toString());
if (transferTransaction.getMessage() != null) {
if (transferTransaction.getMessage().getType() == MessageTypes.PLAIN) {
data.setMessage(new String(transferTransaction.getMessage().getDecodedPayload()));
} else if (transferTransaction.getMessage().getType() == MessageTypes.SECURE) {
// TODO decrypt message need account private key and sender public key
data.setMessage(new String(transferTransaction.getMessage().getEncodedPayload()));
}
}
if (transferTransaction.getMosaics() != null && transferTransaction.getMosaics().size() > 0) {
List<MosaicData> mosaicDataList = new ArrayList<>();
for (Mosaic mosaic : transferTransaction.getMosaics()) {
MosaicData mosaicData = new MosaicData();
mosaicData.setNamespace(mosaic.getMosaicId().getNamespaceId().toString());
mosaicData.setMosaic(mosaic.getMosaicId().getName());
mosaicData.setQuantity(mosaic.getQuantity().getRaw());
mosaicDataList.add(mosaicData);
}
}
} // TODO other transaction type
transactionList.add(data);
});
}
return transactionList;
}
示例12: sendFutureTransferTransaction
import org.nem.core.model.TransferTransaction; //导入依赖的package包/类
public static CompletableFuture<Deserializer> sendFutureTransferTransaction(TransferTransaction transaction) {
final byte[] data = BinarySerializer.serializeToBytes(transaction.asNonVerifiable());
final RequestAnnounce request = new RequestAnnounce(data, transaction.getSignature().getBytes());
return TransactionApi.announceTransaction(NemAppsLibGlobals.getNodeEndpoint(), request);
}
示例13: buildTransaction
import org.nem.core.model.TransferTransaction; //导入依赖的package包/类
/**
* Builds the transaction.
*
* @return the transfer transaction
*/
TransferTransaction buildTransaction();