|
1 |
| -from typing import Optional |
| 1 | +from typing import Optional, List |
2 | 2 |
|
3 | 3 | from . import IGiver
|
4 | 4 | import nekoton as _nt
|
5 | 5 |
|
6 | 6 |
|
7 | 7 | _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 | +""") |
24 | 81 |
|
25 | 82 | _send_transaction = _wallet_abi.get_function("sendTransaction")
|
26 | 83 | assert _send_transaction is not None
|
27 | 84 |
|
| 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 | + |
28 | 91 | _wallet_code = _nt.Cell.decode(
|
29 | 92 | "te6cckEBBgEA/AABFP8A9KQT9LzyyAsBAgEgAgMABNIwAubycdcBAcAA8nqDCNcY7UTQgwfXAdcLP8j4KM8WI88WyfkAA3HXAQHDAJqDB9cBURO68uBk3oBA1wGAINcBgCDXAVQWdfkQ8qj4I7vyeWa++COBBwiggQPoqFIgvLHydAIgghBM7mRsuuMPAcjL/8s/ye1UBAUAmDAC10zQ+kCDBtcBcdcBeNcB10z4AHCAEASqAhSxyMsFUAXPFlAD+gLLaSLQIc8xIddJoIQJuZgzcAHLAFjPFpcwcQHLABLM4skB+wAAPoIQFp4+EbqOEfgAApMg10qXeNcB1AL7AOjRkzLyPOI+zYS/"
|
30 | 93 | )
|
@@ -104,6 +167,34 @@ async def send(
|
104 | 167 | raise RuntimeError("Message expired")
|
105 | 168 | return tx
|
106 | 169 |
|
| 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 | + |
107 | 198 | async def get_account_state(self) -> Optional[_nt.AccountState]:
|
108 | 199 | return await self._transport.get_account_state(self._address)
|
109 | 200 |
|
|
0 commit comments