-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcli.py
157 lines (148 loc) · 2.88 KB
/
cli.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# append the root project path to the pythonpath so that blockchain.py can be accessed by every adapter
import sys
import os
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from PyInquirer import prompt, print_json, style_from_dict, Token, Separator
from blockchain import Blockchain
import api
def askForMethod():
questions = [
{
'type': 'list',
'message': 'Select action',
'name': 'action',
'choices': [
{
'name': 'Store'
},
{
'name': 'Retrieve'
},
{
'name': 'Migrate'
},
],
# 'validate': lambda output: True if (output == "Store") else False
},
]
try:
answer = prompt(questions)['action']
if(answer == 'Store'):
caseStore()
elif(answer == 'Retrieve'):
caseRetrieve()
elif(answer == 'Migrate'):
caseMigrate()
except (KeyboardInterrupt, SystemExit):
raise
except (KeyError):
print('Exiting...')
def caseStore():
questions = [
{
'type': 'list',
'message': 'Select action',
'name': 'blockchain',
'choices': [
{
'name': 'Bitcoin',
'value': Blockchain.BITCOIN,
},
{
'name': 'Ethereum',
'value': Blockchain.ETHEREUM,
},
{
'name': 'Stellar',
'value': Blockchain.STELLAR,
},
{
'name': 'EOS',
'value': Blockchain.EOS,
},
{
'name': 'IOTA',
'value': Blockchain.IOTA,
},
{
'name': 'Hyperledger',
'value': Blockchain.HYPERLEDGER,
},
{
'name': 'Multichain',
'value': Blockchain.MULTICHAIN,
},
{
'name': 'Postgres',
'value': Blockchain.POSTGRES,
},
],
},
{
'type': 'input',
'name': 'data',
'message': 'Please input the data to store',
}
]
answer = prompt(questions)
api.store(answer['data'], answer['blockchain'])
def caseRetrieve():
questions = [
{
'type': 'input',
'name': 'hash',
'message': 'Please input the transaction hash',
}
]
answer = prompt(questions)
api.retrieve(answer['hash'])
def caseMigrate():
questions = [
{
'type': 'input',
'name': 'hash',
'message': 'Please input the hash of the transaction connected to the data',
},
{
'type': 'list',
'name': 'blockchain',
'message': 'Please select which Blockchain to migrate to',
'choices': [
{
'name': 'Bitcoin',
'value': Blockchain.BITCOIN,
},
{
'name': 'Ethereum',
'value': Blockchain.ETHEREUM,
},
{
'name': 'Stellar',
'value': Blockchain.STELLAR,
},
{
'name': 'EOS',
'value': Blockchain.EOS,
},
{
'name': 'IOTA',
'value': Blockchain.IOTA,
},
{
'name': 'Hyperledger',
'value': Blockchain.HYPERLEDGER,
},
{
'name': 'Multichain',
'value': Blockchain.MULTICHAIN,
},
{
'name': 'Postgres',
'value': Blockchain.POSTGRES,
},
],
},
]
answer = prompt(questions)
api.migrate(answer['hash'], answer['blockchain'])
askForMethod()