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


TypeScript nem-library.NEMLibrary类代码示例

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


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

示例1: before

 before(() => {
     NEMLibrary.bootstrap(NetworkTypes.TEST_NET);
     publicAccount = PublicAccount.createWithPublicKey("0414fe7647ec008e533aac98a4bf1c5fbf1d236c75b81fdadf1f5d1042fdd2ff");
     transferTransaction = TransferTransaction.create(
         TimeWindow.createWithDeadline(),
         new Address("TDM3DO-ZM5WJ3-ZRBPSM-YRU6JS-WKUCAH-5VIPOF-4W7K"),
         new XEM(5),
         EmptyMessage
     );
     importanceTransaction = ImportanceTransferTransaction.create(
         TimeWindow.createWithDeadline(),
         ImportanceMode.Activate,
         publicAccount
     );
 });
开发者ID:sbelalex,项目名称:nem-ico-project,代码行数:15,代码来源:ExtractTransferTransaction.spec.ts

示例2: ConfirmedTransactionListener

import {
    NEMLibrary, NetworkTypes, Account, ConfirmedTransactionListener, TransactionTypes, TransferTransaction, TimeWindow, PlainMessage, TransactionHttp, MultisigTransaction
} from "nem-library";
import { WowTestMosaic } from "./models/WowTestMosaic";
import {Observable} from "rxjs";
import {IsOrContainsTransferTransaction} from "./functions/IsOrContainsTransferTransaction";
import {ExtractTransferTransaction} from "./functions/ExtractTransferTransaction";
import {ICOPayment} from "./functions/ICOPayment";

NEMLibrary.bootstrap(NetworkTypes.TEST_NET);
declare let process: any;

const privateKey: string = process.env.PRIVATE_KEY;
const account = Account.createWithPrivateKey(privateKey);

const transactionHttp = new TransactionHttp();

new ConfirmedTransactionListener().given(account.address)
    .map((_) => {
        console.log("\nCONFIRMED TRANSACTION", _);
        return _;
    })
    .filter(IsOrContainsTransferTransaction)
    .map(ExtractTransferTransaction)
    .filter((_) => _!.signer!.address.plain() != account.address.plain())
    .map(ICOPayment)
    .map((_) => account.signTransaction(_))
    .flatMap((_) => transactionHttp.announceTransaction(_))
    .subscribe((_) => {
        console.log("Successfully", _)
    });
开发者ID:sbelalex,项目名称:nem-ico-project,代码行数:31,代码来源:index.ts

示例3: require

import {
	Account, Address, EmptyMessage, MosaicHttp, MosaicId, NEMLibrary, NetworkTypes, Password, SimpleWallet, TimeWindow,
	TransferTransaction, AccountHttp, Mosaic, TransactionHttp, NemAnnounceResult
} from 'nem-library';
import { Observable } from 'rxjs/Observable';

const NETWORK = NetworkTypes.MAIN_NET;
NEMLibrary.bootstrap(NETWORK);

const mosaicSettings = require('./mosaic-settings.json');
const WALLET_NAME = mosaicSettings.wallet_name;
const namespace = mosaicSettings.mosaic_namespace;
const mosaicName = mosaicSettings.mosaic_name;
const mosaicId = new MosaicId(namespace, mosaicName);
const mosaicHttp = new MosaicHttp();

export const getAccountBalances = (account: Account): Promise<Array<Mosaic>> => {
	return new Promise<Array<Mosaic>>((resolve, reject) => {
		const accountHttp = new AccountHttp();
		accountHttp.getMosaicOwnedByAddress(account.address).subscribe(mosaics => {
			resolve(mosaics);
		}, error => {
			reject(error);
		});
	});
};

export const mosaicBalance = (balances: Array<Mosaic>): number => {
	const found = balances.find((mosaic) => {
		return mosaic.mosaicId.name === mosaicName
	});
开发者ID:devslopes,项目名称:mosaic-cli-wallet,代码行数:31,代码来源:wallet.ts

示例4: after

 after(() => {
     NEMLibrary.reset();
 });
开发者ID:sbelalex,项目名称:nem-ico-project,代码行数:3,代码来源:ExtractTransferTransaction.spec.ts

示例5: before

 before(() => {
     NEMLibrary.bootstrap(NetworkTypes.TEST_NET);
 });
开发者ID:sbelalex,项目名称:nem-ico-project,代码行数:3,代码来源:ICOPayment.spec.ts

示例6: tokenHoldingAccountAddress

export const initNEM = () => {
	NEM_NETWORK = process.env.NODE_ENV === 'production' ? NetworkTypes.MAIN_NET : NetworkTypes.TEST_NET;
	const TOKEN_HOLDING_ADDRESS = tokenHoldingAccountAddress();
	NEMLibrary.bootstrap(NEM_NETWORK);
	/**
	 * Even though initNEM is only called once, this transaction listener
	 * will capture all confirmed transactions on the NEM blockchain
	 */
	new ConfirmedTransactionListener()
		.given(new Address(TOKEN_HOLDING_ADDRESS))
		.filter(transferFilter)
		.map(mapTransfer)
		// Next batch of confirmed transactions
		.map( async (transferTransaction: TransferTransaction) => {
			try {
				const rawMsg = (transferTransaction.message as PlainMessage).plain().replace(/ /g, '');
				const hashId = rawMsg.substr(rawMsg.indexOf(':'), rawMsg.length);

				/**
				 * Try finding a transaction in the database that may be a partial payment. Sometimes people will send
				 * multiple amounts of XEM to purchase a product
				 */
				let transaction: XemTransaction = await findOneThatContains<XemTransaction>(DB_PARTIAL_XEM_CHARGES, 'message', hashId, TRANSACTION_MESSAGE_LENGTH);
				/**
				 * If it is not partial, we look up pending charges
				 */
				if (!transaction) {
					transaction = await findOneThatContains<XemTransaction>(DB_PENDING_XEM_CHARGES, 'message', hashId, TRANSACTION_MESSAGE_LENGTH);
				}
				const transfer = await formatIncomingTransaction(transferTransaction);

				/**
				 * Ignore transactions that are confirmed for the holding account - we only want to
				 * listen for customer transactions
				 */
				if (transfer.tokenRecipientAddress === tokenHoldingAccountAddress()
					|| transfer.tokenRecipientAddress === nemConfig.multisigAddress) {
					return;
				}

				/**
				 * If the transaction is not in the database someone sent us XEM without using
				 * our purchase process on the website
				 */
				if (!transaction) {
					saveAnonymousTransaction(transfer);
				} else {
					/**
					 * We found the pending transaction in the database
					 */
					onTransactionConfirmed(transaction, transfer);
				}
			} catch (err) {
				/**
				 * Save errors to the database so we can handle customer inquiries
				 */
				const amountPaid = transferTransaction.xem().amount;
				const errorTrans: XemTransaction = {
					_id: new ObjectID(),
					tokenRecipientAddress: transferTransaction.signer.address.plain(),
					tokenType: TokenType.NA,
					totalPaid: amountPaid,
					message: 'Contains mosaics: ' + transferTransaction.containsMosaics(),
					createdAt: new Date(),
					errMsg: err
				};
				await saveWithId<XemTransaction>(DB_PROBLEM_XEM_CHARGES, errorTrans);
			}
		})
			.subscribe( _ => {}, err => {
			console.log(err);
		});
};
开发者ID:joseabril25,项目名称:nem-coinbase-token-sale-api,代码行数:73,代码来源:nem-service.ts


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