FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-bitshares/bitsharesapi/bitsharesnoderpc.py at master · neo1989/python-bitshares · GitHub
neo1989
/
python-bitshares
Public
forked from
bitshares/python-bitshares
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-bitshares
/
bitsharesapi
/
bitsharesnoderpc.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
92 lines (77 loc) · 3.03 KB
Breadcrumbs
python-bitshares
/
bitsharesapi
/
bitsharesnoderpc.py
Copy path
File metadata and controls
92 lines (77 loc) · 3.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
re
import
sys
import
threading
import
websocket
import
ssl
import
json
import
time
from
itertools
import
cycle
from
grapheneapi
.
graphenewsrpc
import
GrapheneWebsocketRPC
from
bitsharesbase
.
chains
import
known_chains
from
.
import
exceptions
import
logging
log
=
logging
.
getLogger
(
__name__
)
class
NumRetriesReached
(
Exception
):
pass
class
BitSharesNodeRPC
(
GrapheneWebsocketRPC
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
BitSharesNodeRPC
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
chain_params
=
self
.
get_network
()
def
register_apis
(
self
):
self
.
api_id
[
"database"
]
=
self
.
database
(
api_id
=
1
)
self
.
api_id
[
"history"
]
=
self
.
history
(
api_id
=
1
)
self
.
api_id
[
"network_broadcast"
]
=
self
.
network_broadcast
(
api_id
=
1
)
def
rpcexec
(
self
,
payload
):
""" Execute a call by sending the payload.
It makes use of the GrapheneRPC library.
In here, we mostly deal with BitShares specific error handling
:param json payload: Payload data
:raises ValueError: if the server does not respond in proper JSON format
:raises RPCError: if the server returns an error
"""
try
:
# Forward call to GrapheneWebsocketRPC and catch+evaluate errors
return
super
(
BitSharesNodeRPC
,
self
).
rpcexec
(
payload
)
except
exceptions
.
RPCError
as
e
:
msg
=
exceptions
.
decodeRPCErrorMsg
(
e
).
strip
()
if
msg
==
"missing required active authority"
:
raise
exceptions
.
MissingRequiredActiveAuthority
elif
re
.
match
(
"^no method with name.*"
,
msg
):
raise
exceptions
.
NoMethodWithName
(
msg
)
elif
msg
:
raise
exceptions
.
UnhandledRPCError
(
msg
)
else
:
raise
e
except
Exception
as
e
:
raise
e
def
get_account
(
self
,
name
,
**
kwargs
):
""" Get full account details from account name or id
:param str name: Account name or account id
"""
if
len
(
name
.
split
(
"."
))
==
3
:
return
self
.
get_objects
([
name
])[
0
]
else
:
return
self
.
get_account_by_name
(
name
,
**
kwargs
)
def
get_asset
(
self
,
name
,
**
kwargs
):
""" Get full asset from name of id
:param str name: Symbol name or asset id (e.g. 1.3.0)
"""
if
len
(
name
.
split
(
"."
))
==
3
:
return
self
.
get_objects
([
name
],
**
kwargs
)[
0
]
else
:
return
self
.
lookup_asset_symbols
([
name
],
**
kwargs
)[
0
]
def
get_object
(
self
,
o
,
**
kwargs
):
""" Get object with id ``o``
:param str o: Full object id
"""
return
self
.
get_objects
([
o
],
**
kwargs
)[
0
]
def
get_network
(
self
):
""" Identify the connected network. This call returns a
dictionary with keys chain_id, core_symbol and prefix
"""
props
=
self
.
get_chain_properties
()
chain_id
=
props
[
"chain_id"
]
for
k
,
v
in
known_chains
.
items
():
if
v
[
"chain_id"
]
==
chain_id
:
return
v
raise
(
"Connecting to unknown network!"
)
Back
|
FazBrowse Home
|
New Git URL