Skip to content

Commit 0506bf9

Browse files
author
Yucong Sun
authored
Merge pull request #7 from novifinancial/fallentree
Update to libra d641f94
2 parents c669306 + 3afb911 commit 0506bf9

38 files changed

+154
-5443
lines changed

libra

Submodule libra updated from af6b3fd to d641f94
1.01 KB
Binary file not shown.
1.48 KB
Binary file not shown.
1.74 KB
Binary file not shown.

python/setup.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def run(self):
2929

3030

3131
# Require pytest-runner only when running tests
32-
pytest_runner = (
33-
["pytest-runner"] if any(arg in sys.argv for arg in ("pytest", "test")) else []
34-
)
32+
pytest_runner = ["pytest-runner"] if any(arg in sys.argv for arg in ("pytest", "test")) else []
3533
grpcio_tools = ["grpcio-tools"] if any(arg in sys.argv for arg in ["vendor"]) else []
3634

3735
LIBRA_INCLUDE_DIR = "lib"
@@ -40,27 +38,15 @@ def run(self):
4038

4139
extra_link_args = []
4240
if platform.system() == "Darwin":
43-
LIBRA_LIB_FILE = "%s/%s-%s.a" % (
44-
LIBRA_LIB_DIR,
45-
"liblibra_dev",
46-
"darwin-%s" % platform.machine(),
47-
)
41+
LIBRA_LIB_FILE = "%s/%s-%s.a" % (LIBRA_LIB_DIR, "liblibra_dev", "darwin-%s" % platform.machine(),)
4842
extra_link_args.extend(["-framework", "Security"])
4943
elif platform.system() == "Linux":
50-
LIBRA_LIB_FILE = "%s/%s-%s.a" % (
51-
LIBRA_LIB_DIR,
52-
"liblibra_dev",
53-
"linux-%s" % platform.machine(),
54-
)
44+
LIBRA_LIB_FILE = "%s/%s-%s.a" % (LIBRA_LIB_DIR, "liblibra_dev", "linux-%s" % platform.machine(),)
5545
extra_link_args.append("-ldl")
5646
extra_link_args.append("-lm")
5747
extra_link_args.append("-pthread")
5848
elif platform.system() == "Windows":
59-
LIBRA_LIB_FILE = "%s/%s-%s.a" % (
60-
LIBRA_LIB_DIR,
61-
"liblibra_dev",
62-
"windows-%s" % platform.machine(),
63-
)
49+
LIBRA_LIB_FILE = "%s/%s-%s.a" % (LIBRA_LIB_DIR, "liblibra_dev", "windows-%s" % platform.machine(),)
6450

6551

6652
exts = [

python/src/pylibra/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
# pyre-strict
55

66
from ._config import *
7+
from ._types import *
78
from ._jsonrpc_transport import *
89
from ._mint import *
910
from ._native import *
10-
from ._types import *
1111

1212

1313
__all__ = [

python/src/pylibra/_config.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
# pyre-strict
55
import typing
66

7-
87
NETWORK_TESTNET: str = "testnet"
98
NETWORK_DEV: str = "dev"
109

1110
NETWORK_DEFAULT: str = NETWORK_TESTNET
1211

1312
ENDPOINT_CONFIG: typing.Dict[str, typing.Dict[str, str]] = {
14-
NETWORK_TESTNET: {
15-
"json-rpc": "https://client.testnet.libra.org/",
16-
"faucet": "http://faucet.testnet.libra.org",
17-
},
13+
NETWORK_TESTNET: {"json-rpc": "https://client.testnet.libra.org/", "faucet": "http://faucet.testnet.libra.org"},
1814
NETWORK_DEV: {
1915
"json-rpc": "http://client.dev.aws.hlw3truzy4ls.com/",
2016
"faucet": "http://faucet.dev.aws.hlw3truzy4ls.com",

python/src/pylibra/_jsonrpc_transport.py

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
)
2626

2727

28-
EventsType = typing.List[
29-
typing.Union[Event, PaymentEvent, ToLBRExchangeRateUpdateEvent]
30-
]
28+
EventsType = typing.List[typing.Union[Event, PaymentEvent, ToLBRExchangeRateUpdateEvent]]
3129

3230

3331
@dataclasses.dataclass
@@ -158,11 +156,7 @@ def gas(self) -> int:
158156

159157
@property
160158
def metadata(self) -> bytes:
161-
return (
162-
bytes.fromhex(self._transaction["script"]["metadata"])
163-
if self.is_p2p
164-
else b""
165-
)
159+
return bytes.fromhex(self._transaction["script"]["metadata"]) if self.is_p2p else b""
166160

167161
@property
168162
def vm_status(self) -> int:
@@ -376,9 +370,7 @@ def make_json_rpc_request(
376370
timeout: typing.Tuple[float, float],
377371
method: str,
378372
params: typing.List[typing.Any],
379-
result_class: typing.Optional[
380-
typing.Type[typing.Union[GetAccountStateResp, GetMetadataResp, SubmitResp]]
381-
],
373+
result_class: typing.Optional[typing.Type[typing.Union[GetAccountStateResp, GetMetadataResp, SubmitResp]]],
382374
):
383375
req = {"jsonrpc": "2.0", "id": 1, "method": method, "params": params}
384376

@@ -411,10 +403,7 @@ def as_events(resp_list: typing.List[typing.Dict], include: bool = True) -> Even
411403

412404
if include and resp_list:
413405
for e_dict in resp_list:
414-
if (
415-
e_dict["data"]["type"] == "sentpayment"
416-
or e_dict["data"]["type"] == "receivedpayment"
417-
):
406+
if e_dict["data"]["type"] == "sentpayment" or e_dict["data"]["type"] == "receivedpayment":
418407
events.append(JSONPaymentEvent(e_dict))
419408
elif e_dict["data"]["type"] == "to_lbr_exchange_rate_update":
420409
events.append(JSONToLBRExchangeRateUpdateEvent(e_dict))
@@ -454,34 +443,19 @@ def __del__(self):
454443

455444
def currentVersion(self) -> int:
456445
result = make_json_rpc_request(
457-
self._url,
458-
self._session,
459-
self._timeout,
460-
"get_metadata",
461-
["NULL"],
462-
GetMetadataResp,
446+
self._url, self._session, self._timeout, "get_metadata", ["NULL"], GetMetadataResp,
463447
)
464448
return result.version
465449

466450
def currentTimestampUsecs(self) -> int:
467451
result = make_json_rpc_request(
468-
self._url,
469-
self._session,
470-
self._timeout,
471-
"get_metadata",
472-
["NULL"],
473-
GetMetadataResp,
452+
self._url, self._session, self._timeout, "get_metadata", ["NULL"], GetMetadataResp,
474453
)
475454
return result.timestamp
476455

477456
def getAccount(self, address_hex: str) -> typing.Optional[AccountResource]:
478457
resp = make_json_rpc_request(
479-
self._url,
480-
self._session,
481-
self._timeout,
482-
"get_account",
483-
[address_hex],
484-
GetAccountStateResp,
458+
self._url, self._session, self._timeout, "get_account", [address_hex], GetAccountStateResp,
485459
)
486460
if resp is None:
487461
return None
@@ -492,12 +466,7 @@ def getAccount(self, address_hex: str) -> typing.Optional[AccountResource]:
492466

493467
def sendTransaction(self, signed_transaction_bytes: bytes) -> None:
494468
resp = make_json_rpc_request(
495-
self._url,
496-
self._session,
497-
self._timeout,
498-
"submit",
499-
[signed_transaction_bytes.hex()],
500-
SubmitResp,
469+
self._url, self._session, self._timeout, "submit", [signed_transaction_bytes.hex()], SubmitResp,
501470
)
502471
if resp is None:
503472
return None
@@ -510,12 +479,7 @@ def transactions_by_range(
510479
self, start_version: int, limit: int, include_events: bool = False
511480
) -> typing.List[typing.Tuple[SignedTransaction, EventsType]]:
512481
resp_dict = make_json_rpc_request(
513-
self._url,
514-
self._session,
515-
self._timeout,
516-
"get_transactions",
517-
[start_version, limit, include_events],
518-
None,
482+
self._url, self._session, self._timeout, "get_transactions", [start_version, limit, include_events], None,
519483
)
520484

521485
results = []
@@ -533,12 +497,7 @@ def transaction_by_acc_seq(
533497
self, addr_hex: str, seq: int, include_events: bool = False
534498
) -> typing.Tuple[typing.Optional[SignedTransaction], EventsType]:
535499
resp_dict = make_json_rpc_request(
536-
self._url,
537-
self._session,
538-
self._timeout,
539-
"get_account_transaction",
540-
[addr_hex, seq, include_events],
541-
None,
500+
self._url, self._session, self._timeout, "get_account_transaction", [addr_hex, seq, include_events], None,
542501
)
543502

544503
if resp_dict is None:
@@ -554,18 +513,11 @@ def transaction_by_acc_seq(
554513

555514
def get_events(self, key_hex: str, start: int, limit: int) -> EventsType:
556515
resp_list = make_json_rpc_request(
557-
self._url,
558-
self._session,
559-
self._timeout,
560-
"get_events",
561-
[key_hex, start, limit],
562-
None,
516+
self._url, self._session, self._timeout, "get_events", [key_hex, start, limit], None,
563517
)
564518
return as_events(resp_list)
565519

566520
def get_currencies(self) -> typing.List[CurrencyInfo]:
567-
resp_list = make_json_rpc_request(
568-
self._url, self._session, self._timeout, "get_currencies", [], None
569-
)
521+
resp_list = make_json_rpc_request(self._url, self._session, self._timeout, "get_currencies", [], None)
570522
res = [CurrencyInfo(**x) for x in resp_list]
571523
return res

python/src/pylibra/_mint.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ def mint(
3232
amount: int,
3333
identifier: str = "LBR",
3434
session: typing.Optional[requests.Session] = None,
35-
timeout: typing.Optional[
36-
typing.Union[float, typing.Tuple[float, float]]
37-
] = None,
35+
timeout: typing.Optional[typing.Union[float, typing.Tuple[float, float]]] = None,
3836
) -> int:
3937
"""Request faucet to send libra to destination address."""
4038
if len(authkey_hex) != 64:
@@ -47,14 +45,8 @@ def mint(
4745
try:
4846
r = _session.post(
4947
self._baseurl,
50-
params={
51-
"amount": amount,
52-
"auth_key": authkey_hex,
53-
"currency_code": identifier,
54-
},
55-
timeout=timeout
56-
if timeout
57-
else (DEFAULT_CONNECT_TIMEOUT_SECS, DEFAULT_TIMEOUT_SECS),
48+
params={"amount": amount, "auth_key": authkey_hex, "currency_code": identifier},
49+
timeout=timeout if timeout else (DEFAULT_CONNECT_TIMEOUT_SECS, DEFAULT_TIMEOUT_SECS),
5850
)
5951
r.raise_for_status()
6052
if r.text:

python/src/pylibra/_transport.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,17 @@ def sendTransaction(self, signed_transaction_bytes: bytes) -> None:
5050

5151
def transactions_by_range(
5252
self, start_version: int, limit: int, include_events: bool = False
53-
) -> typing.List[
54-
typing.Tuple[SignedTransaction, typing.List[typing.Union[Event, PaymentEvent]]]
55-
]:
53+
) -> typing.List[typing.Tuple[SignedTransaction, typing.List[typing.Union[Event, PaymentEvent]]]]:
5654
raise NotImplementedError()
5755

5856
def transaction_by_acc_seq(
5957
self, addr_hex: str, seq: int, include_events: bool = False
6058
) -> typing.Tuple[
61-
typing.Optional[SignedTransaction],
62-
typing.List[typing.Union[Event, PaymentEvent]],
59+
typing.Optional[SignedTransaction], typing.List[typing.Union[Event, PaymentEvent]],
6360
]:
6461
raise NotImplementedError()
6562

66-
def get_events(
67-
self, key_hex: str, start: int, limit: int
68-
) -> typing.List[typing.Union[Event, PaymentEvent]]:
63+
def get_events(self, key_hex: str, start: int, limit: int) -> typing.List[typing.Union[Event, PaymentEvent]]:
6964
raise NotImplementedError()
7065

7166
def get_currencies(self) -> typing.List[CurrencyInfo]:

python/src/pylibra/lcs/__init__.py

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Copyright (c) Facebook, Inc. and its affiliates
22
# SPDX-License-Identifier: MIT OR Apache-2.0
33

4-
import collections
54
import dataclasses
6-
import typing
7-
from typing import get_type_hints
5+
import collections
86

97
from pylibra import serde_types as st
8+
import typing
9+
from typing import get_type_hints
1010

1111

1212
LCS_MAX_LENGTH = 1 << 31
@@ -105,46 +105,19 @@ def not_implemented():
105105
}
106106

107107
primitive_decode_map = {
108-
st.bool: lambda content: (
109-
st.bool(int.from_bytes(content[:1], byteorder="little", signed=False)),
110-
content[1:],
111-
),
112-
st.uint8: lambda content: (
113-
st.uint8(int.from_bytes(content[:1], byteorder="little", signed=False)),
114-
content[1:],
115-
),
116-
st.uint16: lambda content: (
117-
st.uint16(int.from_bytes(content[:2], byteorder="little", signed=False)),
118-
content[2:],
119-
),
120-
st.uint32: lambda content: (
121-
st.uint32(int.from_bytes(content[:4], byteorder="little", signed=False)),
122-
content[4:],
123-
),
124-
st.uint64: lambda content: (
125-
st.uint64(int.from_bytes(content[:8], byteorder="little", signed=False)),
126-
content[8:],
127-
),
108+
st.bool: lambda content: (st.bool(int.from_bytes(content[:1], byteorder="little", signed=False)), content[1:],),
109+
st.uint8: lambda content: (st.uint8(int.from_bytes(content[:1], byteorder="little", signed=False)), content[1:],),
110+
st.uint16: lambda content: (st.uint16(int.from_bytes(content[:2], byteorder="little", signed=False)), content[2:],),
111+
st.uint32: lambda content: (st.uint32(int.from_bytes(content[:4], byteorder="little", signed=False)), content[4:],),
112+
st.uint64: lambda content: (st.uint64(int.from_bytes(content[:8], byteorder="little", signed=False)), content[8:],),
128113
st.uint128: lambda content: (
129114
st.uint128(int.from_bytes(content[:16], byteorder="little", signed=False)),
130115
content[16:],
131116
),
132-
st.int8: lambda content: (
133-
st.int8(int.from_bytes(content[:1], byteorder="little", signed=True)),
134-
content[1:],
135-
),
136-
st.int16: lambda content: (
137-
st.int16(int.from_bytes(content[:2], byteorder="little", signed=True)),
138-
content[2:],
139-
),
140-
st.int32: lambda content: (
141-
st.int32(int.from_bytes(content[:4], byteorder="little", signed=True)),
142-
content[4:],
143-
),
144-
st.int64: lambda content: (
145-
st.int64(int.from_bytes(content[:8], byteorder="little", signed=True)),
146-
content[8:],
147-
),
117+
st.int8: lambda content: (st.int8(int.from_bytes(content[:1], byteorder="little", signed=True)), content[1:],),
118+
st.int16: lambda content: (st.int16(int.from_bytes(content[:2], byteorder="little", signed=True)), content[2:],),
119+
st.int32: lambda content: (st.int32(int.from_bytes(content[:4], byteorder="little", signed=True)), content[4:],),
120+
st.int64: lambda content: (st.int64(int.from_bytes(content[:8], byteorder="little", signed=True)), content[8:],),
148121
st.int128: lambda content: (
149122
st.int128(int.from_bytes(content[:16], byteorder="little", signed=True)),
150123
content[16:],
@@ -190,9 +163,7 @@ def serialize(obj: typing.Any, obj_type) -> bytes:
190163
item_type = typing.Tuple[types[0], types[1]]
191164
result += encode_length(len(obj))
192165
# Sorting by lexicographic order on the serialized item (or equivalently, serialized keys).
193-
serialized_items = sorted(
194-
serialize(item, item_type) for item in obj.items()
195-
)
166+
serialized_items = sorted(serialize(item, item_type) for item in obj.items())
196167
for s in serialized_items:
197168
result += s
198169

@@ -272,13 +243,8 @@ def deserialize(content: bytes, obj_type):
272243
key, content = deserialize(previous_content, types[0])
273244
serialized_key = previous_content[: -len(content)]
274245
value, content = deserialize(content, types[1])
275-
if (
276-
previous_serialized_key is not None
277-
and previous_serialized_key >= serialized_key
278-
):
279-
raise ValueError(
280-
"Serialized keys in a map must be ordered by increasing lexicographic order"
281-
)
246+
if previous_serialized_key is not None and previous_serialized_key >= serialized_key:
247+
raise ValueError("Serialized keys in a map must be ordered by increasing lexicographic order")
282248
previous_serialized_key = serialized_key
283249
res[key] = value
284250

0 commit comments

Comments
 (0)