-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlockChainAsset.py
90 lines (80 loc) · 3.32 KB
/
BlockChainAsset.py
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
import requests as rq
import json
import time
class BlockChainAsset:
def __init__(self, secret, address):
self.secret = secret
self.address = address
self.assetId = None
def buildAsset(self, orderNumber, createTime, pickupTime, deliveryTime, shippingPrice, quantity, maxTemperature, minTemperature, toleranceTime, measureInterval, penaltyPerday, maxPenalty, bcSyncInterval, incoterm):
data = {
'content': {
'secret': self.secret,
'data': {
'name': incoterm,
'owner': self.address,
'creator': self.address,
'created_at': createTime,
'custom': {
'order_number': orderNumber,
'pickup_time': pickupTime,
'delivery_time': deliveryTime,
'shipping_price': shippingPrice,
'quantity': quantity,
'max_temperature': maxTemperature,
'min_temperature': minTemperature,
'tolerance_time': toleranceTime,
'measure_interval': measureInterval,
'penalty_per_day': penaltyPerday,
'max_penalty': maxPenalty,
'bcSyncInterval': bcSyncInterval
}
},
'identifiers': {
'isbn': '123'
}
}
}
headers = {
'Content-Type': 'application/json'
}
r = rq.post('https://network.ambrosus.com/assets', json=data, headers=headers)
j = json.loads(r.text)
self.assetId = j['id']
def buildEvent(self, tempSensor1, tempSensor2, tempSensor3, createTime):
data = {
'content': {
'secret': self.secret,
'data': {
'type': 'measurement.temperature',
'subject': self.assetId,
'creator': self.address,
'created_at': createTime,
'custom': {
'tempSensor1': tempSensor1,
'tempSensor2': tempSensor2,
'tempSensor3': tempSensor3,
'unit': 'Celcius'
}
}
}
}
headers = {
'Content-Type': 'application/json'
}
r = rq.post('https://network.ambrosus.com/assets/{}/events'.format(self.assetId), json=data, headers=headers)
def getEvents(self):
headers = {
'Content-Type': 'application/json'
}
r = rq.get('https://network.ambrosus.com/assets/{}/events'.format(self.assetId), headers=headers)
#print(json.dumps(json.loads(r.text), indent = 4, sort_keys = True))
return json.loads(r.text)
if __name__ == '__main__':
secret = '0x546de93a45c8df31e63b0bea9534a7ca03e9eb0e817f0d436d9b324b43d0a123'
address = '0xdce2dd4bB3A9E29714dD317d05869fcD72F20Cbe'
bca = BlockChainAsset(secret, address)
asset = bca.buildAsset(0, 1518685688, 1518685688, 1518688000, 1000, 1, 50, 5, 100, 10, 100, 500, 10, 'hah')
bca.buildEvent(8, 12, 10, 1518685688)
bca.buildEvent(9, 13, 11, 1518685800)
bca.getEvents()