-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMetaPublish.js
64 lines (53 loc) · 1.79 KB
/
MetaPublish.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
53
54
55
56
57
58
59
60
61
62
63
64
/*
* StromDAO Business Object: Meta Data Publish
* =========================================
* Distribution Public MetaData for StromDAO Energy Blockchain.
*
* @author Thorsten Zoerner thorsten.zoerner@stromdao.de
*
*/
var request = require('request');
this.metaset=function(role_id) {
var p1 = new Promise(function(resolve, reject) {
var obj = {};
obj.put=function(data_obj) {
var p2 = new Promise(function(resolve2, reject2) {
// First Publish Data and get MultiHash
request.post("https://demo.stromdao.de/put", {form:data_obj}).on('data', function(data) {
var multihash=data.toString();
parent.stringstoragefactory().then( function(ssf) {
ssf.build(multihash).then(function(adr) {
parent.roleLookup().then(function(rl) {
rl.setRelation(role_id,adr).then(function(hash) {
resolve2(adr);
});
});
});
});
});
});
return p2;
// Second set in Role s and return Promise
}
obj.get=function(address) {
var p2 = new Promise(function(resolve2, reject2) {
parent.roleLookup().then(function(rl) {
rl.relations(address,role_id).then(function(roler) {
parent.stringstorage(roler).then(function(ss) {
ss.str().then(function(multihash) {
request.post("https://demo.stromdao.de/get",{form:{key:multihash}}).on('data', function(d) {
string = d.toString();
//console.log(roler,multihash,string);
resolve2(string);
});;
});
});
});
});
});
return p2;
}
resolve(obj);
});
return p1;
};