This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
batnode-sample.js
58 lines (41 loc) · 1.73 KB
/
batnode-sample.js
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
const BatNode = require('./batnode').BatNode;
const PERSONAL_DIR = require('./utils/file').PERSONAL_DIR;
const HOSTED_DIR = require('./utils/file').HOSTED_DIR;
const fileSystem = require('./utils/file').fileSystem;
const crypto = require('crypto');
// Define callback for server to execute when a new connection has been made.
// The connection object can have callbacks defined on it
// Below is a node server that can respond to file retrieval requests or file storage requests
// When sending image data as part of JSON object, two JSON objects are sent, each sending an incomplete JSON object
// with only part of the image data
/*const node1ConnectionCallback = (serverConnection) => {
serverConnection.on('end', () => {
console.log('end')
})
serverConnection.on('data', (receivedData, error) => {
console.log("received data: ")
receivedData = JSON.parse(receivedData)
if (receivedData.messageType === "RETRIEVE_FILE") {
node1.readFile(`./hosted/${receivedData.fileName}`, (error, data) => {
serverConnection.write(data)
})
} else if (receivedData.messageType === "STORE_FILE"){
node1.receiveFile(receivedData)
serverConnection.write(JSON.stringify({messageType: "SUCCESS"}))
}
})
}
*/
const node1 = new BatNode()
//node1.createEscrowAccount();
let buff = Buffer.from('hello', 'hex');
let hash = crypto.createHash('sha256').update(buff).digest('hex')
//console.log(hash)
fileSystem.processUpload('./personal/example.txt', () => {
console.log('done')
})
//node1.getStellarAccountInfo();
//console.log(node1.stellarAccountId)
//node1.createServer(1237,'127.0.0.1', node1ConnectionCallback, null)
// const node2 = new BatNode()
// node2.uploadFile(1237, '127.0.0.1', './personal/example.txt')