本文整理汇总了TypeScript中duniter/app/lib/common-libs/underscore.Underscore.keys方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Underscore.keys方法的具体用法?TypeScript Underscore.keys怎么用?TypeScript Underscore.keys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类duniter/app/lib/common-libs/underscore.Underscore
的用法示例。
在下文中一共展示了Underscore.keys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
pay: async (fromBlock: number, toBlock: number) => {
let blocks = await duniterServer.dal.getBlocksBetween(fromBlock, toBlock);
let reallyPaid = payperblock * blocks.length; // Implicitely: amount in the current base
let statsPerIssuer = getStatsPerIssuer(blocks, payperblock);
let sources = await duniterServer.dal.getAvailableSourcesByPubkey(remuniterPubkey);
let current = await duniterServer.dal.getCurrentBlockOrNull() as DBBlock
let maxBase = current.unitbase;
const minBase = sources.reduce((min, src) => Math.min(min, src.base), 0);
const bases: {
[k: number]: number
} = {}
sources.forEach((src) => bases[src.base] = 0);
sources.forEach((src) => bases[src.base] += src.amount);
bases[maxBase] = bases[maxBase] || 0;
// Try to convert 1 base to the other
let outputsOfRests = [];
for (let i = minBase; i < maxBase; i++) {
bases[i] = bases[i] || 0;
bases[i + 1] = bases[i + 1] || 0;
const rest = bases[i] % 10;
bases[i] -= rest;
bases[i + 1] += bases[i] / 10;
outputsOfRests.push([rest, i, 'SIG(' + remuniterPubkey + ')'].join(':'));
}
const availableMoney = bases[maxBase];
let outputsToIssuers = Underscore.keys(statsPerIssuer).map((issuer) => [statsPerIssuer[issuer].amount, maxBase, 'SIG(' + issuer + ')'].join(':'));
if (availableMoney >= reallyPaid) {
let tx = {
documentType: 'transaction',
version: 10,
currency: duniterServer.conf.currency,
blockstamp: [current.number, current.hash].join('-'),
locktime: 0,
issuers: [remuniterPubkey],
inputs: sources.map((src) => [src.amount, src.base, src.type, src.identifier, src.noffset].join(':')),
unlocks: sources.map((src, index) => [index, 'SIG(0)'].join(':')),
outputs: outputsOfRests.concat(outputsToIssuers).concat([availableMoney - reallyPaid, maxBase, 'SIG(' + remuniterPubkey + ')'].join(':')),
comment: ['REMU', fromBlock, toBlock].join(':'),
signatures: [] as string[]
};
let rawTX = getRawTransaction(tx);
// ----- SIGNATURE -----
tx.signatures = [await duniterServer.sign(rawTX)];
// ----- SUBMITTING -----
await duniterServer.writeRawTransaction(getRawTransaction(tx));
return existsTx(fromBlock, toBlock, 'sending');
}
return false;
},
示例2: return
return (async () => {
let current = await duniterServer.dal.getCurrentBlockOrNull();
if (!current) {
return [];
}
if (blocksCount === undefined) {
blocksCount = current.issuersFrame;
}
let blocks = await duniterServer.dal.getBlocksBetween(current.number - blocksCount + 1, current.number);
let txh = await duniterServer.dal.getTransactionsHistory(remuniterPubkey);
let stats = getStatsPerIssuer(blocks, payperblock);
let issuers: string[] = Underscore.keys(stats) as string[];
// If the data is for the current window view, calculate medianOfBlocksInFrame
let medianOfBlocksInFrame=0;
if (blocksCount == current.issuersFrame) {
let blocksPerIssuerInFrame = issuers.map(issuer => stats[issuer].blocks);
blocksPerIssuerInFrame.sort((a, b) => a - b);
medianOfBlocksInFrame = (blocksPerIssuerInFrame[(blocksPerIssuerInFrame.length - 1) >> 1] + blocksPerIssuerInFrame[blocksPerIssuerInFrame.length >> 1]) / 2;
}
// Memorize max value of blocks, diff, exclusionFactor and handicap
let maxBlocks=0;
let maxDiff=0;
let maxExclusionFactor=0;
let maxHandicap=0;
for (let i = 0, len = issuers.length; i < len; i++) {
stats[issuers[i]].idty = (await getUID(issuers[i]) as FullIindexEntry);
stats[issuers[i]].stringBlocks = stats[issuers[i]].blocks.toString();
// If the data is for the current window view
if (blocksCount == current.issuersFrame) {
// Calculate issuer handicap
let issuerExcess = ( (stats[issuers[i]].blocks + 1) / (medianOfBlocksInFrame) ) - 1;
if (issuerExcess<0) { issuerExcess = 0; }
stats[issuers[i]].handicap = Math.floor(Math.log(1+issuerExcess)/0.17311261);
// Calculate issuer exclusionFactor
stats[issuers[i]].exclusionFactor = Math.max(1, Math.floor(0.67 * stats[issuers[i]].nbPreviousIssuers / (1 + (current.number-stats[issuers[i]].lastBlock))) );
// Calculate issuer diff
stats[issuers[i]].diff = (current.powMin*(stats[issuers[i]].exclusionFactor as number))+(stats[issuers[i]].handicap as number);
// Calculate max value of blocks, diff, exclusionFactor and handicap
maxBlocks = (maxBlocks<stats[issuers[i]].blocks) ? stats[issuers[i]].blocks:maxBlocks;
maxDiff = parseInt(String((maxDiff<stats[issuers[i]].diff) ? stats[issuers[i]].diff:maxDiff))
maxExclusionFactor = parseInt(String((maxExclusionFactor<stats[issuers[i]].exclusionFactor) ? stats[issuers[i]].exclusionFactor:maxExclusionFactor))
maxHandicap = parseInt(String((maxHandicap<stats[issuers[i]].handicap) ? stats[issuers[i]].handicap:maxHandicap))
}
}
// If the data is for the current window view, align field size of blocks, diff, exclusionFactor and handicap
if (blocksCount == current.issuersFrame) {
for (let i = 0, len = issuers.length; i < len; i++) {
// exclusionFactor and handicap : change the default to "-"
if (stats[issuers[i]].exclusionFactor == 1) {
stats[issuers[i]].exclusionFactor = "-";
for (let j = 1;j<maxExclusionFactor.toString().length;j++) {
stats[issuers[i]].exclusionFactor += "-";
}
}
if (stats[issuers[i]].handicap == 0) {
stats[issuers[i]].handicap = "-";
for (let j = 1;j<maxHandicap.toString().length;j++) {
stats[issuers[i]].handicap += "-";
}
}
// addition of "0" for alignment
for (let j = stats[issuers[i]].stringBlocks.length;j<maxBlocks.toString().length;j++) {
stats[issuers[i]].stringBlocks = "0"+stats[issuers[i]].stringBlocks;
}
// addition of "-" for alignment
for (let j = stats[issuers[i]].diff.toString().length;j<maxDiff.toString().length;j++) {
stats[issuers[i]].diff = stats[issuers[i]].diff+"-";
}
for (let j = stats[issuers[i]].exclusionFactor.toString().length;j<maxExclusionFactor.toString().length;j++) {
stats[issuers[i]].exclusionFactor = stats[issuers[i]].exclusionFactor+"-";
}
for (let j = stats[issuers[i]].handicap.toString().length;j<maxHandicap.toString().length;j++) {
stats[issuers[i]].handicap = stats[issuers[i]].handicap+"-";
}
}
}
return issuers.map((issuer) => {
return {
name: stats[issuer].idty.uid,
blocks: stats[issuer].blocks,
stringBlocks: stats[issuer].stringBlocks,
handicap: stats[issuer].handicap,
exclusionFactor: stats[issuer].exclusionFactor,
diff: stats[issuer].diff,
amount: stats[issuer].amount,
paid: getWhatWasPaid(issuer, txh, blocks)
};
});
})()