Skip to content

Commit eedb5db

Browse files
authored
Merge pull request #44 from domikedos/main
add new methods and create test for them
2 parents e8cbb18 + 08f751b commit eedb5db

18 files changed

+286
-17
lines changed

pytonapi/methods/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .liteserver import LiteserverMethod
1010
from .multisig import MultisigMethod
1111
from .nft import NftMethod
12+
from .purchases import PurchasesMethod
1213
from .rates import RatesMethod
1314
from .sse import SSEMethod
1415
from .staking import StakingMethod

pytonapi/methods/blockchain.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ async def get_block_data(self, block_id: str) -> BlockchainBlock:
4545

4646
return BlockchainBlock(**response)
4747

48+
async def get_block_boc(self, block_id: str) -> str:
49+
"""
50+
Get block data.
51+
52+
:param block_id: block ID (string), example: "(-1,8000000000000000,4234234)"
53+
:return: :class:`BlockchainBlock`
54+
"""
55+
method = f"v2/blockchain/blocks/{block_id}/boc"
56+
response = await self._get(method=method)
57+
58+
return response["error"] # api returns raw string so the result stores in error
59+
4860
async def get_block(self, masterchain_seqno: int) -> BlockchainBlockShards:
4961
"""
5062
Get blockchain block shards.

pytonapi/methods/liteserver.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,18 @@ async def get_raw_state(self, block_id: str) -> RawBlockState:
7979

8080
return RawBlockState(**response)
8181

82-
async def get_raw_header(self, block_id: str) -> RawBlockHeader:
82+
async def get_raw_header(self, block_id: str, mode: int) -> RawBlockHeader:
8383
"""
8484
Get raw blockchain block header.
8585
8686
:param block_id: block ID: (workchain,shard,seqno,root_hash,file_hash)
87+
:param mode: mode
8788
:return: :class:`RawBlockHeader`
8889
"""
90+
8991
method = f"v2/liteserver/get_block_header/{block_id}"
90-
response = await self._get(method=method)
92+
params = {"mode": mode}
93+
response = await self._get(method=method, params=params)
9194

9295
return RawBlockHeader(**response)
9396

@@ -195,34 +198,36 @@ async def get_raw_list_block_transaction(
195198
:param lt: lt
196199
:return: :class:`RawListBlockTransactions`
197200
"""
198-
method = f"v2/liteserver/get_block_transactions/{block_id}"
201+
method = f"v2/liteserver/list_block_transactions/{block_id}"
199202
params = {
200203
"mode": mode,
201-
"count": count,
202-
"account_id": account_id,
203-
"lt": lt
204+
"count": count
204205
}
206+
if account_id:
207+
params["account_id"] = account_id
208+
if lt:
209+
params["lt"] = lt
205210
response = await self._get(method=method, params=params)
206211

207212
return RawListBlockTransactions(**response)
208213

209214
async def get_block_proof(
210215
self,
211-
know_block: str,
216+
known_block: str,
212217
mode: int = 0,
213218
target_block: Optional[str] = None,
214219
) -> RawBlockProof:
215220
"""
216221
Get raw block proof.
217222
218-
:param know_block: know block: (workchain,shard,seqno,root_hash,file_hash)
223+
:param known_block: know block: (workchain,shard,seqno,root_hash,file_hash)
219224
:param mode: mode 0
220225
:param target_block: target block: (workchain,shard,seqno,root_hash,file_hash)
221226
:return: :class:`RawBlockProof`
222227
"""
223-
method = f"v2/liteserver/get_block_proof/{know_block}"
228+
method = f"v2/liteserver/get_block_proof"
224229
params = {
225-
"know_block": know_block,
230+
"known_block": known_block,
226231
"mode": mode,
227232
}
228233
if target_block:
@@ -267,7 +272,7 @@ async def get_out_msg_queue_size(self) -> OutMsgQueueSize:
267272
268273
:return: :class:`OutMsgQueueSize` size
269274
"""
270-
method = "v2/liteserver/get_out_msg_queue_size"
275+
method = "v2/liteserver/get_out_msg_queue_sizes"
271276
response = await self._get(method=method)
272277

273278
return OutMsgQueueSize(**response)

pytonapi/methods/multisig.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pytonapi.base import AsyncTonapiClientBase
2-
from pytonapi.schema.multisig import Multisig
2+
from pytonapi.schema.multisig import Multisig, MultisigOrder
33

44

55
class MultisigMethod(AsyncTonapiClientBase):
@@ -15,3 +15,15 @@ async def get_account_info(self, account_id: str) -> Multisig:
1515
response = await self._get(method=method)
1616

1717
return Multisig(**response)
18+
19+
async def get_order_info(self, account_id: str) -> MultisigOrder:
20+
"""
21+
Get multisig order info.
22+
23+
:param account_id: account ID
24+
:return: :class:`MultisigOrder`
25+
"""
26+
method = f"v2/multisig/order/{account_id}"
27+
response = await self._get(method=method)
28+
29+
return MultisigOrder(**response)

pytonapi/methods/purchases.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from typing import Optional
2+
3+
from pytonapi.base import AsyncTonapiClientBase
4+
from pytonapi.schema.purchases import Purchases
5+
6+
7+
class PurchasesMethod(AsyncTonapiClientBase):
8+
9+
async def get_purchases_history(
10+
self,
11+
account_id: str,
12+
limit: int = 100,
13+
before_lt: Optional[int] = None
14+
) -> Purchases:
15+
"""
16+
Get history of purchases.
17+
18+
:param account_id: account ID
19+
:param before_lt: omit this parameter to get last invoices
20+
:param limit: Default value : 100
21+
:return: :class:`Purchases`
22+
"""
23+
method = f"v2/purchases/{account_id}/history"
24+
params = {"limit": limit}
25+
if before_lt:
26+
params["before_lt"] = before_lt
27+
response = await self._get(method=method, params=params)
28+
29+
return Purchases(**response)

pytonapi/methods/wallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Dict, Any, Union
22

33
from pytonapi.base import AsyncTonapiClientBase
4-
from pytonapi.schema.accounts import Accounts
4+
from pytonapi.schema.accounts import Accounts, Account
55
from pytonapi.schema.events import MessageConsequences
66
from pytonapi.schema.wallet import Wallet
77

pytonapi/schema/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
from pytonapi.schema import domains
55
from pytonapi.schema import events
66
from pytonapi.schema import extra_currency
7+
from pytonapi.schema import gasless
78
from pytonapi.schema import jettons
89
from pytonapi.schema import liteserver
10+
from pytonapi.schema import multisig
911
from pytonapi.schema import nft
12+
from pytonapi.schema import purchases
1013
from pytonapi.schema import rates
1114
from pytonapi.schema import staking
1215
from pytonapi.schema import storage

pytonapi/schema/multisig.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class Risk(BaseModel):
1414
jettons: List[JettonQuantity]
1515
nfts: List[NftItem]
1616

17+
class ChangingParameters(BaseModel):
18+
threshold: int
19+
signers: List[Address]
20+
proposers: str
1721

1822
class MultisigOrder(BaseModel):
1923
address: Address
@@ -22,8 +26,11 @@ class MultisigOrder(BaseModel):
2226
sent_for_execution: bool
2327
signers: List[Address]
2428
approvals_num: int
25-
expiration_data: int
29+
expiration_date: int
2630
risk: Risk
31+
creation_date: int
32+
signed_by: List[Address]
33+
multisig_address: Address
2734

2835

2936
class Multisig(BaseModel):
@@ -32,7 +39,7 @@ class Multisig(BaseModel):
3239
threshold: int
3340
signers: List[Address]
3441
proposers: List[Address]
35-
orders: MultisigOrder
42+
orders: List[MultisigOrder]
3643

3744

3845
class Multisigs(BaseModel):

pytonapi/schema/purchases.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from typing import List, Optional
2+
3+
from pydantic import BaseModel
4+
5+
from pytonapi.schema.accounts import AccountAddress
6+
7+
class Metadata(BaseModel):
8+
encrypted_binary: str
9+
decryption_key: Optional[str] = None
10+
11+
12+
class CurrencyAmount(BaseModel):
13+
currency_type: str
14+
value: str
15+
decimals: int
16+
token_name: str
17+
verification: str
18+
image: str
19+
jetton: Optional[str] = None
20+
21+
22+
class Purchase(BaseModel):
23+
event_id: str
24+
invoice_id: str
25+
source: AccountAddress
26+
destination: AccountAddress
27+
lt: int
28+
utime: int
29+
amount: CurrencyAmount
30+
metadata: Metadata
31+
32+
33+
class Purchases(BaseModel):
34+
purchases: List[Purchase]
35+
next_from: int

pytonapi/schema/wallet.py

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

77

88
class WalletStats(BaseModel):
9-
ton_balance: int
109
nfts_count: int
1110
jettons_count: int
1211
multisig_count: int
@@ -20,8 +19,15 @@ class WalletPlugin(BaseModel):
2019

2120
class Wallet(BaseModel):
2221
address: Address
22+
is_wallet: bool
23+
balance: int
2324
stats: WalletStats
25+
status: str
26+
last_activity: int
2427
plugins: List[WalletPlugin]
2528
name: Optional[str] = None
2629
icon: Optional[str] = None
2730
is_suspended: Optional[bool] = None
31+
signature_disabled: bool
32+
interfaces: List[str]
33+
last_lt: int

0 commit comments

Comments
 (0)