-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_previous.js
More file actions
106 lines (86 loc) · 3.42 KB
/
app_previous.js
File metadata and controls
106 lines (86 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const express = require("express");
const ejs = require("ejs");
const WavesAPI = require("waves-api");
const app = express();
const Waves = WavesAPI.create(WavesAPI.TESTNET_CONFIG);
const newConfig = {
// The byte allowing to distinguish networks (mainnet, testnet, devnet, etc)
networkByte: Waves.constants.TESTNET_BYTE,
// Node and Matcher addresses, no comments here
nodeAddress: 'https://testnode2.wavesnodes.com',
matcherAddress: 'https://testnode2.wavesnodes.com/matcher',
// If a seed phrase length falls below that value an error will be thrown
minimumSeedLength: 50
};
Waves.config.set(newConfig);
const seed = Waves.Seed.create();
console.log(seed.phrase); // random 'hole law front bottom then mobile fabric under horse drink other member work twenty boss'
console.log(seed.address); // random '3Mr5af3Y7r7gQej3tRtugYbKaPr5qYps2ei'
console.log(seed.keyPair); // random { privateKey: 'HkFCbtBHX1ZUF42aNE4av52JvdDPWth2jbP88HPTDyp4', publicKey: 'AF9HLq2Rsv2fVfLPtsWxT7Y3S9ZTv6Mw4ZTp8K8LNdEp' }
let amount;
// if we have database can be extracted the signature
// When staring the second voting, extract the signature from db
// Waves.API.Node.v1.blocks.get(signature).then((block) => console.log(block));
// in this case I use the first block cuz I dont have any data of signature
Waves.API.Node.v1.blocks.first().then((firstBlock) => {
// confirmation sender and amount from the transaction block
for (i = 0; i < firstBlock.transactions.length; i++) {
console.log(firstBlock)
let recipient = firstBlock.transactions[i].recipient;
console.log("recipient", recipient);
amount = firstBlock.transactions[i].amount / 2;
console.log("amount", amount);
const transferData = {
recipient: recipient,
assetId: 'WAVE',
amount: amount,
feeAssetId: 'WAVES',
fee: 100000,
attachment: '',
timestamp: Date.now()
};
Waves.API.Node.v1.assets.transfer(transferData, seed.keyPair).then((responseData) => {
console.log(responseData);
});
}
// => transfer rest amount to correct answer address SCAM or not SCAM
var result = Waves.API.Node.v1.addresses.balance(seed.address).then((balance) => {
console.log(balance);
const transferData = {
recipient: " / address chosing correct answer / ",
assetId: 'WAVE',
amount: balance.balance,
feeAssetId: 'WAVES',
fee: 100000,
attachment: '',
timestamp: Date.now()
};
Waves.API.Node.v1.assets.transfer(transferData, seed.keyPair).then((responseData) => {
console.log(responseData);
});
// use the correct answers signature
for (i = 0; i < firstBlock.transactions.length; i++) {
// choose address of the correct answer block.
let recipient = firstBlock.transactions[i].recipient;
console.log("recipient", recipient);
console.log(balance.balance, amount)
let return_amount = balance * firstBlock.transactions[i].amount / (balance - amount);
console.log("amount", return_amount);
const transferData = {
recipient: recipient,
assetId: 'WAVE',
amount: amount,
feeAssetId: 'WAVES',
fee: 100000,
attachment: '',
timestamp: Date.now()
};
Waves.API.Node.v1.assets.transfer(transferData, seed.keyPair).then((responseData) => {
console.log(responseData);
});
}
});
});
var server = app.listen(8080, function() {
console.log("Server is running!");
});