Skip to content

Commit 1c4050d

Browse files
authored
Merge pull request #44 from ltonetwork/Renaming-main-class-and-few-minor
Renaming main class and few minors
2 parents bef39c4 + d30edf0 commit 1c4050d

17 files changed

+82
-24
lines changed

src/lto/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from lto.accounts.account_factory_ed25519 import AccountFactoryED25519
1818

1919

20-
class PyCLTO:
20+
class LTO:
2121

2222
def __init__(self, chain_id='T'):
2323

src/lto/public_node.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def wrapper(self, api, post_data='', host='', headers=None):
3535
return r.json()
3636

3737
def broadcast(self, transaction):
38-
from lto import PyCLTO
38+
from lto import LTO
3939
data = json.dumps(transaction.to_json())
4040
response = self.wrapper(api='/transactions/broadcast', post_data=data)
41-
return PyCLTO().from_data(response)
41+
return LTO().from_data(response)
4242

4343
def compile(self, script_source):
4444
return self.wrapper(api='/utils/script/compile', post_data=script_source)['script']
@@ -53,9 +53,9 @@ def block(self, n):
5353
return self.wrapper('/blocks/at/%d' % n)
5454

5555
def tx(self, id):
56-
from lto import PyCLTO
56+
from lto import LTO
5757
response = self.wrapper('/transactions/info/%s' % id)
58-
return PyCLTO().from_data(response)
58+
return LTO().from_data(response)
5959

6060
def lease_list(self, address):
6161
return self.wrapper(api='/leasing/active/{}'.format(address))

src/lto/transaction.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def sponsor_with(self, sponsor_account):
4444
raise Exception('Transaction must be signed first')
4545

4646
self.sponsor = sponsor_account.address
47-
self.sponsor_public_key = sponsor_account.public_key
47+
self.sponsor_public_key = base58.b58encode(sponsor_account.public_key.__bytes__())
48+
self.sponsor_key_type = sponsor_account.key_type
4849
self.proofs.append(sponsor_account.sign(self.to_binary()))
4950

5051
def broadcast_to(self, node: PublicNode):
@@ -57,7 +58,7 @@ def to_json(self):
5758
def _sponsor_json(self):
5859
if self.sponsor:
5960
return {"sponsor": self.sponsor,
60-
"sponsorPublicKey": base58.b58encode(self.sponsor_public_key.__bytes__()),
61+
"sponsorPublicKey": self.sponsor_public_key,
6162
"sponsorKeyType": self.sponsor_key_type}
6263
else:
6364
return{}

src/lto/transactions/anchor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,10 @@ def from_data(data):
7777
tx.anchors = data['anchors']
7878
tx.proofs = data['proofs'] if 'proofs' in data else []
7979
tx.height = data['height'] if 'height' in data else ''
80+
81+
if "sponsor_public_key" in data:
82+
tx.sponsor = data['sponsor']
83+
tx.sponsor_public_key = data['sponsorPublicKey']
84+
tx.sponsor_key_type = data['sponsorKeyType']
85+
8086
return tx

src/lto/transactions/association.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,11 @@ def from_data(data):
112112
tx.proofs = data['proofs'] if 'proofs' in data else []
113113
tx.height = data['height'] if 'height' in data else ''
114114

115+
if "sponsor_public_key" in data:
116+
tx.sponsor = data['sponsor']
117+
tx.sponsor_public_key = data['sponsorPublicKey']
118+
tx.sponsor_key_type = data['sponsorKeyType']
119+
120+
115121
return tx
116122

src/lto/transactions/cancel_lease.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class CancelLease(Transaction):
88
TYPE = 9
9-
DEFAULT_FEE = 500000000
9+
DEFAULT_FEE = 100000000
1010
DEFAULT_VERSION = 3
1111

1212

@@ -73,6 +73,12 @@ def from_data(data):
7373
tx.proofs = data['proofs'] if 'proofs' in data else []
7474
tx.lease_id = data['leaseId'] if 'leaseId' in data else ''
7575
tx.height = data['height'] if 'height' in data else ''
76+
77+
if "sponsor_public_key" in data:
78+
tx.sponsor = data['sponsor']
79+
tx.sponsor_public_key = data['sponsorPublicKey']
80+
tx.sponsor_key_type = data['sponsorKeyType']
81+
7682
return tx
7783

7884

src/lto/transactions/cancel_sponsorship.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,11 @@ def from_data(data):
7171
tx.proofs = data['proofs']
7272
tx.recipient = data['recipient']
7373
tx.height = data['height'] if 'height' in data else ''
74+
75+
if "sponsor_public_key" in data:
76+
tx.sponsor = data['sponsor']
77+
tx.sponsor_public_key = data['sponsorPublicKey']
78+
tx.sponsor_key_type = data['sponsorKeyType']
79+
7480
return tx
7581

src/lto/transactions/lease.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def from_data(data):
7070
tx.id = data['id'] if 'id' in data else ''
7171
tx.type = data['type']
7272
tx.version = data['version']
73+
tx.amount = data['amount']
7374
tx.sender = data['sender'] if 'sender' in data else ''
7475
tx.sender_key_type = data['senderKeyType'] if 'senderKeyType' in data else 'ed25519'
7576
tx.sender_public_key = data['senderPublicKey']
@@ -78,6 +79,12 @@ def from_data(data):
7879
tx.recipient = data['recipient']
7980
tx.proofs = data['proofs'] if 'proofs' in data else []
8081
tx.height = data['height'] if 'height' in data else ''
82+
83+
if "sponsor_public_key" in data:
84+
tx.sponsor = data['sponsor']
85+
tx.sponsor_public_key = data['sponsorPublicKey']
86+
tx.sponsor_key_type = data['sponsorKeyType']
87+
8188
return tx
8289

8390

src/lto/transactions/mass_transfer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,11 @@ def from_data(data):
9292
tx.attachment = data['attachment'] if 'attachment' in data else ''
9393
tx.transfers = data['transfers']
9494
tx.height = data['height'] if 'height' in data else ''
95+
96+
if "sponsor_public_key" in data:
97+
tx.sponsor = data['sponsor']
98+
tx.sponsor_public_key = data['sponsorPublicKey']
99+
tx.sponsor_key_type = data['sponsorKeyType']
100+
95101
return tx
96102

src/lto/transactions/revoke_association.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,10 @@ def from_data(data):
9595
tx.fee = data['fee']
9696
tx.proofs = data['proofs'] if 'proofs' in data else []
9797
tx.height = data['height'] if 'height' in data else ''
98+
99+
if "sponsor_public_key" in data:
100+
tx.sponsor = data['sponsor']
101+
tx.sponsor_public_key = data['sponsorPublicKey']
102+
tx.sponsor_key_type = data['sponsorKeyType']
103+
98104
return tx

src/lto/transactions/set_script.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,10 @@ def from_data(data):
8181
tx.proofs = data['proofs']
8282
tx.script = data['script']
8383
tx.height = data['height'] if 'height' in data else ''
84+
85+
if "sponsor_public_key" in data:
86+
tx.sponsor = data['sponsor']
87+
tx.sponsor_public_key = data['sponsorPublicKey']
88+
tx.sponsor_key_type = data['sponsorKeyType']
89+
8490
return tx

src/lto/transactions/sponsorship.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,10 @@ def from_data(data):
7171
tx.fee = data['fee']
7272
tx.proofs = data['proofs']
7373
tx.height = data['height'] if 'height' in data else ''
74+
75+
if "sponsor_public_key" in data:
76+
tx.sponsor = data['sponsor']
77+
tx.sponsor_public_key = data['sponsorPublicKey']
78+
tx.sponsor_key_type = data['sponsorKeyType']
79+
7480
return tx

src/lto/transactions/transfer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ def from_data(data):
8686
tx.proofs = data['proofs'] if 'proofs' in data else []
8787
tx.height = data['height'] if 'height' in data else ''
8888

89-
if 'sponsorPublicKey' in data:
89+
if "sponsor_public_key" in data:
9090
tx.sponsor = data['sponsor']
9191
tx.sponsor_public_key = data['sponsorPublicKey']
92+
tx.sponsor_key_type = data['sponsorKeyType']
9293

9394
return tx

tests/init_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from unittest import mock
2-
from lto import PyCLTO
2+
from lto import LTO
33
from lto.public_node import PublicNode
44
from lto.accounts.ed25519.account_ed25519 import AccountED25519 as Account
55

@@ -20,21 +20,21 @@
2020
class TestInit():
2121

2222
def testconstruct(self):
23-
pyclto = PyCLTO()
23+
pyclto = LTO()
2424
assert pyclto.NODE.url == PublicNode('https://testnet.lto.network').url
2525
assert pyclto.chain_id == 'T'
26-
pyclto = PyCLTO('L')
26+
pyclto = LTO('L')
2727
assert pyclto.NODE.url == PublicNode('https://nodes.lto.network').url
2828
assert pyclto.chain_id == 'L'
29-
pyclto = PyCLTO('A')
29+
pyclto = LTO('A')
3030
assert pyclto.NODE == ''
3131

3232
def test_get_chain_id(self):
33-
pyclto = PyCLTO()
33+
pyclto = LTO()
3434
assert pyclto.getchain_id() == 'T'
3535

3636
def test_account(self):
37-
pyclto = PyCLTO()
37+
pyclto = LTO()
3838
private_key = '4sEbCdhpYrZuYGsGSNCR9mJrZgLY6kTdFMGDZnK3oQtSCjyvMz3K6ZMo1GfGmbqHK95Pwx6WTi7vMLpFGbsgbfqz'
3939
seed = 'fragile because fox snap picnic mean art observe vicious program chicken purse text hidden chest'
4040
expectedAccount = Account(seed=seed, public_key='G3PaJt9cUvM5dVW8XAZnKrqmQj1xbSQ4yM7gWuknEKjn',
@@ -46,7 +46,7 @@ def test_account(self):
4646
assert pyclto.Account()
4747

4848
def test_from_data(self):
49-
pyclto = PyCLTO()
49+
pyclto = LTO()
5050
data = ({
5151
"type": 4,
5252
"recipient": '3N6MFpSbbzTozDcfkTUT5zZ2sNbJKFyRtRj',

tests/transaction_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ def test_sponsor_with(self):
2121

2222
transaction.sponsor_with(self.account2)
2323
assert transaction.sponsor == self.account2.address
24-
assert transaction.sponsor_public_key == self.account2.public_key
24+
assert transaction.sponsor_public_key == base58.b58encode(self.account2.public_key.__bytes__())
2525
assert transaction.sponsor_key_type == 'ed25519'
2626

2727
assert self.account2.verify_signature(transaction.to_binary(), transaction.proofs[1])
2828

2929
json = transaction.to_json()
3030
assert json['sponsor'] == self.account2.address
3131
assert json['sponsorPublicKey'] == base58.b58encode(self.account2.public_key.__bytes__())
32-
assert json['sponsorKeyType'] == 'ed25519'
32+
assert json['sponsorKeyType'] == self.account2.key_type

tests/transactions/cancel_lease_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TestCancelLease:
1414
def test_construct(self):
1515
transaction = CancelLease('B22YzYdNv7DCqMqdK2ckpt53gQuYq2v997N7g8agZoHo')
1616
assert transaction.lease_id == 'B22YzYdNv7DCqMqdK2ckpt53gQuYq2v997N7g8agZoHo'
17-
assert transaction.tx_fee == 500000000
17+
assert transaction.tx_fee == 100000000
1818

1919

2020
@freeze_time("2021-01-14")
@@ -30,10 +30,10 @@ def test_sign_with(self):
3030
assert self.account.verify_signature(transaction.to_binary(), transaction.proofs[0])
3131

3232

33-
expected_v2 = {'fee': 500000000,
33+
expected_v2 = {'fee': 100000000,
3434
'senderKeyType': 'ed25519',
3535
'leaseId': 'B22YzYdNv7DCqMqdK2ckpt53gQuYq2v997N7g8agZoHo',
36-
'proofs': ['4bvuZhr215hhxyBmyvbSoMMb2QHULuy36Zdsx2zY2dQqzowHYVq3S6g21J8TzHN5cdxVyChTMx3HMssyaWKAwNYF'],
36+
'proofs': ['r293ec6yhFaVxqg72y1HVqS1UspqMvS97HzontVfrV2T4i6VdhqTe9MxJhutanvAYXUu8fXv4AEx9vgC4BPht47'],
3737
'sender': '3MtHYnCkd3oFZr21yb2vEdngcSGXvuNNCq2',
3838
'senderPublicKey': '4EcSxUkMxqxBEBUBL2oKz3ARVsbyRJTivWpNrYQGdguz',
3939
'timestamp': 1326499200000,
@@ -46,9 +46,9 @@ def test_sign_with(self):
4646
"sender": '3MtHYnCkd3oFZr21yb2vEdngcSGXvuNNCq2',
4747
"senderKeyType": "ed25519",
4848
"senderPublicKey": '4EcSxUkMxqxBEBUBL2oKz3ARVsbyRJTivWpNrYQGdguz',
49-
"fee": 500000000,
49+
"fee": 100000000,
5050
"timestamp": 1326499200000,
51-
"proofs": ['3mR62iT9JBuyDBic678DWaSW5wZ8mZv7dRDTc7LKdA4pu6rJAzFbAUDu3Mi7RjUirwvtryAErSwE37EatJZ1kUbP'],
51+
"proofs": ['2oRKZ1wTUHzhwxfQCseUNCREiKh9aG46KChQJDPHievdbmMTfJpyGaayD3eXQK89odDwCShDyiD1Dp5SUWZJuPEB'],
5252
"leaseId": "B22YzYdNv7DCqMqdK2ckpt53gQuYq2v997N7g8agZoHo"
5353
}
5454

@@ -81,7 +81,7 @@ def test_from_data(self):
8181
"senderKeyType": 'ed25519',
8282
"senderPublicKey": "4EcSxUkMxqxBEBUBL2oKz3ARVsbyRJTivWpNrYQGdguz",
8383
"timestamp": 1519862400,
84-
"fee": 500000000,
84+
"fee": 100000000,
8585
"leaseId": "B22YzYdNv7DCqMqdK2ckpt53gQuYq2v997N7g8agZoHo",
8686
"proofs": [
8787
"2AKUBja93hF8AC2ee21m9AtedomXZNQG5J3FZMU85avjKF9B8CL45RWyXkXEeYb13r1AhpSzRvcudye39xggtDHv"

tests/transactions/lease_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def test_from_data(self):
8282
"type" : 8,
8383
"version": 3,
8484
"sender" : "3HgqG68qfeVz5dqbyvqnxQceFaH49xmGvUS",
85+
"amount" : 1,
8586
"senderKeyType": 'ed25519',
8687
"senderPublicKey" : "DddGQs63eWAA1G1ZJnJDVSrCpMS97NH4odnggwUV42kE",
8788
"fee" : 500000000,

0 commit comments

Comments
 (0)