本文整理汇总了TypeScript中nem-library.NEMLibrary.bootstrap方法的典型用法代码示例。如果您正苦于以下问题:TypeScript NEMLibrary.bootstrap方法的具体用法?TypeScript NEMLibrary.bootstrap怎么用?TypeScript NEMLibrary.bootstrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nem-library.NEMLibrary
的用法示例。
在下文中一共展示了NEMLibrary.bootstrap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
);
});
示例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", _)
});
示例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
});
示例4: before
before(() => {
NEMLibrary.bootstrap(NetworkTypes.TEST_NET);
});
示例5: 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);
});
};