Skip to content

Commit de4ed7c

Browse files
committed
additional terms
1 parent 50d1338 commit de4ed7c

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

tronapi/tron.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,17 @@ def get_account(self, address):
148148
'address': self.to_hex(address)
149149
}, 'post')
150150

151-
def get_balance(self, address):
151+
def get_balance(self, address, from_tron: bool = False):
152152
"""Получение баланса
153153
154154
Args:
155155
address (str): Адрес учетной записи
156+
from_tron (bool): Преобразовать в обычный формат
156157
157158
"""
158159
response = self.get_account(address)
160+
if from_tron:
161+
return self.from_tron(response['balance'])
159162

160163
return response['balance']
161164

@@ -223,9 +226,19 @@ def _create_transaction(self, from_address, to_address, amount):
223226
Возвращает неподписанную транзакцию
224227
225228
"""
229+
230+
if type(amount) != float or amount < 0:
231+
raise Exception('Invalid amount provided')
232+
233+
_to = self.to_hex(to_address)
234+
_from = self.from_hex(from_address)
235+
236+
if _to == _from:
237+
raise Exception('Cannot transfer TRX to the same account')
238+
226239
return self.full_node.request('/wallet/createtransaction', {
227-
'to_address': self.to_hex(to_address),
228-
'owner_address': self.to_hex(from_address),
240+
'to_address': _to,
241+
'owner_address': _from,
229242
'amount': self.to_tron(amount)
230243
}, 'post')
231244

0 commit comments

Comments
 (0)