本文整理汇总了TypeScript中duniter/server.Server类的典型用法代码示例。如果您正苦于以下问题:TypeScript Server类的具体用法?TypeScript Server怎么用?TypeScript Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Server类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
},
开发者ID:duniter,项目名称:remuniter,代码行数:56,代码来源:wallet.ts
示例2: constructor
constructor(
private port:number,
private server:Server) {
ProverDependency.duniter.methods.hookServer(server)
server.addEndpointsDefinitions(async () => {
return BmaDependency.duniter.methods.getMainEndpoint(server.conf)
})
}
开发者ID:duniter,项目名称:remuniter,代码行数:10,代码来源:test-tools.ts
示例3: listenWebSocket
function listenWebSocket(httpServer: any, duniterServer: Server, payperblock: number) {
let remuWallet = wallet(duniterServer, payperblock);
let lastBlocks: DBBlock[] = [];
let top1 = remuWallet.lastDayTheoretical();
let top2 = remuWallet.lastWeekTheoretical();
let topgifts = remuWallet.topGifts();
let wssBlock = new WebSocketServer({
server: httpServer,
path: '/ws/block'
});
let getData = () => co(function *() {
try {
let current = yield remuWallet.getCurrentBlock();
let data1 = yield top1;
let data2 = yield top2;
let data3 = yield topgifts;
yield lastBlocks.map((b: any) => co(function *() {
const idty = yield remuWallet.getUID(b.issuer)
b.uid = (idty && idty.uid) || b.issuer.substr(0, 10)
return b;
}));
(current as any).uid = (yield remuWallet.getUID(current.issuer)).uid;
let remains = yield remuWallet.remains();
return {
key: remuWallet.pubkey,
current,
issuersCount: current.issuersCount,
issuersWeek: data2.length,
issuersFrame: current.issuersFrame,
remains: remains,
remains_days: (Math.floor(remains / (remuWallet.pay_per_block * Math.pow(10, current.unitbase))) * duniterServer.conf.avgGenTime / (3600 * 24)).toFixed(1),
pay_per_block: remuWallet.pay_per_block,
unitbase: current.unitbase,
blocks: lastBlocks,
top1: data1,
top2: data2,
topgifts: data3,
unit: PAY_UNIT
};
} catch (e) {
console.error(e);
}
});
wssBlock.on('connection', function connection(ws: any) {
co(function *() {
if (lastBlocks.length < 10) {
let current = yield duniterServer.dal.getCurrentBlockOrNull();
lastBlocks = yield duniterServer.dal.getBlocksBetween(current.number - 10, current.number);
}
ws.on('message', function(message: any) {
console.log('received: %s', message);
co(function *() {
let toSend = yield getData();
ws.send(JSON.stringify(toSend));
});
});
});
});
wssBlock.broadcast = (data: any) => wssBlock.clients.forEach((client: any) => client.send(data));
// Forward blocks
duniterServer.on('data', async (data: any) => {
if (data.bcEvent === 'newHEAD') {
try {
// Broadcast block
lastBlocks.shift();
lastBlocks.push(data.block);
top1 = remuWallet.lastDayTheoretical();
top2 = remuWallet.lastWeekTheoretical();
topgifts = remuWallet.topGifts();
co(function* () {
let toSend = yield getData()
wssBlock.broadcast(JSON.stringify(toSend));
});
} catch (e) {
console.error(e)
}
}
})
}
开发者ID:duniter,项目名称:remuniter,代码行数:87,代码来源:webserver.ts
示例4: commit
async commit(options:any = null) {
const proven = await this.generateNext(options)
await this.server.writeBlock(proven, true, true) // The resolution is done manually
const blocksResolved = await this.server.BlockchainService.blockResolution()
console.log(BlockDTO.fromJSONObject(blocksResolved).getRawSigned())
if (!blocksResolved) {
throw Error('BLOCK_WASNT_COMMITTED')
}
return blocksResolved
}
开发者ID:duniter,项目名称:remuniter,代码行数:10,代码来源:test-tools.ts
示例5: createJoinAndSubmit
async createJoinAndSubmit() {
const join = await this.makeMembership('IN')
await this.server.writeRawMembership(join.getRawSigned())
}
开发者ID:duniter,项目名称:remuniter,代码行数:4,代码来源:test-user.ts
示例6: createCertAndSubmit
public async createCertAndSubmit(user: TestUser) {
const cert = await this.createCert(user)
await this.server.writeRawCertification(cert.getRawSigned())
}
开发者ID:duniter,项目名称:remuniter,代码行数:4,代码来源:test-user.ts
示例7: createIdentityAndSubmit
async createIdentityAndSubmit() {
await this.createIdentity()
await this.server.writeRawIdentity(this.createdIdentity.getRawSigned())
}
开发者ID:duniter,项目名称:remuniter,代码行数:4,代码来源:test-user.ts
示例8: createTxAndSubmit
async createTxAndSubmit(recipient: TestUser, amount: number, comment = '') {
const raw = await this.prepareITX(amount, recipient, comment)
await this.server.writeRawTransaction(raw)
}
开发者ID:duniter,项目名称:remuniter,代码行数:4,代码来源:test-user.ts
注:本文中的duniter/server.Server类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论