Skip to content

Commit dd17145

Browse files
committed
[client]: Wrap contract call
1 parent 7b73b9b commit dd17145

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

starcoin/sdk/client.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ def get_transaction_info(self, txn_hash: str) -> dict:
9292
}
9393
ret = self.execute(operation)
9494
return ret
95-
96-
def get_txpool_pending_txn(self, txn_hash:str) -> dict:
95+
96+
def get_blocks_by_number(self, number: int, count: int) -> dict:
9797
operation = {
98-
"rpc_method": "txpool.pending_txn",
99-
"params": [txn_hash],
98+
"rpc_method": "chain.get_blocks_by_number",
99+
"params": [number, count],
100100
}
101101
ret = self.execute(operation)
102102
return ret
@@ -198,6 +198,26 @@ def get_events_by_txn_hash(self, txn_hash: str):
198198
ret = self.execute(operation)
199199
return ret
200200

201+
def get_txpool_pending_txn(self, txn_hash: str) -> dict:
202+
operation = {
203+
"rpc_method": "txpool.pending_txn",
204+
"params": [txn_hash],
205+
}
206+
ret = self.execute(operation)
207+
return ret
208+
209+
def contract_call(self, function_id: str, type_args: list, args: list):
210+
operation = {
211+
"rpc_method": "contract.call_v2",
212+
"params": [{
213+
"function_id": function_id,
214+
"type_args": type_args,
215+
"args": args,
216+
}],
217+
}
218+
ret = self.execute(operation)
219+
return ret
220+
201221

202222
class RpcRequest():
203223
def __init__(self, url):

tests/test_jsonrpc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_apis():
1313
'0x00000000000000000000000000000001/1/0x00000000000000000000000000000001::Account::Account')
1414
auth_key = bytes(starcoin_types.AccountResource.bcs_deserialize(
1515
bytes(account_resource)).authentication_key).hex()
16-
assert auth_key == "0000000000000000000000000000000000000000000000000000000000000000"
16+
assert auth_key == "0000000000000000000000000000000000000000000000000000000000000001"
1717
assert isinstance(cli.get_account_sequence(
1818
"0x00000000000000000000000000000001"), int) is True
1919
assert cli.get_account_token(
@@ -28,7 +28,11 @@ def test_apis():
2828
"0xc48e82f3f836b7521ccc62d7a4ecd5a80dd4580da8ef75764d7329967c5b14cb")
2929
for event in events:
3030
event_key = event["event_key"][2:]
31+
print(event_key)
3132
event_key = starcoin_types.EventKey.bcs_deserialize(
3233
bytes.fromhex(event_key))
3334
add = utils.account_address_hex(event_key.address)
3435
print(add)
36+
37+
print(cli.contract_call("0x07fa08a855753f0ff7292fdcbe871216::TokenSwapRouter::get_amount_out", [
38+
], ["200u128", "500u128", "600u128"]))

0 commit comments

Comments
 (0)