-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontract.py
More file actions
executable file
·48 lines (36 loc) · 1.6 KB
/
Copy pathcontract.py
File metadata and controls
executable file
·48 lines (36 loc) · 1.6 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
#!/usr/bin/env python3
import argparse
import time
from web3 import Web3, HTTPProvider
import json
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--password', default="")
parser.add_argument('contract', metavar='CONTRACT')
parser.add_argument('account', metavar='ACCOUNT', nargs='?',
help='Required if --set-actuation is used')
parser.add_argument('--amount', type=int, default=1000000000)
parser.add_argument('--server-url', default='http://localhost:8545',
metavar='URL')
parser.add_argument('--abi-file', default='device_sol_Device.abi',
metavar='FILE')
parser.add_argument('--set-actuation', dest='actuation',
metavar='VALUE', type=int, default=None)
args = parser.parse_args()
web3 = Web3(HTTPProvider(args.server_url, request_kwargs={'timeout': 60}))
abi = json.load(open(args.abi_file))
device = web3.eth.contract(args.contract, abi=abi)
# fetch current temperature and actuation values
temp = device.call().get()
act = device.call().actuation()
print("Current temperature:", temp / 100.0)
print("Current actuation:", act)
if args.actuation is not None:
assert args.account is not None, \
"ACCOUNT may not be empty if --set is used"
web3.personal.unlockAccount(args.account, args.password)
device.transact({"from": args.account,
"value": args.amount}).actuate(args.actuation)
print("Updated actuation to:", args.actuation)
if __name__ == '__main__':
main()