本文整理汇总了TypeScript中nem-library.TransferTransaction.mosaics方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TransferTransaction.mosaics方法的具体用法?TypeScript TransferTransaction.mosaics怎么用?TypeScript TransferTransaction.mosaics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nem-library.TransferTransaction
的用法示例。
在下文中一共展示了TransferTransaction.mosaics方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: xemToUsd
return new Promise<XemTransaction>(async (resolve, reject) => {
try {
let tokenType = TokenType.NA;
let paid = 0;
let usdPaid = 0;
/**
* This first part is a safeguard - it means someone sent a Mosaic token
* instead of XEM. Handle these scenario accordingly
*/
if (transaction.containsMosaics()) {
transaction.mosaics().map(mosaic => {
if (mosaic.mosaicId.namespaceId === nemConfig.mosaicNamespace
&& mosaic.mosaicId.name === nemConfig.mosaicForTransfer) {
tokenType = TokenType.CHE;
paid += mosaic.quantity;
}
});
} else {
/**
* Someone sent XEM
*/
tokenType = TokenType.XEM;
paid = transaction.xem().amount * 1e6;
usdPaid = await xemToUsd(paid);
}
const formmatedTransaction: XemTransaction = {
_id: new ObjectID(),
tokenRecipientAddress: transaction.signer.address.plain(),
tokenType: tokenType,
totalPaid: paid,
usdPaid: usdPaid,
createdAt: new Date()
};
if (transaction.message) {
formmatedTransaction.message = (transaction.message as PlainMessage).plain().replace(/ /g, '');
}
resolve(formmatedTransaction);
} catch (err) {
reject(err);
}
});