Skip to content

Commit e885f68

Browse files
committed
Add EverWallet.send_raw
1 parent c22f352 commit e885f68

File tree

3 files changed

+110
-19
lines changed

3 files changed

+110
-19
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nekoton-python"
3-
version = "0.1.22"
3+
version = "0.1.23"
44
edition = "2021"
55

66
[lib]

python/nekoton/contracts/ever_wallet.py

Lines changed: 108 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,93 @@
1-
from typing import Optional
1+
from typing import Optional, List
22

33
from . import IGiver
44
import nekoton as _nt
55

66

77
_wallet_abi = _nt.ContractAbi("""{
8-
"ABI version": 2,
9-
"version": "2.3",
10-
"header": ["pubkey", "time", "expire"],
11-
"functions": [{
12-
"name": "sendTransaction",
13-
"inputs": [
14-
{"name": "dest", "type": "address"},
15-
{"name": "value", "type": "uint128"},
16-
{"name": "bounce", "type": "bool"},
17-
{"name": "flags", "type": "uint8"},
18-
{"name": "payload", "type": "cell"}
19-
],
20-
"outputs": []
21-
}],
22-
"events": []
23-
}""")
8+
"ABI version": 2,
9+
"version": "2.3",
10+
"header": ["pubkey", "time", "expire"],
11+
"functions": [
12+
{
13+
"name": "sendTransaction",
14+
"inputs": [
15+
{ "name": "dest", "type": "address" },
16+
{ "name": "value", "type": "uint128" },
17+
{ "name": "bounce", "type": "bool" },
18+
{ "name": "flags", "type": "uint8" },
19+
{ "name": "payload", "type": "cell" }
20+
],
21+
"outputs": []
22+
},
23+
{
24+
"name": "sendTransactionRaw0",
25+
"inputs": [],
26+
"outputs": [],
27+
"id": "0x169e3e11"
28+
},
29+
{
30+
"name": "sendTransactionRaw1",
31+
"inputs": [
32+
{ "name": "flags0", "type": "uint8" },
33+
{ "name": "message0", "type": "cell" }
34+
],
35+
"outputs": [],
36+
"id": "0x169e3e11"
37+
},
38+
{
39+
"name": "sendTransactionRaw2",
40+
"inputs": [
41+
{ "name": "flags0", "type": "uint8" },
42+
{ "name": "message0", "type": "cell" },
43+
{ "name": "flags1", "type": "uint8" },
44+
{ "name": "message1", "type": "cell" }
45+
],
46+
"outputs": [],
47+
"id": "0x169e3e11"
48+
},
49+
{
50+
"name": "sendTransactionRaw3",
51+
"inputs": [
52+
{ "name": "flags0", "type": "uint8" },
53+
{ "name": "message0", "type": "cell" },
54+
{ "name": "flags1", "type": "uint8" },
55+
{ "name": "message1", "type": "cell" },
56+
{ "name": "flags2", "type": "uint8" },
57+
{ "name": "message2", "type": "cell" }
58+
],
59+
"outputs": [],
60+
"id": "0x169e3e11"
61+
},
62+
{
63+
"name": "sendTransactionRaw4",
64+
"inputs": [
65+
{ "name": "flags0", "type": "uint8" },
66+
{ "name": "message0", "type": "cell" },
67+
{ "name": "flags1", "type": "uint8" },
68+
{ "name": "message1", "type": "cell" },
69+
{ "name": "flags2", "type": "uint8" },
70+
{ "name": "message2", "type": "cell" },
71+
{ "name": "flags3", "type": "uint8" },
72+
{ "name": "message3", "type": "cell" }
73+
],
74+
"outputs": [],
75+
"id": "0x169e3e11"
76+
}
77+
],
78+
"events": []
79+
}
80+
""")
2481

2582
_send_transaction = _wallet_abi.get_function("sendTransaction")
2683
assert _send_transaction is not None
2784

85+
_send_transaction_raw = list()
86+
for i in range(4):
87+
abi = _wallet_abi.get_function(f"sendTransactionRaw{i}")
88+
assert abi is not None
89+
_send_transaction_raw.append(abi)
90+
2891
_wallet_code = _nt.Cell.decode(
2992
"te6cckEBBgEA/AABFP8A9KQT9LzyyAsBAgEgAgMABNIwAubycdcBAcAA8nqDCNcY7UTQgwfXAdcLP8j4KM8WI88WyfkAA3HXAQHDAJqDB9cBURO68uBk3oBA1wGAINcBgCDXAVQWdfkQ8qj4I7vyeWa++COBBwiggQPoqFIgvLHydAIgghBM7mRsuuMPAcjL/8s/ye1UBAUAmDAC10zQ+kCDBtcBcdcBeNcB10z4AHCAEASqAhSxyMsFUAXPFlAD+gLLaSLQIc8xIddJoIQJuZgzcAHLAFjPFpcwcQHLABLM4skB+wAAPoIQFp4+EbqOEfgAApMg10qXeNcB1AL7AOjRkzLyPOI+zYS/"
3093
)
@@ -104,6 +167,34 @@ async def send(
104167
raise RuntimeError("Message expired")
105168
return tx
106169

170+
async def send_raw(
171+
self,
172+
messages: List[tuple[_nt.Message, int]],
173+
) -> _nt.Transaction:
174+
if len(messages) > 4:
175+
raise RuntimeError("Too many messages at once")
176+
177+
state_init = await self.__get_state_init()
178+
signature_id = await self._transport.get_signature_id()
179+
180+
abi = _send_transaction_raw[len(messages)]
181+
input = dict()
182+
for i, (message, flags) in enumerate(messages):
183+
input[f"flags{i}"] = flags
184+
input[f"message{i}"] = message.build_cell()
185+
186+
external_message = abi.encode_external_message(
187+
self._address,
188+
input,
189+
public_key=self._keypair.public_key,
190+
state_init=state_init,
191+
).sign(self._keypair, signature_id)
192+
193+
tx = await self._transport.send_external_message(external_message)
194+
if tx is None:
195+
raise RuntimeError("Message expired")
196+
return tx
197+
107198
async def get_account_state(self) -> Optional[_nt.AccountState]:
108199
return await self._transport.get_account_state(self._address)
109200

0 commit comments

Comments
 (0)